Package org.drools.core.time.impl
Class PseudoClockScheduler
- java.lang.Object
-
- org.drools.core.time.impl.PseudoClockScheduler
-
- All Implemented Interfaces:
java.io.Externalizable
,java.io.Serializable
,InternalSchedulerService
,SchedulerService
,SessionPseudoClock
,TimerService
,org.kie.api.time.SessionClock
,org.kie.api.time.SessionPseudoClock
public class PseudoClockScheduler extends java.lang.Object implements TimerService, SessionPseudoClock, java.io.Externalizable, InternalSchedulerService
A PseudoClockScheduler is a scheduler based on a user controlled clock that allows the user to explicitly control current time.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.concurrent.atomic.AtomicLong
idCounter
protected java.util.PriorityQueue<TimerJobInstance>
queue
protected java.util.concurrent.atomic.AtomicLong
timer
-
Constructor Summary
Constructors Constructor Description PseudoClockScheduler()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description long
advanceTime(long amount, java.util.concurrent.TimeUnit unit)
long
getCurrentTime()
Returns the current time from the scheduler clockTimerJobFactoryManager
getTimerJobFactoryManager()
java.util.Collection<TimerJobInstance>
getTimerJobInstances(long id)
This method may return null for some TimerService implementations that do not want the overhead of maintain this.long
getTimeToNextJob()
Returns the number of time units (usually ms) to the next scheduled jobvoid
internalSchedule(TimerJobInstance timerJobInstance)
void
readExternal(java.io.ObjectInput in)
void
removeJob(org.drools.base.time.JobHandle jobHandle)
Remove the job identified by the given job handle from the scheduled queuevoid
reset()
Reset this serviceorg.drools.base.time.JobHandle
scheduleJob(Job job, JobContext ctx, org.drools.base.time.Trigger trigger)
Schedule a job for later executionvoid
setStartupTime(long i)
void
setTimerJobFactoryManager(TimerJobFactoryManager timerJobFactoryManager)
void
shutdown()
Shuts the service downvoid
writeExternal(java.io.ObjectOutput out)
-
-
-
Field Detail
-
timer
protected java.util.concurrent.atomic.AtomicLong timer
-
queue
protected java.util.PriorityQueue<TimerJobInstance> queue
-
idCounter
protected java.util.concurrent.atomic.AtomicLong idCounter
-
-
Method Detail
-
readExternal
public void readExternal(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundException
- Specified by:
readExternal
in interfacejava.io.Externalizable
- Throws:
java.io.IOException
java.lang.ClassNotFoundException
-
writeExternal
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException
- Specified by:
writeExternal
in interfacejava.io.Externalizable
- Throws:
java.io.IOException
-
setTimerJobFactoryManager
public void setTimerJobFactoryManager(TimerJobFactoryManager timerJobFactoryManager)
- Specified by:
setTimerJobFactoryManager
in interfaceTimerService
-
getTimerJobFactoryManager
public TimerJobFactoryManager getTimerJobFactoryManager()
- Specified by:
getTimerJobFactoryManager
in interfaceTimerService
-
getCurrentTime
public long getCurrentTime()
Description copied from interface:TimerService
Returns the current time from the scheduler clock- Specified by:
getCurrentTime
in interfaceorg.kie.api.time.SessionClock
- Specified by:
getCurrentTime
in interfaceTimerService
- Returns:
- the current timestamp
-
scheduleJob
public org.drools.base.time.JobHandle scheduleJob(Job job, JobContext ctx, org.drools.base.time.Trigger trigger)
Description copied from interface:SchedulerService
Schedule a job for later execution- Specified by:
scheduleJob
in interfaceSchedulerService
- Returns:
-
internalSchedule
public void internalSchedule(TimerJobInstance timerJobInstance)
- Specified by:
internalSchedule
in interfaceInternalSchedulerService
-
removeJob
public void removeJob(org.drools.base.time.JobHandle jobHandle)
Description copied from interface:SchedulerService
Remove the job identified by the given job handle from the scheduled queue- Specified by:
removeJob
in interfaceSchedulerService
- Parameters:
jobHandle
- the job identity handle
-
advanceTime
public long advanceTime(long amount, java.util.concurrent.TimeUnit unit)
- Specified by:
advanceTime
in interfaceorg.kie.api.time.SessionPseudoClock
-
setStartupTime
public void setStartupTime(long i)
-
reset
public void reset()
Description copied from interface:TimerService
Reset this service- Specified by:
reset
in interfaceTimerService
-
shutdown
public void shutdown()
Description copied from interface:TimerService
Shuts the service down- Specified by:
shutdown
in interfaceTimerService
-
getTimeToNextJob
public long getTimeToNextJob()
Description copied from interface:TimerService
Returns the number of time units (usually ms) to the next scheduled job- Specified by:
getTimeToNextJob
in interfaceTimerService
- Returns:
- the number of time units until the next scheduled job or -1 if there is no job scheduled
-
getTimerJobInstances
public java.util.Collection<TimerJobInstance> getTimerJobInstances(long id)
Description copied from interface:TimerService
This method may return null for some TimerService implementations that do not want the overhead of maintain this.- Specified by:
getTimerJobInstances
in interfaceTimerService
- Returns:
-
-