BEA Systems, Inc.

com.bea.rfid.workflow.util
Class Accumulator

java.lang.Object
  extended by com.bea.rfid.workflow.util.Accumulator

public class Accumulator
extends Object

Plain java class for accumulating tags. This keeps track of unique tags list and sends them out to registered observers after the specified accumulation period or after the tags list has been stable for the specified stable set duration. This may also be used without specifying accumulation duration or stable set duration, in which case, it is the responsibility of the caller to get the accumulated tags and reset this as needed.


Constructor Summary
Accumulator(long stableSetTimeout, int stableSetCount, Timer timer)
          Constructor.
 
Method Summary
 List add(List tagList)
          Add unique tags from the list of ECReportGroupListMember to current accumulated tags list, if this accumulator is in active state.
 List delete(List tagList)
          Deletes tags from the list of ECReportGroupListMember from current accumulated tags list, if this accumulator is in active state.
 List getAccumulatedTagList()
          Returns the current list of accumulated tags.
 boolean isActive()
          Returns boolean indicating if this is active or not.
 void registerObserver(AccumulationObserver accumulationObserver)
          Registers an AccumulationObserver as the one that will be notified with the accumulated tags when the accumulation duration or stable set duration expires.
 void reset()
          Clears the currently accumulated tags list and resets this accumulator to inactive state.
 void shutdown()
          Releases any resources used by this accumulator and cancels its timer tasks.
 void startAccumulating()
          Moves this accumulator to active state and starts accumulating.
 void startAccumulating(long accumulationDuration)
          Moves this accumulator to active state and starts accumulating for the specified duration.
 void unregisterObserver()
          Unregisters the existing AccumulationObserver from this.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Accumulator

public Accumulator(long stableSetTimeout,
                   int stableSetCount,
                   Timer timer)
Constructor.

Parameters:
stableSetTimeout - time in milliseconds for which the tag list must be unchanged, before the accumulation is considered finished. Values <= 0 means no stable set timeout.
stableSetCount - the minimum number of tags that must be present in the accumulated tag list to activate stable set timeout. For example, if stable set count of 5 is specified and tag list of size 2 has been unchanged for the specified stable set timeout, the accumulation is not considered finished. If stable set count of 5 is specified and tag list of size 5 or more has been unchanged for the specified stable set timeout, that accumulation will be considered finished and observers notified.

This parameter must be >= 0.

timer - java.util.Timer object for scheduling TimerTasks for accumulation duration and stable set duration
Throws:
IllegalArgumentException - if negative stableSetCount is passed in or null value is passed in for timer
Method Detail

isActive

public boolean isActive()
Returns boolean indicating if this is active or not. When accumulator is not active it ignores tags it receives through add and delete methods.

Returns:
boolean indicating if this is active or not. Returns true if this accumulator is active; false otherwise.

getAccumulatedTagList

public List getAccumulatedTagList()
Returns the current list of accumulated tags.

This method should be used to get the accumulated tags when there is no accumulation period or stable set timeout specified. A call to reset() will finish the current accumulation.

This method may also be used to simply know the progress by getting the current accumulated tags.

Returns:
current list of accumulated tags

reset

public void reset()
Clears the currently accumulated tags list and resets this accumulator to inactive state.


startAccumulating

public void startAccumulating()
Moves this accumulator to active state and starts accumulating. No accumulation duration can be specified through this method. Therefore, if there is no stable set timeout specified as well on this accumulator, it will keep on accumulating tags until the user finishes the accumulation by calling reset.

This does nothing if the accumulator is already active.


startAccumulating

public void startAccumulating(long accumulationDuration)
Moves this accumulator to active state and starts accumulating for the specified duration. Observers will be notified with the accumulated tags after the specified duration expires.

Parameters:
accumulationDuration - the duration in milliseconds for which tags must be accumulated. This value must be >=0.
Throws:
IllegalArgumentException - if the specified accumulation duration is not >=0

registerObserver

public void registerObserver(AccumulationObserver accumulationObserver)
Registers an AccumulationObserver as the one that will be notified with the accumulated tags when the accumulation duration or stable set duration expires. This currently supports only one observer and hence will overwrite the any existing observer in this accumulator.

Parameters:
accumulationObserver - AccumulationObserver interested in receiving tag accumulation result when stable set or accumulation duration expires

unregisterObserver

public void unregisterObserver()
Unregisters the existing AccumulationObserver from this.


add

public List add(List tagList)
Add unique tags from the list of ECReportGroupListMember to current accumulated tags list, if this accumulator is in active state. The list is ignored if the accumulator is not active. If a tag in this list already exists in the accumulated list, that will be ignored.

The current list after the add operation is returned.

Parameters:
tagList - list of ECReportGroupListMember to be added to the accumulated tags list
Returns:
the current list after the add operation

delete

public List delete(List tagList)
Deletes tags from the list of ECReportGroupListMember from current accumulated tags list, if this accumulator is in active state. The list is ignored if the accumulator is not active.

The current list after the delete operation is returned.

Parameters:
tagList - list of ECReportGroupListMember to be removed from the accumulated tags list
Returns:
the current list after the delete operation

shutdown

public void shutdown()
Releases any resources used by this accumulator and cancels its timer tasks. This method must be called once this accumulator is no longer needed.


Documentation is available at
${DOCSWEBROOT}
Copyright 2007 BEA Systems Inc.