org.sonatype.aether.util.listener
Class ChainedTransferListener

java.lang.Object
  extended by org.sonatype.aether.transfer.AbstractTransferListener
      extended by org.sonatype.aether.util.listener.ChainedTransferListener
All Implemented Interfaces:
TransferListener

public class ChainedTransferListener
extends AbstractTransferListener

A transfer listener that delegates to zero or more other listeners (multicast). The list of target listeners is thread-safe, i.e. target listeners can be added or removed by any thread at any time.

Author:
Benjamin Bentmann

Constructor Summary
ChainedTransferListener(Collection<TransferListener> listeners)
          Creates a new multicast listener that delegates to the specified listeners.
ChainedTransferListener(TransferListener... listeners)
          Creates a new multicast listener that delegates to the specified listeners.
 
Method Summary
 void add(Collection<TransferListener> listeners)
          Adds the specified listeners to the end of the multicast chain.
 void add(TransferListener listener)
          Adds the specified listener to the end of the multicast chain.
protected  void handleError(TransferEvent event, TransferListener listener, RuntimeException error)
           
static TransferListener newInstance(TransferListener listener1, TransferListener listener2)
          Creates a new multicast listener that delegates to the specified listeners.
 void remove(TransferListener listener)
          Removes the specified listener from the multicast chain.
 void transferCorrupted(TransferEvent event)
          Notifies the listener that a checksum validation failed.
 void transferFailed(TransferEvent event)
          Notifies the listener about the unsuccessful termination of a transfer.
 void transferInitiated(TransferEvent event)
          Notifies the listener about the initiation of a transfer.
 void transferProgressed(TransferEvent event)
          Notifies the listener about some progress in the data transfer.
 void transferStarted(TransferEvent event)
          Notifies the listener about the start of a data transfer, i.e.
 void transferSucceeded(TransferEvent event)
          Notifies the listener about the successful completion of a transfer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ChainedTransferListener

public ChainedTransferListener(TransferListener... listeners)
Creates a new multicast listener that delegates to the specified listeners.

Parameters:
listeners - The listeners to delegate to, may be null or empty.

ChainedTransferListener

public ChainedTransferListener(Collection<TransferListener> listeners)
Creates a new multicast listener that delegates to the specified listeners.

Parameters:
listeners - The listeners to delegate to, may be null or empty.
Method Detail

newInstance

public static TransferListener newInstance(TransferListener listener1,
                                           TransferListener listener2)
Creates a new multicast listener that delegates to the specified listeners. In contrast to the constructor, this factory method will avoid creating an actual chained listener if one of the specified readers is actually null.

Parameters:
listener1 - The first listener, may be null.
listener2 - The second listener, may be null.
Returns:
The chained listener or null if no listener was supplied.

add

public void add(Collection<TransferListener> listeners)
Adds the specified listeners to the end of the multicast chain.

Parameters:
listeners - The listeners to add, may be null or empty.

add

public void add(TransferListener listener)
Adds the specified listener to the end of the multicast chain.

Parameters:
listener - The listener to add, may be null.

remove

public void remove(TransferListener listener)
Removes the specified listener from the multicast chain. Trying to remove a non-existing listener has no effect.

Parameters:
listener - The listener to remove, may be null.

handleError

protected void handleError(TransferEvent event,
                           TransferListener listener,
                           RuntimeException error)

transferInitiated

public void transferInitiated(TransferEvent event)
                       throws TransferCancelledException
Description copied from interface: TransferListener
Notifies the listener about the initiation of a transfer. This event gets fired before any actual network access to the remote repository.

Specified by:
transferInitiated in interface TransferListener
Overrides:
transferInitiated in class AbstractTransferListener
Parameters:
event - The event details, must not be null.
Throws:
TransferCancelledException - If the transfer should be aborted.

transferStarted

public void transferStarted(TransferEvent event)
                     throws TransferCancelledException
Description copied from interface: TransferListener
Notifies the listener about the start of a data transfer, i.e. the successful connection to the remote repository.

Specified by:
transferStarted in interface TransferListener
Overrides:
transferStarted in class AbstractTransferListener
Parameters:
event - The event details, must not be null.
Throws:
TransferCancelledException - If the transfer should be aborted.

transferProgressed

public void transferProgressed(TransferEvent event)
                        throws TransferCancelledException
Description copied from interface: TransferListener
Notifies the listener about some progress in the data transfer. This event may even be fired if actually zero bytes have been transferred since the last event, for instance to enable cancellation.

Specified by:
transferProgressed in interface TransferListener
Overrides:
transferProgressed in class AbstractTransferListener
Parameters:
event - The event details, must not be null.
Throws:
TransferCancelledException - If the transfer should be aborted.

transferCorrupted

public void transferCorrupted(TransferEvent event)
                       throws TransferCancelledException
Description copied from interface: TransferListener
Notifies the listener that a checksum validation failed. TransferEvent.getException() will be of type ChecksumFailureException and can be used to query further details about the expected/actual checksums.

Specified by:
transferCorrupted in interface TransferListener
Overrides:
transferCorrupted in class AbstractTransferListener
Parameters:
event - The event details, must not be null.
Throws:
TransferCancelledException - If the transfer should be aborted.

transferSucceeded

public void transferSucceeded(TransferEvent event)
Description copied from interface: TransferListener
Notifies the listener about the successful completion of a transfer.

Specified by:
transferSucceeded in interface TransferListener
Overrides:
transferSucceeded in class AbstractTransferListener
Parameters:
event - The event details, must not be null.

transferFailed

public void transferFailed(TransferEvent event)
Description copied from interface: TransferListener
Notifies the listener about the unsuccessful termination of a transfer. TransferEvent.getException() will provide further information about the failure.

Specified by:
transferFailed in interface TransferListener
Overrides:
transferFailed in class AbstractTransferListener
Parameters:
event - The event details, must not be null.


Copyright © 2010-2013. All Rights Reserved.