com.emarsys.ecommon.time.schedule
Interface QueueScheduler<T>

All Known Implementing Classes:
MockQueueScheduler

public interface QueueScheduler<T>

A QueueScheduler manages the time of the processing of SchedulableQueueElements in a queue using a QueueSchedulingStrategy to calculate the date when a queue element should be processed.

The QueueScheduler represents a mapping of QueueSchedulingStrategy instances to SchedulableQueueElements and is not intended to do the actual queueing or unqueueing of the elements to be processed, neither it's responsible for the processing itself but solely to provide (and initialize) an apropriate QueueSchedulingStrategy that will do the actual computation of the next schedule date; thus a QueueScheduler can be seen as some kind of strategy factory.

Neither the QueueScheduler nor the QueueSchedulingStrategy are responsible for changing the schedulable element's state, this is left to the latter itself in its SchedulableQueueElement.getScheduled(QueueScheduler) method.
This should increase the reusability of schedulers and strategys.

Author:
Michael "kULO" Kulovits

See Also:
QueueSchedulingStrategy,


Method Summary
 QueueSchedulingContext<T> getContext(SchedulableQueueElement<T> schedulable)
           Retrieves the QueueSchedulingContext for the passed SchedulableQueueElement.
 QueueSchedulingStrategy<T> getSchedulingStrategy(SchedulableQueueElement<T> schedulable)
          Will create and initialize/configure a new strategy instance if not yet present.
 java.util.Calendar now()
          Creates a new Calendar with the schedulers current time in its TimeZone representing the current time.
 

Method Detail

getSchedulingStrategy

QueueSchedulingStrategy<T> getSchedulingStrategy(SchedulableQueueElement<T> schedulable)
Will create and initialize/configure a new strategy instance if not yet present.

Returns:
the QueueSchedulingStrategy instance associated with the passed schedulable.

now

java.util.Calendar now()
Creates a new Calendar with the schedulers current time in its TimeZone representing the current time. All Calendar instances in the context of queue scheduling should be created through this method in order to prevent mismatching TimeZones or Locale. Furthermore if this is used as a factory method for dates it enables easier testing because progressing time could easily be mocked.

Returns:
a Calendar with the schedulers current time in its TimeZone.

getContext

QueueSchedulingContext<T> getContext(SchedulableQueueElement<T> schedulable)

Retrieves the QueueSchedulingContext for the passed SchedulableQueueElement. If no such context is present a new instance will be created and registered with the QueueScheduler.

The QueueSchedulingContext is used to save parameters that are associated with a specific scheduling process.

Parameters:
schedulable - - the SchedulableQueueElement
Returns:
always a valid QueueSchedulingContext instance associated with this QueueScheduler and the passed SchedulableQueueElement; never null.


Copyright © 2010 emarsys AG. All Rights Reserved.