uk.org.retep.util.monitor
Class ProgressListenerSet

java.lang.Object
  extended by uk.org.retep.util.concurrent.ReadWriteConcurrencySupport
      extended by uk.org.retep.util.concurrent.ConcurrencySupport
          extended by uk.org.retep.util.monitor.ProgressListenerSet
All Implemented Interfaces:
ProgressListener

@ThreadSafe
public class ProgressListenerSet
extends ConcurrencySupport
implements ProgressListener

A set of ProgressListener's that will receive the same events as received by this class. This enables more than one ProgressListener to be attached to a monitored process.

Author:
peter

Constructor Summary
ProgressListenerSet()
           
ProgressListenerSet(ProgressListener... listeners)
           
 
Method Summary
 boolean add(ProgressListener l)
          Add a ProgressListener to the set
static ProgressListener add(ProgressListener current, ProgressListener listener)
          Utility method that allows a ProgressListener to be added to an existing ProgressListener using the following schematics: If the current listener is null then this returns the new listener.
 ProgressListener[] getListeners()
          Returns a snapshot of the ProgressListener's currently in the set
 boolean isEmpty()
          Is the set empty.
 boolean remove(ProgressListener l)
          Remove a ProgressListener from the set
static ProgressListener remove(ProgressListener current, ProgressListener listener)
          Utility method that removes a ProgressListener from the current ProgressListener if that instance is a ProgressListenerSet.
 void setMaximum(long maximum)
          Notify the listeners that the maximum value has changed
 void setMaximum(long inputMaximum, long outputMaximum)
          Notify the listeners that the maximum value has changed
 void showProgress(int progress)
          Notify listeners of the current progress.
 void showProgress(long inputSize, long outputSize)
          Notify listners of the current progress.
 int size()
          The number of ProgressListener's in this set.
 
Methods inherited from class uk.org.retep.util.concurrent.ConcurrencySupport
getLog
 
Methods inherited from class uk.org.retep.util.concurrent.ReadWriteConcurrencySupport
readLock, writeLock
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ProgressListenerSet

public ProgressListenerSet()

ProgressListenerSet

public ProgressListenerSet(ProgressListener... listeners)
Method Detail

add

public static ProgressListener add(ProgressListener current,
                                   ProgressListener listener)
Utility method that allows a ProgressListener to be added to an existing ProgressListener using the following schematics:
  1. If the current listener is null then this returns the new listener.
  2. If the current listener is an instance of ProgressListenerSet then the new listener is added to it and the current listener is returned.
  3. If neither of the above are met a new ProgressListenerSet is created, and both the current and new listeners are added to it and the set is returned.

For example, a monotored process has an addProgressListener() method:

 private ProgressListener listener;

 public void addProgressListener( final ProgressListener newListener )
 {
      listener = ProgressListenerSet.add( listener, newListener );
 }
 

Parameters:
current - The current ProgressListener
listener - The ProgressListener to add
Returns:
a ProgressListener
Throws:
java.lang.IllegalArgumentException - if newListener is null

remove

public static ProgressListener remove(ProgressListener current,
                                      ProgressListener listener)
Utility method that removes a ProgressListener from the current ProgressListener if that instance is a ProgressListenerSet.

For example, a monotored process has an removeProgressListener() method:

 private ProgressListener listener;

 public void removeProgressListener( final ProgressListener newListener )
 {
      listener = ProgressListenerSet.remove( listener, newListener );
 }
 

Parameters:
current -
listener -
Returns:

add

@WriteLock
public boolean add(ProgressListener l)
Add a ProgressListener to the set

Parameters:
l - ProgressListener to add
Returns:
true if the set was modified

remove

@WriteLock
public boolean remove(ProgressListener l)
Remove a ProgressListener from the set

Parameters:
l - ProgressListener to remove
Returns:
true if the set was modified

isEmpty

@ReadLock
public boolean isEmpty()
Is the set empty. This value is a snapshot so is for informational use only.

Returns:
true if the set is empty

size

@ReadLock
public int size()
The number of ProgressListener's in this set. This value is a snapshot so is for informational use only.

Returns:

getListeners

@ReadLock
public ProgressListener[] getListeners()
Returns a snapshot of the ProgressListener's currently in the set

Returns:
array of ProgressListener's

showProgress

public void showProgress(int progress)
Description copied from interface: ProgressListener
Notify listeners of the current progress.

Specified by:
showProgress in interface ProgressListener
Parameters:
progress - The current value of the process

showProgress

public void showProgress(long inputSize,
                         long outputSize)
Description copied from interface: ProgressListener
Notify listners of the current progress. This method is normall used by compression routines so the listener knows how much the input has been compressed by

Specified by:
showProgress in interface ProgressListener
Parameters:
inputSize - The current size of the input, possibly the amount read so far
outputSize - The current size of the output, probably the total size of the compressed output

setMaximum

public void setMaximum(long maximum)
Description copied from interface: ProgressListener
Notify the listeners that the maximum value has changed

Specified by:
setMaximum in interface ProgressListener
Parameters:
maximum - The new maximum

setMaximum

public void setMaximum(long inputMaximum,
                       long outputMaximum)
Description copied from interface: ProgressListener
Notify the listeners that the maximum value has changed

Specified by:
setMaximum in interface ProgressListener
Parameters:
inputMaximum - The new maximum for the input
outputMaximum - The new maximum for the output.


Copyright © 1998-2010 Retep Development Group. All Rights Reserved.