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

All Superinterfaces:
GenericAdapter<T>
All Known Implementing Classes:
MockSchedulable, SchedulableQueueElementProxy

public interface SchedulableQueueElement<T>
extends GenericAdapter<T>

A SchedulableQueueElement represents an object that will be processed in an arbitrary time based queueing mechanism.

The schedulable holds information about several timestamps in its queueing context and thus has implicitly an assigned TimeZone and Locale because Calendar objects have to agree on them.
The schedulable for instance stores when it has been queued, how often it has been (re-) processed, when it was processed the last time, when there is the next date to be processed, what's the minimum interval between two processings and optionally a maximum schedule date.
There are some asumptions on this data:

The lifecycle of a SchedulableQueueElement should look like this:

  1. queueing, setting of queuing date, last and next processing dates are apriori unset, i.e. null
  2. first processing, setting of last processing date to the current time, then...
    1. unqueueing - processing successful/finished or maximum schedule interval reached
    2. rescheduling - processing not successful/finished yet and max interval not yet reached, calculation and setting of next processing date
  3. all further processings are analogous to the first one

The schedulable itself is responsible for updating its properties (count, last- and next processing date) during being scheduled by an QueueScheduler, see getScheduled(QueueScheduler); because of this there are only getter methods in the SchedulableQueueElement interface - to a QueueScheduler or QueueSchedulingStrategy a schedulable element therefore "feels" like an immutable/read-only object.

Author:
Michael "kULO" Kulovits

See Also:
QueueScheduler,


Method Summary
 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<T> 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.
 
Methods inherited from interface com.emarsys.ecommon.util.GenericAdapter
getConcreteInstance
 

Method Detail

now

java.util.Calendar now()

Returns the schedulables notion of the current time.

Might be a clone of the queueing date.

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

getQueueingDate

java.util.Calendar getQueueingDate()

Returns the schedulable's queueing date.

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

Returns:
should return a Calendar instance representing a date in the past, must not be null.

getLastProcessing

java.util.Calendar getLastProcessing()

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 getScheduled(QueueScheduler) this value should have been set to now().

A priori the last scheduled date is null.

Returns:
the last scheduled date, maybe null.
See Also:
now()

getNextProcessing

java.util.Calendar getNextProcessing()

Returns the next scheduled date which a priori is null.

Returns:
the next scheduled date, maybe null.

getMaxScheduleDate

java.util.Calendar getMaxScheduleDate()

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

Returns:
a date in the future or null if there's no maximum restriction.

getMinSchedulingInterval

int getMinSchedulingInterval()

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

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

Returns:
an integer > 0

getScheduledCount

int getScheduledCount()

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 getScheduled(QueueScheduler).
Thus a priori the scheduled count is 0.

Returns:
an int >= 0 representing the number of times this SchedulableQueueElement has been (re-)scheduled.

getScheduled

java.util.Calendar getScheduled(QueueScheduler<T> scheduler)

(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 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 getMinSchedulingInterval() millis after the last processing date (which is now() during getScheduled(QueueScheduler)).

Parameters:
scheduler - - the QueueScheduler responsible for scheduling this instance.
Returns:
the new next scheduled date calculated by the passed QueueScheduler.


Copyright © 2010 emarsys AG. All Rights Reserved.