FreeHEP API
Version current

org.freehep.record.loop
Class SequentialRecordLoopImpl

java.lang.Object
  extended byorg.freehep.record.loop.SequentialRecordLoopImpl
All Implemented Interfaces:
RecordListenerManager, SequentialRecordLoop

public class SequentialRecordLoopImpl
extends Object
implements SequentialRecordLoop

This class is the default implementation of the SequentialRecordLoop interface. This class is minimally thread safe i.e. only the "setInterruptResquested" and "isInterruptRequested" methods are considered thread safe. The rest of the implementation is designed to run in a single thread. When its RecordListener responses to any RecordEvents, a return from that method signals that the listener has completed all responsibilities related to that message.

Version:
$Id: SequentialRecordLoopImpl.java,v 1.2 2004/01/19 21:23:51 duns Exp $
Author:
patton
Source Code:
SequentialRecordLoopImpl.java

Constructor Summary
SequentialRecordLoopImpl()
          Create an instance of this class.
SequentialRecordLoopImpl(SequentialRecordSource supplier)
          Create an instance of this class with the specified SequentialRecordSource.
 
Method Summary
 void addRecordListener(RecordListener listener)
          Adds the specified RecordListener to this object.
 void addRecordLoopListener(RecordLoopListener listener)
          Adds the specified RecordLoopListener to this object.
 void dispose()
          Signals that this object in no longer going to be used.
 void doNotCount(Object record)
          Tells this object that if it is currently supplying the specified record then it should not be added to the "countable" record total.
 RecordListener getRecordListener()
          Returns this objects RecordListener if there is one.
 SequentialRecordSource getRecordSource()
          Returns the SequentialRecordSource used by this object.
 long getTotalCountableSupplied()
          Returns the total number of countable records supplied.
 long getTotalSupplied()
          Returns the total number of records supplied.
 boolean isInterruptRequested()
          Returns true if an interrupt has been requested and the loop method has not yet returned.
 long loop(long number)
          Processes the specified number of records through the record loop.
 void removeRecordListener(RecordListener listener)
          Removes the specified listener from this object if it is this objects listener, otherwise it does nothing.
 void removeRecordLoopListener(RecordLoopListener listener)
          Removes the specified listener from this object if it is this objects listener, otherwise it does nothing.
 void reset()
          Resets the loop so that the next time loop is called this object will behave as if the previous calls to loop never happened.
 void setConfiguration(Object configuration)
          Sets the configuration object which should be passed to this objects RecordListener next time the loop(long) method is invoked.
 void setInterruptRequested(boolean interruptRequested)
          This method can either request that the loop method terminate when it has finished dealing with all its current data or clear such a request.
 void setProgessByRecords(long records)
          Set the progress reporting interval in terms of records.
 void setProgessByTime(long milliseconds)
          Set the progress reporting interval in terms of milliseconds.
 void setRecordSource(SequentialRecordSource supplier)
          Sets this objects SequentialRecordSource to the one that is specified.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SequentialRecordLoopImpl

public SequentialRecordLoopImpl()
Create an instance of this class.


SequentialRecordLoopImpl

public SequentialRecordLoopImpl(SequentialRecordSource supplier)
Create an instance of this class with the specified SequentialRecordSource.

Parameters:
supplier - the SequentialRecordSource to use with this object.
See Also:
setRecordSource(org.freehep.record.source.SequentialRecordSource)
Method Detail

addRecordListener

public void addRecordListener(RecordListener listener)
                       throws TooManyListenersException
Description copied from interface: RecordListenerManager
Adds the specified RecordListener to this object.

Specified by:
addRecordListener in interface RecordListenerManager
Parameters:
listener - the RecordListener to add.
Throws:
TooManyListenersException - if a listener is already present.
See Also:
RecordListenerManager.removeRecordListener(org.freehep.record.loop.event.RecordListener)

addRecordLoopListener

public void addRecordLoopListener(RecordLoopListener listener)
Description copied from interface: SequentialRecordLoop
Adds the specified RecordLoopListener to this object.

Specified by:
addRecordLoopListener in interface SequentialRecordLoop
Parameters:
listener - the RecordLoopListener to add.
See Also:
SequentialRecordLoop.removeRecordLoopListener(org.freehep.record.loop.event.RecordLoopListener)

dispose

public void dispose()
Description copied from interface: SequentialRecordLoop
Signals that this object in no longer going to be used. If this object has a RecordListener, then the listener is passed a finish event.

Specified by:
dispose in interface SequentialRecordLoop

doNotCount

public void doNotCount(Object record)
Description copied from interface: SequentialRecordLoop
Tells this object that if it is currently supplying the specified record then it should not be added to the "countable" record total.

Specified by:
doNotCount in interface SequentialRecordLoop
Parameters:
record - the recornd that should not be counted.

getRecordListener

public RecordListener getRecordListener()
Description copied from interface: RecordListenerManager
Returns this objects RecordListener if there is one.

Specified by:
getRecordListener in interface RecordListenerManager
Returns:
this objects RecordListener if there is one.

getRecordSource

public SequentialRecordSource getRecordSource()
Description copied from interface: SequentialRecordLoop
Returns the SequentialRecordSource used by this object.

Specified by:
getRecordSource in interface SequentialRecordLoop
Returns:
the SequentialRecordSource used by this object.

getTotalSupplied

public long getTotalSupplied()
Description copied from interface: SequentialRecordLoop
Returns the total number of records supplied.

Specified by:
getTotalSupplied in interface SequentialRecordLoop
Returns:
the total number of records supplied.

getTotalCountableSupplied

public long getTotalCountableSupplied()
Description copied from interface: SequentialRecordLoop
Returns the total number of countable records supplied.

Specified by:
getTotalCountableSupplied in interface SequentialRecordLoop
Returns:
the total number of countable records supplied.

isInterruptRequested

public boolean isInterruptRequested()
Description copied from interface: SequentialRecordLoop
Returns true if an interrupt has been requested and the loop method has not yet returned. As the interrupt may come for another thread this method must always be implemented in a thread-safe manner.

Specified by:
isInterruptRequested in interface SequentialRecordLoop
Returns:
true if an interrupt has been requested and the loop method has not yet returned.

loop

public long loop(long number)
          throws LoopException,
                 IOException
Description copied from interface: SequentialRecordLoop
Processes the specified number of records through the record loop. If the number of records is specified to be less than zero then the loop will continue until this objects SequentialRecordSource throws a LoopSourceExhaustedException respose to its getCurrentRecord method. If the SequentialRecordLoop.doNotCount(java.lang.Object) method is called while this method is executing and its argument is a record that is currently being supplied by this object then that record will not count towards the specified number of records requested. Nor will it be counted in the return value of this method. If the loop is interrupted before it is completed then a LoopInterruptedException is thrown, even if the requested number of records have been supplied. The number of completed countable records is contained in the LoopInterruptedException so\ this value can be used to determine whether all requested records where supplied on not.

Specified by:
loop in interface SequentialRecordLoop
Parameters:
number - the number of countable records to supply.
Returns:
the number of countable records that have been supplied.
Throws:
IOException - if there is problems reading a record.
LoopException

removeRecordListener

public void removeRecordListener(RecordListener listener)
Description copied from interface: RecordListenerManager
Removes the specified listener from this object if it is this objects listener, otherwise it does nothing. If removed, a finish event is sent to the listener if it has been configured so that is can clean up any resources it holds.

Specified by:
removeRecordListener in interface RecordListenerManager
Parameters:
listener - the RecordListener to remove.
See Also:
RecordListenerManager.addRecordListener(org.freehep.record.loop.event.RecordListener)

removeRecordLoopListener

public void removeRecordLoopListener(RecordLoopListener listener)
Description copied from interface: SequentialRecordLoop
Removes the specified listener from this object if it is this objects listener, otherwise it does nothing.

Specified by:
removeRecordLoopListener in interface SequentialRecordLoop
Parameters:
listener - the RecordLoopListener to remove.
See Also:
SequentialRecordLoop.addRecordLoopListener(org.freehep.record.loop.event.RecordLoopListener)

reset

public void reset()
           throws IOException
Description copied from interface: SequentialRecordLoop
Resets the loop so that the next time loop is called this object will behave as if the previous calls to loop never happened. This means that this object's SequentialRecordSource will have its rewing method called while the objects listener, if it exists, will be sent a finish event. At the next loop call the listener will receive a configure event rather than a reconfigure or resume event.

Specified by:
reset in interface SequentialRecordLoop
Throws:
IOException - if there is problems rewinding this object's source.

setConfiguration

public void setConfiguration(Object configuration)
Description copied from interface: SequentialRecordLoop
Sets the configuration object which should be passed to this objects RecordListener next time the SequentialRecordLoop.loop(long) method is invoked. If this method is called any time after the first loop invocation (even with the same configuration object) then a reconfigure event will be used to start the next loop. Otherwise the next loop will start with a resume event.

Specified by:
setConfiguration in interface SequentialRecordLoop
Parameters:
configuration - the configuration object to pass to this object's RecordListener.

setInterruptRequested

public void setInterruptRequested(boolean interruptRequested)
Description copied from interface: SequentialRecordLoop
This method can either request that the loop method terminate when it has finished dealing with all its current data or clear such a request. For a meaningful interrupt to happen it must come from a thread other than the one executing the loop method, therefore this method must always be implemented in a thread-safe manner.

Specified by:
setInterruptRequested in interface SequentialRecordLoop
Parameters:
interruptRequested - true if the loop should be interrupted.

setProgessByRecords

public void setProgessByRecords(long records)
Description copied from interface: SequentialRecordLoop
Set the progress reporting interval in terms of records. This number is only a guideline to the the loop, which can choose to ignore it wishes. If the loop if it is observing both guidelines and the interval has been specified by both time and number of records, the interval which expired first should be the one used by the loop. If neither method has been used to specify an interval the the loop will use a sensible defaualt. A value of zero or less with effectively remove any guideline that has been set.

Specified by:
setProgessByRecords in interface SequentialRecordLoop
Parameters:
records - the number of records between progress reports.

setProgessByTime

public void setProgessByTime(long milliseconds)
Description copied from interface: SequentialRecordLoop
Set the progress reporting interval in terms of milliseconds. This number is only a guideline to the the loop, which can choose to ignore it wishes. If the loop if it is observing both guidelines and the interval has been specified by both time and number of records, the interval which expired first should be the one used by the loop. If neither method has been used to specify an interval the the loop will use a sensible defaualt. A value of zero or less with effectively remove any guideline that has been set.

Specified by:
setProgessByTime in interface SequentialRecordLoop
Parameters:
milliseconds - the number of milliseconds between progress reports.

setRecordSource

public void setRecordSource(SequentialRecordSource supplier)
Description copied from interface: SequentialRecordLoop
Sets this objects SequentialRecordSource to the one that is specified. If this object already has a SequentialRecordSource it will be replaced by the new one.

Specified by:
setRecordSource in interface SequentialRecordLoop
Parameters:
supplier - the SequentialRecordSource to use with this object.

FreeHEP API
Version current

Copyright © 2000-2004 FreeHEP, All Rights Reserved.