|
Jive Forums API (5.5.20.2-oracle) Developer Javadocs | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.jivesoftware.util.CronTask
public class CronTask
A CronTask is a task which runs according to a schedule determined by a CronTimer
.
CronTasks are created and persisted by using an instance of a CronTaskManager
.
In a clustered environment tasks are run on all cluster members. For a task to run only once
across all cluster members the task must implement Invocable
and do something similar
to the following:
public class MyTask implements Invocable { private long myvariable; private boolean isMaster = false; public void init(InvocationService invocationService) { if (invocationService.getInfo().getOldestMember().getId() == invocationService.getCluster().getLocalMember().getId()) { isMaster = true; } } public void run() { // Only run this task on the master cluster member. if (CacheFactory.isClusteringEnabled() && !isMaster) { return; } // do something here } public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof MyTask)) { return false; } final MyTask myTask = (MyTask) o; if (myvariable != myTask.myvariable) { return false; } return true; } public int hashCode() { return (int) (myvariable ^ (myvariable >>> 32)); } }Tasks must implement
Serializable
and override Object.equals(java.lang.Object)
to work
properly in a clustered environment. Failure to do so will result in errors.
Any changes to the cronTimer used in this class should be followed by a call to
CronTaskManager.saveCronTask(CronTask)
so that the changes are persisted.
Constructor Summary | |
---|---|
protected |
CronTask(long id,
java.lang.Runnable task,
CronTimer cronTimer)
|
protected |
CronTask(java.lang.Runnable task,
CronTimer cronTimer)
|
Method Summary | |
---|---|
boolean |
equals(java.lang.Object o)
Both timer and task are used to compare equality. |
CronTimer |
getCronTimer()
Returns the CronTimer instance used to schedule this task. |
long |
getID()
Returns the unique id of the crontask. |
java.lang.Runnable |
getRunnable()
Returns the Runnable object which is run on the schedule defined by the CronTimer. |
int |
hashCode()
|
boolean |
isStopped()
Returns true is the CronTask is stopped, false otherwise. |
void |
run()
|
void |
setCronTimer(CronTimer cronTimer)
Sets the CronTimer to use to schedule this task. |
void |
setCronTimerNoCluster(CronTimer cronTimer)
* This method is only intended to be used internally to Jive by the CronClusterUpdateTask class. |
void |
start()
Start the CronTask running after it has been previously stopped. |
void |
stop()
Stop the CronTask from running. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
protected CronTask(java.lang.Runnable task, CronTimer cronTimer)
protected CronTask(long id, java.lang.Runnable task, CronTimer cronTimer)
Method Detail |
---|
public long getID()
public CronTimer getCronTimer()
CronTimer
instance used to schedule this task.
CronTimer
instance used to schedule this taskpublic void setCronTimer(CronTimer cronTimer)
cronTimer
- the CronTimer to use to schedule this taskpublic void setCronTimerNoCluster(CronTimer cronTimer)
CronClusterUpdateTask
class.
cronTimer
- the CronTimer to use to schedule this taskpublic java.lang.Runnable getRunnable()
public void run()
run
in interface java.lang.Runnable
public void start()
public void stop()
CronTaskManager.removeCronTask(CronTask)
to do that.
public boolean isStopped()
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
|
Jive Forums Project Page | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |