@Override public void start() { // for example from unit testing we want to start Camel later (manually) if (Boolean.TRUE.equals(NO_START.get())) { LOG.trace("Ignoring start() as NO_START is false"); return; } if (!isStarted() && !isStarting()) { try { StopWatch watch = new StopWatch(); super.start(); LOG.debug("start() took {} millis", watch.stop()); } catch (Exception e) { throw wrapRuntimeCamelException(e); } } else { // ignore as Camel is already started LOG.trace("Ignoring start() as Camel is already started"); } }
public long timeTaken() { return watch.taken(); }
@Override protected void starting(Description description) { watch.restart(); }
@ManagedAttribute(description = "Summary of last FTP activity (download only)") public String getLastFtpActivity() { FTPClient client = getOperations().getFtpClient(); FtpClientActivityListener listener = (FtpClientActivityListener) client.getCopyStreamListener(); if (listener != null) { String log = listener.getLastLogActivity(); if (log != null) { long since = listener.getLastLogActivityTimestamp(); if (since > 0) { StopWatch watch = new StopWatch(new Date(since)); long delta = watch.taken(); String human = TimeUtils.printDuration(delta); return log + " " + human + " ago"; } else { return log; } } } return null; }
@Override public void onUpload(String host, String file, long chunkSize, long totalChunkSize, long fileSize) { transferredBytes = totalChunkSize; String msg = "Uploading to host: " + host + " file: " + file + " chunk (" + chunkSize + "/" + totalChunkSize + " bytes)"; if (fileSize > 0) { float percent = ((float) totalChunkSize / (float) fileSize) * 100L; String num = String.format("%.1f", percent); // avoid 100.0 as its only done when we get the onUploadComplete if (totalChunkSize < fileSize && "100.0".equals(num)) { num = "99.9"; } String size = StringHelper.humanReadableBytes(totalChunkSize); msg += " (progress: " + size + "/" + num + "%)"; } else { // okay we do not know the total size, but then make what we have uploaded so-far human readable String size = StringHelper.humanReadableBytes(totalChunkSize); msg += " (uploaded: " + size + ")"; } // each chunk is verbose doLogVerbose(msg); // however if the operation is slow then log once in a while if (interval.taken() > endpoint.getTransferLoggingIntervalSeconds() * 1000) { doLog(msg); interval.restart(); } }
@Override protected void finished(Description description) { watch.stop(); }
@ManagedAttribute(description = "Summary of last FTP activity (all)") public String getLastFtpActivityVerbose() { FTPClient client = getOperations().getFtpClient(); FtpClientActivityListener listener = (FtpClientActivityListener) client.getCopyStreamListener(); if (listener != null) { String log = listener.getLastVerboseLogActivity(); if (log != null) { long since = listener.getLastVerboseLogActivityTimestamp(); if (since > 0) { StopWatch watch = new StopWatch(new Date(since)); long delta = watch.taken(); String human = TimeUtils.printDuration(delta); return log + " " + human + " ago"; } else { return log; } } } return null; }
@Override public void onDownload(String host, String file, long chunkSize, long totalChunkSize, long fileSize) { totalChunkSize = totalChunkSize + resumeOffset; transferredBytes = totalChunkSize; String prefix = resume ? "Resume downloading" : "Downloading"; String msg = prefix + " from host: " + host + " file: " + file + " chunk (" + chunkSize + "/" + totalChunkSize + " bytes)"; if (fileSize > 0) { float percent = ((float) totalChunkSize / (float) fileSize) * 100L; String num = String.format("%.1f", percent); // avoid 100.0 as its only done when we get the onDownloadComplete if (totalChunkSize < fileSize && "100.0".equals(num)) { num = "99.9"; } String size = StringHelper.humanReadableBytes(totalChunkSize); msg += " (progress: " + size + "/" + num + "%)"; } else { // okay we do not know the total size, but then make what we have download so-far human readable String size = StringHelper.humanReadableBytes(totalChunkSize); msg += " (downloaded: " + size + ")"; } doLogVerbose(msg); // however if the operation is slow then log once in a while if (interval.taken() > endpoint.getTransferLoggingIntervalSeconds() * 1000) { doLog(msg); interval.restart(); } }
@Override public void afterPropertiesSet() throws Exception { StopWatch watch = new StopWatch(); super.afterPropertiesSet(); Boolean shutdownEager = CamelContextHelper.parseBoolean(getContext(), getShutdownEager()); if (shutdownEager != null) { LOG.debug("Using shutdownEager: {}", shutdownEager); getContext().setShutdownEager(shutdownEager); } LOG.debug("afterPropertiesSet() took {} millis", watch.stop()); }
@After public void tearDown() throws Exception { long time = watch.taken();
public static void main(String[] args) { LoanBrokerWS loanBroker = getProxy(url); StopWatch watch = new StopWatch(); String result = loanBroker.getLoanQuote("SSN", 5000.00, 24); System.out.println("Took " + watch.stop() + " milliseconds to call the loan broker service"); System.out.println(result); }
@Override public void onDownloadComplete(String host, String file) { String prefix = resume ? "Resume downloading" : "Downloading"; String msg = prefix + " from host: " + host + " file: " + file + " completed"; if (transferredBytes > 0) { msg += " (size: " + StringHelper.humanReadableBytes(transferredBytes) + ")"; } long taken = watch.taken(); String time = TimeUtils.printDuration(taken); msg += " (took: " + time + ")"; doLog(msg); }
@Override public void onUploadComplete(String host, String file) { String msg = "Uploading to host: " + host + " file: " + file + " completed"; if (transferredBytes > 0) { msg += " (size: " + StringHelper.humanReadableBytes(transferredBytes) + ")"; } long taken = watch.taken(); String time = TimeUtils.printDuration(taken); msg += " (took: " + time + ")"; doLog(msg); }
@Override public void onBeginDownloading(String host, String file) { download = true; resume = false; resumeOffset = 0; watch.restart(); interval.restart(); String msg = "Downloading from host: " + host + " file: " + file + " starting "; // add extra space to align with completed if (fileSize > 0) { msg += " (size: " + fileSizeText + ")"; } doLog(msg); }
final StopWatch watch = new StopWatch(); boolean answer; log.debug("About to store file: {} using stream: {}", targetName, is); long time = watch.taken(); log.debug("Took {} ({} millis) to store file: {} and FTP client returned: {}", new Object[]{TimeUtils.printDuration(time), time, targetName, answer});