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

java.lang.Object
  extended by com.emarsys.ecommon.time.schedule.LinearQueueSchedulingStrategy<T>
Type Parameters:
T -
All Implemented Interfaces:
QueueSchedulingStrategy<T>

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

LinearQueueSchedulingStrategy will compute the next processing date by linearly scaling its intervalMillis with the number of already happend reschedulings thus resulting in a linear increase of the intervals.
The linear scaling behavior on reschedulings can be delayed by setting delayCount which is 0 if not done so. See calculateScalingFactor(SchedulableQueueElement) for further details on the scaling behavior.

Author:
Michael "kULO" Kulovits

Field Summary
protected  int delayCount
           
protected  int intervalMillis
           
 
Constructor Summary
LinearQueueSchedulingStrategy(int intervalMillis)
          Creates a new LinearQueueSchedulingStrategy instance with the passed intervalMillis and no delayCount.
LinearQueueSchedulingStrategy(int intervalMillis, int delayCount)
          Creates a new LinearQueueSchedulingStrategy instance with the passed intervalMillis and delayCount.
 
Method Summary
 java.util.Calendar calculateNextProcessing(QueueScheduler<T> scheduler, SchedulableQueueElement<T> schedulable)
          Calculates the next processing date by adding the intervalMillis multiplied with a scaling factor (see calculateScalingFactor(SchedulableQueueElement)) to the current time.
protected  int calculateScalingFactor(SchedulableQueueElement<T> schedulable)
          Calculates the factor the intervalMillis should be scalied with linearly as the maximum of 1 and (SchedulableQueueElement.getScheduledCount() + 1 - delayCount)
The delayCount, nomen es omen, thus is used to specify the number of times the LinearQueueSchedulingStrategy should do a constant rescheduling just like the ConstantQueueSchedulingStrategy before proceeding with the linear scaling.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

intervalMillis

protected final int intervalMillis

delayCount

protected final int delayCount
Constructor Detail

LinearQueueSchedulingStrategy

public LinearQueueSchedulingStrategy(int intervalMillis)
Creates a new LinearQueueSchedulingStrategy instance with the passed intervalMillis and no delayCount.

Parameters:
intervalMillis -

LinearQueueSchedulingStrategy

public LinearQueueSchedulingStrategy(int intervalMillis,
                                     int delayCount)
Creates a new LinearQueueSchedulingStrategy instance with the passed intervalMillis and delayCount.

Parameters:
intervalMillis -
delayCount -
Method Detail

calculateScalingFactor

protected int calculateScalingFactor(SchedulableQueueElement<T> schedulable)
Calculates the factor the intervalMillis should be scalied with linearly as the maximum of 1 and (SchedulableQueueElement.getScheduledCount() + 1 - delayCount)
The delayCount, nomen es omen, thus is used to specify the number of times the LinearQueueSchedulingStrategy should do a constant rescheduling just like the ConstantQueueSchedulingStrategy before proceeding with the linear scaling.
The '+1' in the above formula is needed because a SchedulableQueueElement.getScheduledCount() specifies the number prior scheduling, exclusive the current one.

Parameters:
schedulable -
Returns:
an int >= 1

calculateNextProcessing

public java.util.Calendar calculateNextProcessing(QueueScheduler<T> scheduler,
                                                  SchedulableQueueElement<T> schedulable)
Calculates the next processing date by adding the intervalMillis multiplied with a scaling factor (see calculateScalingFactor(SchedulableQueueElement)) to the current time.

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 next scheduled date for the passed SchedulableQueueElement

See Also:
QueueSchedulingStrategy.calculateNextProcessing(com.emarsys.ecommon.time.schedule.QueueScheduler, com.emarsys.ecommon.time.schedule.SchedulableQueueElement)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
See Also:
Object.toString()


Copyright © 2010 emarsys AG. All Rights Reserved.