com.emarsys.ecommon.time.schedule.mock
Class MockSchedulable

java.lang.Object
  extended by com.emarsys.ecommon.time.schedule.mock.MockSchedulable
All Implemented Interfaces:
SchedulableQueueElement<MockSchedulable>, GenericAdapter<MockSchedulable>

public class MockSchedulable
extends java.lang.Object
implements SchedulableQueueElement<MockSchedulable>

Mock implementation of SchedulableQueueElement for unit testing purposes.

Author:
Michael "kULO" Kulovits

Field Summary
protected  java.util.Calendar lastProcessing
           
protected  java.util.Calendar maxScheduleDate
           
protected  int minSchedulingInterval
           
protected  java.util.Calendar nextProcessing
           
protected  java.util.Calendar queueingDate
           
protected  int scheduledCount
           
 
Constructor Summary
MockSchedulable()
           
 
Method Summary
 MockSchedulable getConcreteInstance()
           
 java.util.Calendar getLastProcessing()
           Returns the schedulable's last processing date.
 java.util.Calendar getMaxScheduleDate()
           Returns the maximum schedule date which defines a date in the future and must not be exceeded on reschedulings.
 int getMinSchedulingInterval()
           Returns the minimal scheduling interval in milliseconds that is compulsory for this SchedulableQueueElement.
 java.util.Calendar getNextProcessing()
           Returns the next scheduled date which a priori is null.
 java.util.Calendar getQueueingDate()
           Returns the schedulable's queueing date.
 java.util.Calendar getScheduled(QueueScheduler<MockSchedulable> scheduler)
           (Re)schedules this queue element using the passed QueueScheduler.
 int getScheduledCount()
           Returns this queue element's scheduled count.
 java.util.Calendar now()
           Returns the schedulables notion of the current time.
 void setLastProcessing(java.util.Calendar lastProcessing)
           
 void setMaxScheduleDate(java.util.Calendar maxScheduleDate)
           
 void setMinSchedulingInterval(int minSchedulingInterval)
           
 void setNextProcessing(java.util.Calendar nextProcessing)
           
 void setQueueingDate(java.util.Calendar queueingDate)
           
 void setScheduledCount(int scheduledCount)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

scheduledCount

protected int scheduledCount

minSchedulingInterval

protected int minSchedulingInterval

queueingDate

protected java.util.Calendar queueingDate

lastProcessing

protected java.util.Calendar lastProcessing

nextProcessing

protected java.util.Calendar nextProcessing

maxScheduleDate

protected java.util.Calendar maxScheduleDate
Constructor Detail

MockSchedulable

public MockSchedulable()
Method Detail

getScheduled

public java.util.Calendar getScheduled(QueueScheduler<MockSchedulable> scheduler)
Description copied from interface: SchedulableQueueElement

(Re)schedules this queue element using the passed QueueScheduler.

The passed QueueScheduler will be used to retrieve a QueueSchedulingStrategy for this SchedulableQueueElement that will be used to calculate the date of the next processing which will be set to the new value, see SchedulableQueueElement.getNextProcessing().
Futhermore the last processing date will be set to the current time.

The SchedulableQueueElement must not set its next processing date to a value that's not at least SchedulableQueueElement.getMinSchedulingInterval() millis after the last processing date (which is SchedulableQueueElement.now() during SchedulableQueueElement.getScheduled(QueueScheduler)).

Specified by:
getScheduled in interface SchedulableQueueElement<MockSchedulable>
Parameters:
scheduler - - the QueueScheduler responsible for scheduling this instance.
Returns:
the new next scheduled date calculated by the passed QueueScheduler.
See Also:
SchedulableQueueElement.getScheduled(com.emarsys.ecommon.time.schedule.QueueScheduler)

getLastProcessing

public java.util.Calendar getLastProcessing()
Description copied from interface: SchedulableQueueElement

Returns the schedulable's last processing date.

The last scheduled date refers to the time of the last rescheduling, i.e. on the last call to SchedulableQueueElement.getScheduled(QueueScheduler) this value should have been set to SchedulableQueueElement.now().

A priori the last scheduled date is null.

Specified by:
getLastProcessing in interface SchedulableQueueElement<MockSchedulable>
Returns:
the last scheduled date, maybe null.
See Also:
SchedulableQueueElement.now()

setLastProcessing

public void setLastProcessing(java.util.Calendar lastProcessing)

getMaxScheduleDate

public java.util.Calendar getMaxScheduleDate()
Description copied from interface: SchedulableQueueElement

Returns the maximum schedule date which defines a date in the future and must not be exceeded on reschedulings.

Specified by:
getMaxScheduleDate in interface SchedulableQueueElement<MockSchedulable>
Returns:
a date in the future or null if there's no maximum restriction.

setMaxScheduleDate

public void setMaxScheduleDate(java.util.Calendar maxScheduleDate)

getNextProcessing

public java.util.Calendar getNextProcessing()
Description copied from interface: SchedulableQueueElement

Returns the next scheduled date which a priori is null.

Specified by:
getNextProcessing in interface SchedulableQueueElement<MockSchedulable>
Returns:
the next scheduled date, maybe null.

getMinSchedulingInterval

public int getMinSchedulingInterval()
Description copied from interface: SchedulableQueueElement

Returns the minimal scheduling interval in milliseconds that is compulsory for this SchedulableQueueElement.

On getting scheduled (see SchedulableQueueElement.getScheduled(QueueScheduler)) this schedulable must not set its next processing date either to a value >= (SchedulableQueueElement.now() + minSchedulingInterval) or to null (which is actually the dequeueing of the schedulable queue element).

Specified by:
getMinSchedulingInterval in interface SchedulableQueueElement<MockSchedulable>
Returns:
an integer > 0
See Also:
SchedulableQueueElement.getMinSchedulingInterval()

setMinSchedulingInterval

public void setMinSchedulingInterval(int minSchedulingInterval)
Parameters:
minSchedulingInterval - the minSchedulingInterval to set

setNextProcessing

public void setNextProcessing(java.util.Calendar nextProcessing)

getQueueingDate

public java.util.Calendar getQueueingDate()
Description copied from interface: SchedulableQueueElement

Returns the schedulable's queueing date.

The queueing date represents the timestamp when this SchedulableQueueElement has been added to the queuing mechanism.

Specified by:
getQueueingDate in interface SchedulableQueueElement<MockSchedulable>
Returns:
should return a Calendar instance representing a date in the past, must not be null.

setQueueingDate

public void setQueueingDate(java.util.Calendar queueingDate)

getScheduledCount

public int getScheduledCount()
Description copied from interface: SchedulableQueueElement

Returns this queue element's scheduled count.

The scheduled count specifies the number of times this SchedulableQueueElement got rescheduled, i.e. the number of calls to SchedulableQueueElement.getScheduled(QueueScheduler).
Thus a priori the scheduled count is 0.

Specified by:
getScheduledCount in interface SchedulableQueueElement<MockSchedulable>
Returns:
an int >= 0 representing the number of times this SchedulableQueueElement has been (re-)scheduled.

setScheduledCount

public void setScheduledCount(int scheduledCount)

now

public java.util.Calendar now()
Description copied from interface: SchedulableQueueElement

Returns the schedulables notion of the current time.

Might be a clone of the queueing date.

Specified by:
now in interface SchedulableQueueElement<MockSchedulable>
Returns:
a Calendar with the schedulables current time in its TimeZone.

getConcreteInstance

public MockSchedulable getConcreteInstance()
Specified by:
getConcreteInstance in interface GenericAdapter<MockSchedulable>
Returns:
this instance with its concrete type T.
See Also:
GenericAdapter.getConcreteInstance()


Copyright © 2010 emarsys AG. All Rights Reserved.