com.univocity.api.statistics
Class DataTransferListener<S,T,E extends DataTransfer<S,T>>

java.lang.Object
  extended by com.univocity.api.statistics.DataTransferListener<S,T,E>
Type Parameters:
S - type of the supported sources of data
T - type of the supported targets of data
E - type of the entries managed by this list, created for each individual data transfer with a call to newDataTransfer(Object, long, Object)
All Implemented Interfaces:
DataTransfer<S,T>, Iterable<E>
Direct Known Subclasses:
DownloadListener

public abstract class DataTransferListener<S,T,E extends DataTransfer<S,T>>
extends Object
implements DataTransfer<S,T>, Iterable<E>

A basic management structure for data transfers occurring in parallel.

Author:
uniVocity Software Pty Ltd - dev@univocity.com *
See Also:
DownloadListener, DataTransfer

Constructor Summary
DataTransferListener()
           
 
Method Summary
 void aborted(S source, T target, Exception error)
          Notifies that the data transfer has been aborted.
 void completed(S source, T target)
          Notifies that a data transfer has been finalized.
 List<E> getActiveTransfers()
          Returns a copy of the internal list of currently active transfers
 boolean isAborted()
          Returns a flag indicating whether the data transfer was aborted.
 boolean isRunning()
          Returns a flag indicating whether the data transfer is running.
 boolean isStarted()
          Returns a flag indicating whether the data transfer has been started.
 Iterator<E> iterator()
           
protected abstract  E newDataTransfer(S source, long totalSize, T target)
          Creates a a new DataTransfer
 int size()
          Returns the number of active transfers currently maintained by this list
 void started(S source, long totalSize, T target)
          Notifies a data transfer has been started.
 void transferred(S source, long transferred, T target)
          Notifies how much data has been transferred from source to target.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DataTransferListener

public DataTransferListener()
Method Detail

started

public void started(S source,
                    long totalSize,
                    T target)
Description copied from interface: DataTransfer
Notifies a data transfer has been started.

Specified by:
started in interface DataTransfer<S,T>
Parameters:
source - the source of data
totalSize - the total size of the data. The meaning of the amount provided depends on the underlying implementation: this can be bytes, number of records, etc. If -1, the total size is unknown ahead of time.
target - the data target

transferred

public void transferred(S source,
                        long transferred,
                        T target)
Description copied from interface: DataTransfer
Notifies how much data has been transferred from source to target. Can be invoked multiple times until the data transfer is completed or aborted.

Specified by:
transferred in interface DataTransfer<S,T>
Parameters:
source - the source of data
transferred - the amount of data transferred since the last time this method was called. The meaning of the amount provided depends on the underlying implementation: this can be bytes, number of records, etc.
target - the data target

completed

public void completed(S source,
                      T target)
Description copied from interface: DataTransfer
Notifies that a data transfer has been finalized.

Specified by:
completed in interface DataTransfer<S,T>
Parameters:
source - the source of data
target - the data target

aborted

public void aborted(S source,
                    T target,
                    Exception error)
Description copied from interface: DataTransfer
Notifies that the data transfer has been aborted.

Specified by:
aborted in interface DataTransfer<S,T>
Parameters:
source - the source of data
target - the data target
error - exception that caused the process abortion.

newDataTransfer

protected abstract E newDataTransfer(S source,
                                     long totalSize,
                                     T target)
Creates a a new DataTransfer

Parameters:
source - where the data will be transferred from
totalSize - the total size of the data to be transferred
target - the target where the data will be transferred to
Returns:
a new DataTransfer that will transfer data of size totalSize from source to target

isStarted

public final boolean isStarted()
Description copied from interface: DataTransfer
Returns a flag indicating whether the data transfer has been started.

Specified by:
isStarted in interface DataTransfer<S,T>
Returns:
a flag indicating whether the data transfer has been started.

isRunning

public final boolean isRunning()
Description copied from interface: DataTransfer
Returns a flag indicating whether the data transfer is running.

Specified by:
isRunning in interface DataTransfer<S,T>
Returns:
a flag indicating whether the data transfer is running.

isAborted

public final boolean isAborted()
Description copied from interface: DataTransfer
Returns a flag indicating whether the data transfer was aborted.

Specified by:
isAborted in interface DataTransfer<S,T>
Returns:
a flag indicating whether the data transfer was aborted.

size

public int size()
Returns the number of active transfers currently maintained by this list

Returns:
the number of active data transfers

getActiveTransfers

public List<E> getActiveTransfers()
Returns a copy of the internal list of currently active transfers

Returns:
the active transfers

iterator

public Iterator<E> iterator()
Specified by:
iterator in interface Iterable<E extends DataTransfer<S,T>>


Copyright © 2018 uniVocity Software Pty Ltd. All rights reserved.