com.emarsys.ecommon.time.schedule
Class ChainElement<T>

java.lang.Object
  extended by com.emarsys.ecommon.time.schedule.ChainElement<T>
Type Parameters:
T -
All Implemented Interfaces:
java.lang.Cloneable

public class ChainElement<T>
extends java.lang.Object
implements java.lang.Cloneable

A ChainElement is a part of a QueueSchedulingStrategyChain and represents some kind of an execution context.

A ChainElement encapsulates a QueueSchedulingStrategy together with two a Predicates on ChainElements. The first one defines if said strategy should be executed (see fires()) if it's its turn in the chain and the second specifies whether or not the chain execution should proceed() after this ChainElement.

The ChainElement also serves as a communication object that transports the state of the chain execution to the next element being executed and thus saves the current result date, i.e. the one computed by the last strategy being executed, as well as the SchedulableQueueElement currently being processed. Either the result either the schedulable will be set/injected by the QueueSchedulingStrategyChain.

Author:
Michael "kULO" Kulovits


Field Summary
protected  org.apache.commons.collections.Predicate fire
           
protected  org.apache.commons.collections.Predicate proceed
           
protected  java.util.Calendar result
           
protected  SchedulableQueueElement<T> schedulable
           
protected  QueueSchedulingStrategy<T> strategy
           
 
Constructor Summary
ChainElement(QueueSchedulingStrategy<T> strategy)
          Creates a new ChainElement instance.
 
Method Summary
protected  void checkInvariants()
           
protected  java.lang.Object clone()
           
 boolean equals(java.lang.Object that)
           
 java.util.Calendar execute(QueueScheduler<T> scheduler)
          Executes the QueueSchedulingStrategy associated with this ChainElement and passed the schedulable and the passed scheduler as parameters to QueueSchedulingStrategy.calculateNextProcessing(QueueScheduler, SchedulableQueueElement).
 boolean fires()
           
 org.apache.commons.collections.Predicate getFire()
           
 org.apache.commons.collections.Predicate getProceed()
           
 java.util.Calendar getResult()
           
 SchedulableQueueElement<T> getSchedulable()
           
 QueueSchedulingStrategy<T> getStrategy()
           
 int hashCode()
           
 boolean proceed()
           
 void setFire(org.apache.commons.collections.Predicate fire)
           
 void setProceed(org.apache.commons.collections.Predicate proceed)
           
 void setResult(java.util.Calendar result)
           
 void setSchedulable(SchedulableQueueElement<T> schedulable)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

fire

protected org.apache.commons.collections.Predicate fire

strategy

protected QueueSchedulingStrategy<T> strategy

proceed

protected org.apache.commons.collections.Predicate proceed

schedulable

protected volatile SchedulableQueueElement<T> schedulable

result

protected volatile java.util.Calendar result
Constructor Detail

ChainElement

public ChainElement(QueueSchedulingStrategy<T> strategy)
Creates a new ChainElement instance.

Parameters:
fire -
strategy -
proceed -
Method Detail

checkInvariants

protected void checkInvariants()
                        throws java.lang.IllegalArgumentException
Throws:
java.lang.IllegalArgumentException

execute

public java.util.Calendar execute(QueueScheduler<T> scheduler)
                           throws java.lang.IllegalStateException
Executes the QueueSchedulingStrategy associated with this ChainElement and passed the schedulable and the passed scheduler as parameters to QueueSchedulingStrategy.calculateNextProcessing(QueueScheduler, SchedulableQueueElement). Implicitly overwrites the current result with the new one computed.

Parameters:
scheduler -
Returns:
the new result computed by the execution of this strategy.
Throws:
java.lang.IllegalStateException - - if this schedulable is not set at the time of the execution

fires

public boolean fires()
Parameters:
previous -
Returns:
true if this element's fire Predicate evaluates to true for the passed chain element, false otherwise.

proceed

public boolean proceed()
Parameters:
calendar -
Returns:
true if this element's proceed Predicate evaluates to true for the passed chain element, false otherwise.

getFire

public org.apache.commons.collections.Predicate getFire()
Returns:
the Predicate that defines whether this

getStrategy

public QueueSchedulingStrategy<T> getStrategy()
Returns:

getProceed

public org.apache.commons.collections.Predicate getProceed()
Returns:

getResult

public java.util.Calendar getResult()
Returns:

getSchedulable

public SchedulableQueueElement<T> getSchedulable()
Returns:

setProceed

public void setProceed(org.apache.commons.collections.Predicate proceed)
Parameters:
proceed -

setFire

public void setFire(org.apache.commons.collections.Predicate fire)
Parameters:
fire -

setResult

public void setResult(java.util.Calendar result)
Parameters:
result -

setSchedulable

public void setSchedulable(SchedulableQueueElement<T> schedulable)
Parameters:
schedulable -

clone

protected java.lang.Object clone()
                          throws java.lang.CloneNotSupportedException
Overrides:
clone in class java.lang.Object
Throws:
java.lang.CloneNotSupportedException
See Also:
Object.clone()

equals

public boolean equals(java.lang.Object that)
Overrides:
equals in class java.lang.Object
See Also:
Object.equals(java.lang.Object)

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object
See Also:
Object.hashCode()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
See Also:
Object.toString()


Copyright © 2010 emarsys AG. All Rights Reserved.