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

java.lang.Object
  extended by com.emarsys.ecommon.time.schedule.QueueSchedulingStrategyChain<T>
All Implemented Interfaces:
QueueSchedulingStrategy<T>

public class QueueSchedulingStrategyChain<T>
extends java.lang.Object
implements QueueSchedulingStrategy<T>

A QueueSchedulingStrategyChain implements a chain of responsibility for queue scheduling strategies whilest being a composited strategy itself and can be used to create arbitrary, dynamic combinations of existing scheduling algorithms.

The QueueSchedulingStrategyChain design is inspired by the GOF design patterns "Chain of Responsibilty", "Composite" and "Strategy" although not being very puristic in their implementation.

As said a QueueSchedulingStrategyChain is an aggregation of several concrete QueueSchedulingStrategy objects that form a strategy themselves. The "chain" is realised as a List of ChainElements.
See calculateNextProcessing(QueueScheduler, SchedulableQueueElement) for detailed informations on the execution flow of the chain.

As defined in QueueSchedulingStrategy's contract the configuration/setting of a strategy has to be frozen after its instantiation, thus it's immutable.
In order to not being forced to create a List of ChainElements "manually" a ChainFactory can be obtained by calling #getFactory(Object) which is used to build the chain step by step.
If you want to change the chain's elements you have to create a new instance - you can easily achieve this by calling getCloneFactory().

Author:
Michael "kULO" Kulovits

See Also:
QueueSchedulingStrategy,


Field Summary
protected  java.util.List<ChainElement<T>> elements
           
 
Constructor Summary
QueueSchedulingStrategyChain(java.util.List<ChainElement<T>> elements)
          Creates a new QueueSchedulingStrategyChain consisting of the passed ChainElements.
 
Method Summary
 java.util.Calendar calculateNextProcessing(QueueScheduler<T> scheduler, SchedulableQueueElement<T> schedulable)
          Calculates the next processing date by iterating over the strategy chain elements and for every instance...
 ChainFactory<T> getCloneFactory()
          Allows for "indirect cloning" of QueueSchedulingStrategyChains which could be altered through the ChainFactory returned.
static
<T> ChainFactory<T>
getFactory(QueueSchedulingStrategy<T> strategy)
          Creates a ChainFactory for the concrete strategy instance (which is only used to bind the type parameter and ensure/enable type safety) passed.
static
<T> ChainFactory<T>
getFactory(SchedulableQueueElement<T> schedulable)
          Creates a ChainFactory for the concrete schedulable instance (which is only used to bind the type parameter and ensure/enable type safety) passed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

elements

protected final java.util.List<ChainElement<T>> elements
Constructor Detail

QueueSchedulingStrategyChain

public QueueSchedulingStrategyChain(java.util.List<ChainElement<T>> elements)
Creates a new QueueSchedulingStrategyChain consisting of the passed ChainElements.

Parameters:
elements -
Method Detail

getFactory

public static <T> ChainFactory<T> getFactory(SchedulableQueueElement<T> schedulable)
Creates a ChainFactory for the concrete schedulable instance (which is only used to bind the type parameter and ensure/enable type safety) passed.


getFactory

public static <T> ChainFactory<T> getFactory(QueueSchedulingStrategy<T> strategy)
Creates a ChainFactory for the concrete strategy instance (which is only used to bind the type parameter and ensure/enable type safety) passed.


calculateNextProcessing

public java.util.Calendar calculateNextProcessing(QueueScheduler<T> scheduler,
                                                  SchedulableQueueElement<T> schedulable)
Calculates the next processing date by iterating over the strategy chain elements and for every instance...

Specified by:
calculateNextProcessing in interface QueueSchedulingStrategy<T>
Parameters:
scheduler - - the QueueScheduler that is associated with this strategy instance
schedulable - - the SchedulableQueueElement that will be (re)scheduled
Returns:
the Calendar object representing the next processing date - might be null.
See Also:
QueueSchedulingStrategy.calculateNextProcessing(com.emarsys.ecommon.time.schedule.QueueScheduler, com.emarsys.ecommon.time.schedule.SchedulableQueueElement)

getCloneFactory

public ChainFactory<T> getCloneFactory()
Allows for "indirect cloning" of QueueSchedulingStrategyChains which could be altered through the ChainFactory returned.

Returns:
a ChainFactory instance that is initalized with the same elements as this instance.


Copyright © 2010 emarsys AG. All Rights Reserved.