com.emarsys.ecommon.time.schedule.mock
Class MockQueueScheduler<T>

java.lang.Object
  extended by com.emarsys.ecommon.time.schedule.mock.MockQueueScheduler<T>
All Implemented Interfaces:
QueueScheduler<T>

public class MockQueueScheduler<T>
extends java.lang.Object
implements QueueScheduler<T>

Mock implementation of QueueScheduler for unit testing purposes.

Author:
Michael "kULO" Kulovits

Field Summary
protected  java.util.Map<SchedulableQueueElement<T>,QueueSchedulingContext<T>> contexts
           
protected  java.util.Map<SchedulableQueueElement<T>,QueueSchedulingStrategy<T>> strategies
           
 
Constructor Summary
MockQueueScheduler(java.lang.Class<T> concreteSchedulableClass)
           
 
Method Summary
 QueueSchedulingContext<T> getContext(SchedulableQueueElement<T> schedulable)
           Retrieves the QueueSchedulingContext for the passed SchedulableQueueElement.
static MockQueueScheduler<MockSchedulable> getInstance()
           
static
<T> MockQueueScheduler<T>
getInstance(java.lang.Class<T> concreteSchedulableClass)
           
 QueueSchedulingStrategy<T> getSchedulingStrategy(SchedulableQueueElement<T> schedulable)
          Will create and initialize/configure a new strategy instance if not yet present.
 java.util.Map<SchedulableQueueElement<T>,QueueSchedulingStrategy<T>> getStrategies()
           
 java.util.Calendar now()
          Creates a new Calendar with the schedulers current time in its TimeZone representing the current time.
 QueueSchedulingStrategy<T> register(SchedulableQueueElement<T> schedulable, QueueSchedulingStrategy<T> strategy)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

strategies

protected final java.util.Map<SchedulableQueueElement<T>,QueueSchedulingStrategy<T>> strategies

contexts

protected final java.util.Map<SchedulableQueueElement<T>,QueueSchedulingContext<T>> contexts
Constructor Detail

MockQueueScheduler

public MockQueueScheduler(java.lang.Class<T> concreteSchedulableClass)
Method Detail

getInstance

public static final MockQueueScheduler<MockSchedulable> getInstance()
Returns:

getInstance

public static final <T> MockQueueScheduler<T> getInstance(java.lang.Class<T> concreteSchedulableClass)
Type Parameters:
T -
Parameters:
concreteSchedulableClass -
Returns:

getSchedulingStrategy

public QueueSchedulingStrategy<T> getSchedulingStrategy(SchedulableQueueElement<T> schedulable)
Description copied from interface: QueueScheduler
Will create and initialize/configure a new strategy instance if not yet present.

Specified by:
getSchedulingStrategy in interface QueueScheduler<T>
Returns:
the QueueSchedulingStrategy instance associated with the passed schedulable.
See Also:
com.emarsys.ecommon.time.schedule.QueueScheduler#getSchedulingStrategy()

register

public QueueSchedulingStrategy<T> register(SchedulableQueueElement<T> schedulable,
                                           QueueSchedulingStrategy<T> strategy)
Parameters:
key -
value -
Returns:

getStrategies

public java.util.Map<SchedulableQueueElement<T>,QueueSchedulingStrategy<T>> getStrategies()
Returns:

now

public java.util.Calendar now()
Description copied from interface: QueueScheduler
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.

Specified by:
now in interface QueueScheduler<T>
Returns:
a Calendar with the schedulers current time in its TimeZone.
See Also:
QueueScheduler.now()

getContext

public QueueSchedulingContext<T> getContext(SchedulableQueueElement<T> schedulable)
Description copied from interface: QueueScheduler

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.

Specified by:
getContext in interface QueueScheduler<T>
Parameters:
schedulable - - the SchedulableQueueElement
Returns:
always a valid QueueSchedulingContext instance associated with this QueueScheduler and the passed SchedulableQueueElement; never null.
See Also:
QueueScheduler.getContext(com.emarsys.ecommon.time.schedule.SchedulableQueueElement)


Copyright © 2010 emarsys AG. All Rights Reserved.