private static Future<?> publishByteCountEvent( final ProgressListener listener, final ProgressEventType type, final long bytes) { if (listener == ProgressListener.NOOP || listener == null || bytes <= 0) return null; return deliverEvent(listener, new ProgressEvent(type, bytes)); }
@Override protected void onNotifyBytesRead() { publishRequestBytesTransferred(getListener(), getUnnotifiedByteCount()); } }
@Override protected void onNotifyBytesRead() { publishResponseBytesTransferred(getListener(), getUnnotifiedByteCount()); } }
@Override public void progressChanged(ProgressEvent progressEvent) { ProgressEventType type = progressEvent.getEventType(); if (type.isByteCountEvent()) return; if (type != types[count]) { throw new AssertionError("Expect event type " + types[count] + " but got " + progressEvent.getEventType()); } count++; }
@Override public ProgressEvent filter(ProgressEvent progressEvent) { // Block COMPLETE events from the low-level GetObject operation, // but we still want to keep the BytesTransferred return progressEvent.getEventType() == ProgressEventType.TRANSFER_COMPLETED_EVENT ? null // discard this event : progressEvent ; } }
/** * Adds the specified progress listener to the list of listeners * receiving updates about this transfer's progress. * * @param listener * The progress listener to add. */ public synchronized void addProgressListener(ProgressListener listener) { listenerChain.addProgressListener(listener); }
@Override public void run() { listener.progressChanged(event); } });
@Override protected void onReset() { publishRequestReset(getListener(), getNotifiedByteCount()); }
@Override protected void onReset() { publishResponseReset(getListener(), getNotifiedByteCount()); }
/** * Removes the specified progress listener from the list of progress * listeners receiving updates about this transfer's progress. * * @param listener * The progress listener to remove. */ public synchronized void removeProgressListener(ProgressListener listener) { listenerChain.removeProgressListener(listener); }
public static boolean isSyncCallSafe(ProgressListener listener) { if (listener instanceof DeliveryMode) { DeliveryMode mode = (DeliveryMode) listener; return mode.isSyncCallSafe(); } return listener == null; } }
/** * Convenient method to publish a response bytes discard event to the given listener. */ public static Future<?> publishResponseBytesDiscarded( final ProgressListener listener, final long bytesDiscarded) { return publishResetEvent(listener, ProgressEventType.RESPONSE_BYTE_DISCARD_EVENT, bytesDiscarded); }
/** * Wrap with a {@link ProgressInputStream} to report request progress to listener. * * @param listener Listener to report to * @param content Input stream to monitor progress for * @return Wrapped input stream with progress monitoring capabilities. */ private InputStream monitorStreamProgress(ProgressListener listener, InputStream content) { return ProgressInputStream.inputStreamForRequest(content, listener); }
@Override public boolean isSyncCallSafe() { return progressListenerChain == null || progressListenerChain.isSyncCallSafe(); } }
/** * Returns true if this event type is related to the execution of a * single http request-response to AWS; false otherwise. */ public boolean isRequestCycleEvent() { return !isTransferEvent(); }
/** * Returns a wrapper for the given listener to capture the first * exception thrown. */ public static ExceptionReporter wrap(ProgressListener listener) { return new ExceptionReporter(listener); }
/** * Defaults to behave the same as {@link #onEOF()}. */ protected void onClose() { eof(); } /**
private void eof() { if (doneEOF) return; onEOF(); unnotifiedByteCount = 0; doneEOF = true; }
public LegacyS3ProgressListener(final ProgressListener listener) { this.listener = listener; if (listener instanceof DeliveryMode) { DeliveryMode mode = (DeliveryMode)listener; syncCallSafe = mode.isSyncCallSafe(); } else syncCallSafe = false; }
/** * Convenient method to publish a response reset event to the given listener. */ public static Future<?> publishResponseReset( final ProgressListener listener, final long bytesReset) { return publishResetEvent(listener, HTTP_RESPONSE_CONTENT_RESET_EVENT, bytesReset); }