Package play.jobs
Class Job<V>
- java.lang.Object
-
- play.Invoker.Invocation
-
- play.jobs.Job<V>
-
- Type Parameters:
V- The job result type (if any)
- All Implemented Interfaces:
java.lang.Runnable,java.util.concurrent.Callable<V>
public class Job<V> extends Invoker.Invocation implements java.util.concurrent.Callable<V>
A job is an asynchronously executed unit of work
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.concurrent.ExecutorServiceexecutorstatic java.lang.StringinvocationTypeprotected java.lang.ThrowablelastExceptionprotected longlastRunprotected booleanwasError
-
Constructor Summary
Constructors Constructor Description Job()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void_finally()Things to do in all cases after the invocation.F.Promise<V>afterRequest()If is called in a 'HttpRequest' invocation context, waits until request is served and schedules job then.Vcall()voiddoJob()Here you do the jobVdoJobWithResult()Here you do the job and return a resultvoidevery(int seconds)Run this job every n secondsvoidevery(java.lang.String delay)Run this job every n secondsvoidexecute()Override this methodInvoker.InvocationContextgetInvocationContext()F.Promise<V>in(int seconds)Start this job in several secondsF.Promise<V>in(java.lang.String delay)Start this job in several secondsF.Promise<V>now()Start this job now (well ASAP)voidonException(java.lang.Throwable e)Things to do if the Invocation code thrown an exceptionvoidrun()It's time to execute.java.lang.StringtoString()
-
-
-
Field Detail
-
invocationType
public static final java.lang.String invocationType
- See Also:
- Constant Field Values
-
executor
protected java.util.concurrent.ExecutorService executor
-
lastRun
protected long lastRun
-
wasError
protected boolean wasError
-
lastException
protected java.lang.Throwable lastException
-
-
Method Detail
-
getInvocationContext
public Invoker.InvocationContext getInvocationContext()
- Specified by:
getInvocationContextin classInvoker.Invocation
-
doJob
public void doJob() throws java.lang.ExceptionHere you do the job- Throws:
java.lang.Exception- if problems occurred
-
doJobWithResult
public V doJobWithResult() throws java.lang.Exception
Here you do the job and return a result- Returns:
- The job result
- Throws:
java.lang.Exception- if problems occurred
-
execute
public void execute() throws java.lang.ExceptionDescription copied from class:Invoker.InvocationOverride this method- Specified by:
executein classInvoker.Invocation- Throws:
java.lang.Exception- Thrown if Invocation encounters any problems
-
afterRequest
public F.Promise<V> afterRequest()
If is called in a 'HttpRequest' invocation context, waits until request is served and schedules job then. Otherwise is the same as now(); If you want to schedule a job to run after some other job completes, wait till a promise redeems of just override first Job's call() to schedule the second one.- Returns:
- the job completion
-
in
public F.Promise<V> in(java.lang.String delay)
Start this job in several seconds- Parameters:
delay- time in seconds- Returns:
- the job completion
-
in
public F.Promise<V> in(int seconds)
Start this job in several seconds- Parameters:
seconds- time in seconds- Returns:
- the job completion
-
every
public void every(java.lang.String delay)
Run this job every n seconds- Parameters:
delay- time in seconds
-
every
public void every(int seconds)
Run this job every n seconds- Parameters:
seconds- time in seconds
-
onException
public void onException(java.lang.Throwable e)
Description copied from class:Invoker.InvocationThings to do if the Invocation code thrown an exception- Overrides:
onExceptionin classInvoker.Invocation- Parameters:
e- The exception
-
run
public void run()
Description copied from class:Invoker.InvocationIt's time to execute.- Specified by:
runin interfacejava.lang.Runnable- Overrides:
runin classInvoker.Invocation
-
_finally
public void _finally()
Description copied from class:Invoker.InvocationThings to do in all cases after the invocation.- Overrides:
_finallyin classInvoker.Invocation
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-