/** * @param progressWatchers * all the watchers involved in the same byte transfer operation. * @return * an estimate of the time (in seconds) it will take for the transfer to completed, based * on the number of bytes remaining to transfer and the overall bytes/second rate. */ public static long calculateRemainingTime(BytesProgressWatcher[] progressWatchers) { long bytesRemaining = sumBytesToTransfer(progressWatchers) - sumBytesTransferred(progressWatchers); double bytesPerSecond = calculateOverallBytesPerSecond(progressWatchers); if (Math.abs(bytesPerSecond) < 0.001d) { // No transfer has occurred yet. return 0; } double remainingSecs = bytesRemaining / bytesPerSecond; return Math.round(remainingSecs); }
/** * @return * an estimate of the recent rate of bytes/second transfer speed. */ public long getBytesPerSecond() { return BytesProgressWatcher.calculateRecentByteRatePerSecond(progressWatchers); }
@Override public void close() throws IOException { try { inputStream.close(); } finally { progressWatcher.clearHistory(); } }
/** * @param progressWatchers * all the watchers involved in the same byte transfer operation. * @return * the rate of bytes/second that has been achieved recently (ie within the last * {@link #SECONDS_OF_HISTORY} seconds). */ public static long calculateRecentByteRatePerSecond(BytesProgressWatcher[] progressWatchers) { double sumOfRates = 0; for (int i = 0; i < progressWatchers.length; i++) { if (progressWatchers[i].isStarted()) { sumOfRates += progressWatchers[i].getRecentByteRatePerSecond(); } } return Math.round(sumOfRates); }
@Override public void updateBytesTransferred(long byteCount) { super.updateBytesTransferred(byteCount); printProgressLine("Comparing files: " + byteFormatter.formatByteSize(super.getBytesTransferred())); } };
private String formatBytesProgressWatcherDetails(BytesProgressWatcher watcher, boolean includeBytes) { long secondsRemaining = watcher.getRemainingTime(); String detailsText = (includeBytes ? byteFormatter.formatByteSize(watcher.getBytesTransferred()) + " of " + byteFormatter.formatByteSize(watcher.getBytesToTransfer()) + " - " : "") + "Time remaining: " + timeFormatter.formatTime(secondsRemaining); return detailsText; }
/** * @param progressWatchers * all the watchers involved in the same byte transfer operation. * @return * the overall rate of bytes/second over all transfers for all watchers. */ public static double calculateOverallBytesPerSecond(BytesProgressWatcher[] progressWatchers) { long initialStartTime = Long.MAX_VALUE; // The oldest start time of any monitor. long bytesTotal = 0; for (int i = 0; i < progressWatchers.length; i++) { // Ignore any watchers that have not yet started. if (!progressWatchers[i].isStarted()) { continue; } // Add up all the bytes transferred by all started watchers. bytesTotal += progressWatchers[i].getTotalBytesInAllTransfers(); // Find the earliest starting time of any monitor. if (progressWatchers[i].getHistoricStartTimeMS() < initialStartTime) { initialStartTime = progressWatchers[i].getHistoricStartTimeMS(); } } // Determine how much time has elapsed since the earliest watcher start time. long elapsedTimeSecs = (System.currentTimeMillis() - initialStartTime) / 1000; // Calculate the overall rate of bytes/second over all transfers for all watchers. double bytesPerSecondOverall = (elapsedTimeSecs == 0 ? bytesTotal : (double)bytesTotal / elapsedTimeSecs); return bytesPerSecondOverall; }
for (int i = 0; i < runnables.length; i++) { incompletedObjectsList.add(objects[i]); BytesProgressWatcher progressMonitor = new BytesProgressWatcher(objects[i].getContentLength()); runnables[i] = new CreateObjectRunnable(bucket, objects[i], progressMonitor); progressWatchers.add(progressMonitor);
/** * @param progressWatchers * all the watchers involved in the same byte transfer operation. * @return * the total number of bytes already transferred. */ public static long sumBytesTransferred(BytesProgressWatcher[] progressWatchers) { long sumOfBytes = 0; for (int i = 0; i < progressWatchers.length; i++) { sumOfBytes += progressWatchers[i].getBytesTransferred(); } return sumOfBytes; }
/** * @param progressWatchers * all the watchers involved in the same byte transfer operation. * @return * the total number of bytes to transfer. */ public static long sumBytesToTransfer(BytesProgressWatcher[] progressWatchers) { long sumOfBytes = 0; for (int i = 0; i < progressWatchers.length; i++) { sumOfBytes += progressWatchers[i].getBytesToTransfer(); } return sumOfBytes; }
/** * @return * an estimate of the time (in seconds) it will take for the transfer to completed, based * on the number of bytes remaining to transfer and the overall bytes/second rate. */ public long getRemainingTime() { BytesProgressWatcher[] progressWatchers = new BytesProgressWatcher[1]; progressWatchers[0] = this; long bytesRemaining = bytesToTransfer - totalBytesInCurrentTransfer; double remainingSecs = bytesRemaining / calculateOverallBytesPerSecond(progressWatchers); return Math.round(remainingSecs); }
/** * @return * an estimate of the how many <b>seconds</b> until the data transfer completes, based on the * overall byte rate of the transmission. * @throws IllegalStateException * if the time remaining estimave is not available - check this availability * with the {@link #isTimeRemainingAvailable()} method. */ public long getTimeRemaining() { if (!isTimeRemainingAvailable()) { throw new IllegalStateException("Time remaining estimate is not available in this object"); } return BytesProgressWatcher.calculateRemainingTime(progressWatchers); }
private String formatBytesProgressWatcherDetails(BytesProgressWatcher watcher, boolean includeBytes) { long secondsRemaining = watcher.getRemainingTime(); String detailsText = (includeBytes ? byteFormatter.formatByteSize(watcher.getBytesTransferred()) + " of " + byteFormatter.formatByteSize(watcher.getBytesToTransfer()) + " - " : "") + "Time remaining: " + timeFormatterTerse.formatTime(secondsRemaining); return detailsText; }
/** * @param progressWatchers * all the watchers involved in the same byte transfer operation. * @return * the overall rate of bytes/second over all transfers for all watchers. */ public static double calculateOverallBytesPerSecond(BytesProgressWatcher[] progressWatchers) { long initialStartTime = Long.MAX_VALUE; // The oldest start time of any monitor. long bytesTotal = 0; for (int i = 0; i < progressWatchers.length; i++) { // Ignore any watchers that have not yet started. if (!progressWatchers[i].isStarted()) { continue; } // Add up all the bytes transferred by all started watchers. bytesTotal += progressWatchers[i].getTotalBytesInAllTransfers(); // Find the earliest starting time of any monitor. if (progressWatchers[i].getHistoricStartTimeMS() < initialStartTime) { initialStartTime = progressWatchers[i].getHistoricStartTimeMS(); } } // Determine how much time has elapsed since the earliest watcher start time. long elapsedTimeSecs = (System.currentTimeMillis() - initialStartTime) / 1000; // Calculate the overall rate of bytes/second over all transfers for all watchers. double bytesPerSecondOverall = (elapsedTimeSecs == 0 ? bytesTotal : (double)bytesTotal / elapsedTimeSecs); return bytesPerSecondOverall; }
for (int i = 0; i < runnables.length; i++) { incompletedObjectsList.add(objects[i]); BytesProgressWatcher progressMonitor = new BytesProgressWatcher(objects[i].getContentLength()); runnables[i] = new CreateObjectRunnable(bucketName, objects[i], progressMonitor); progressWatchers.add(progressMonitor);
@Override public void updateBytesTransferred(long byteCount) { super.updateBytesTransferred(byteCount); printProgressLine("Comparing files: " + byteFormatter.formatByteSize(super.getBytesTransferred())); } };
/** * @param progressWatchers * all the watchers involved in the same byte transfer operation. * @return * the rate of bytes/second that has been achieved recently (ie within the last * {@link #SECONDS_OF_HISTORY} seconds). */ public static long calculateRecentByteRatePerSecond(BytesProgressWatcher[] progressWatchers) { double sumOfRates = 0; for (int i = 0; i < progressWatchers.length; i++) { if (progressWatchers[i].isStarted()) { sumOfRates += progressWatchers[i].getRecentByteRatePerSecond(); } } return Math.round(sumOfRates); }
/** * @param progressWatchers * all the watchers involved in the same byte transfer operation. * @return * the total number of bytes already transferred. */ public static long sumBytesTransferred(BytesProgressWatcher[] progressWatchers) { long sumOfBytes = 0; for (int i = 0; i < progressWatchers.length; i++) { sumOfBytes += progressWatchers[i].getBytesTransferred(); } return sumOfBytes; }
/** * @param progressWatchers * all the watchers involved in the same byte transfer operation. * @return * the total number of bytes to transfer. */ public static long sumBytesToTransfer(BytesProgressWatcher[] progressWatchers) { long sumOfBytes = 0; for (int i = 0; i < progressWatchers.length; i++) { sumOfBytes += progressWatchers[i].getBytesToTransfer(); } return sumOfBytes; }
/** * @return * an estimate of the time (in seconds) it will take for the transfer to completed, based * on the number of bytes remaining to transfer and the overall bytes/second rate. */ public long getRemainingTime() { BytesProgressWatcher[] progressWatchers = new BytesProgressWatcher[1]; progressWatchers[0] = this; long bytesRemaining = bytesToTransfer - totalBytesInCurrentTransfer; double remainingSecs = bytesRemaining / calculateOverallBytesPerSecond(progressWatchers); return Math.round(remainingSecs); }