@Component(value="cuba_Scheduling") public class Scheduling extends java.lang.Object implements SchedulingAPI
ScheduledTask
s in distributed environment.Modifier and Type | Field and Description |
---|---|
protected Authentication |
authentication |
protected ClusterManagerAPI |
clusterManager |
protected Configuration |
configuration |
protected Coordinator |
coordinator |
protected java.util.Map<ScheduledTask,java.lang.Long> |
lastFinishCache |
protected java.util.Map<ScheduledTask,java.lang.Long> |
lastStartCache |
protected Runner |
runner |
protected java.util.concurrent.ConcurrentMap<ScheduledTask,java.lang.Long> |
runningTasks |
protected long |
schedulingStartTime |
protected ServerInfoAPI |
serverInfo |
protected ServerInfoService |
serverInfoService |
protected TimeSource |
timeSource |
protected UserSessionsAPI |
userSessions |
NAME
Constructor and Description |
---|
Scheduling() |
Modifier and Type | Method and Description |
---|---|
protected long |
calculateNextCronDate(ScheduledTask task,
long date,
long currentDate,
long frame) |
protected long |
calculateNextDelayDate(ScheduledTask task,
long lastStart,
long lastFinish,
long currentDate,
long frame,
long period) |
protected long |
calculateNextPeriodDate(ScheduledTask task,
long date,
long currentDate,
long frame,
long period) |
protected boolean |
checkFirst(ScheduledTask task,
java.lang.Integer serverPriority,
long now) |
java.util.List<ScheduledTask> |
getActiveTasks() |
protected java.util.TimeZone |
getCurrentTimeZone() |
protected long |
getSchedulingInterval() |
protected java.lang.Integer |
getServerPriority(ScheduledTask task,
java.lang.String serverId) |
protected UserSession |
getUserSession(ScheduledTask task) |
boolean |
isActive()
Whether the scheduling is currently active.
|
protected boolean |
isRunning(ScheduledTask task) |
protected boolean |
lastServerWasNotMe(ScheduledTask task,
java.lang.String me) |
protected boolean |
needToStartInTimeFrame(long now,
long frame,
long lastStart,
long currentStart) |
void |
processScheduledTasks()
Process all active scheduled tasks once.
|
void |
processScheduledTasks(boolean onlyIfActive) |
protected void |
processTask(ScheduledTask task) |
void |
runOnce(ScheduledTask task)
Runs a task right now and only once.
|
protected void |
runSingletonTask(ScheduledTask task,
long now,
java.lang.String server) |
protected void |
runTask(ScheduledTask task,
long time) |
void |
setActive(boolean value)
Activate/deactivate scheduling.
|
void |
setFinished(ScheduledTask task)
Mark the scheduled task as finished in the internal list.
|
boolean |
setRunning(ScheduledTask task,
boolean running)
Mark the scheduled task as running/not running in the internal list.
|
@Inject protected Configuration configuration
@Inject protected ServerInfoAPI serverInfo
@Inject protected ClusterManagerAPI clusterManager
@Inject protected TimeSource timeSource
@Inject protected Authentication authentication
@Inject protected Coordinator coordinator
@Inject protected Runner runner
@Inject protected UserSessionsAPI userSessions
@Inject protected ServerInfoService serverInfoService
protected java.util.concurrent.ConcurrentMap<ScheduledTask,java.lang.Long> runningTasks
protected java.util.Map<ScheduledTask,java.lang.Long> lastStartCache
protected java.util.Map<ScheduledTask,java.lang.Long> lastFinishCache
protected volatile long schedulingStartTime
public void processScheduledTasks()
SchedulingAPI
<task:scheduled ref="cuba_Scheduling" method="processScheduledTasks" fixed-rate="1000"/>
This methods returns immediately if scheduling is not active.
processScheduledTasks
in interface SchedulingAPI
public void processScheduledTasks(boolean onlyIfActive)
processScheduledTasks
in interface SchedulingAPI
public boolean setRunning(ScheduledTask task, boolean running)
SchedulingAPI
setRunning
in interface SchedulingAPI
task
- task instancerunning
- true to mark as running, false to mark as not runningpublic void setFinished(ScheduledTask task)
SchedulingAPI
setFinished
in interface SchedulingAPI
task
- task instancepublic boolean isActive()
SchedulingAPI
ServerConfig.getSchedulingActive()
configuration parameter.isActive
in interface SchedulingAPI
public void setActive(boolean value)
SchedulingAPI
ServerConfig.getSchedulingActive()
configuration parameter.setActive
in interface SchedulingAPI
value
- true to activate schedulingpublic java.util.List<ScheduledTask> getActiveTasks()
getActiveTasks
in interface SchedulingAPI
protected long getSchedulingInterval()
protected void processTask(ScheduledTask task)
protected boolean needToStartInTimeFrame(long now, long frame, long lastStart, long currentStart)
protected long calculateNextCronDate(ScheduledTask task, long date, long currentDate, long frame)
protected long calculateNextPeriodDate(ScheduledTask task, long date, long currentDate, long frame, long period)
protected long calculateNextDelayDate(ScheduledTask task, long lastStart, long lastFinish, long currentDate, long frame, long period)
protected java.util.TimeZone getCurrentTimeZone()
protected boolean lastServerWasNotMe(ScheduledTask task, java.lang.String me)
protected void runSingletonTask(ScheduledTask task, long now, java.lang.String server) throws LoginException
LoginException
protected void runTask(ScheduledTask task, long time) throws LoginException
LoginException
protected boolean checkFirst(ScheduledTask task, java.lang.Integer serverPriority, long now)
protected java.lang.Integer getServerPriority(ScheduledTask task, java.lang.String serverId)
@Nullable protected UserSession getUserSession(ScheduledTask task) throws LoginException
LoginException
protected boolean isRunning(ScheduledTask task)
public void runOnce(ScheduledTask task)
SchedulingAPI
runOnce
in interface SchedulingAPI
task
- task to execute