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.ExecutorService
executor
static java.lang.String
invocationType
protected java.lang.Throwable
lastException
protected long
lastRun
protected boolean
wasError
-
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.V
call()
void
doJob()
Here you do the jobV
doJobWithResult()
Here you do the job and return a resultvoid
every(int seconds)
Run this job every n secondsvoid
every(java.lang.String delay)
Run this job every n secondsvoid
execute()
Override this methodInvoker.InvocationContext
getInvocationContext()
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)void
onException(java.lang.Throwable e)
Things to do if the Invocation code thrown an exceptionvoid
run()
It's time to execute.java.lang.String
toString()
-
-
-
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:
getInvocationContext
in classInvoker.Invocation
-
doJob
public void doJob() throws java.lang.Exception
Here 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.Exception
Description copied from class:Invoker.Invocation
Override this method- Specified by:
execute
in 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.Invocation
Things to do if the Invocation code thrown an exception- Overrides:
onException
in classInvoker.Invocation
- Parameters:
e
- The exception
-
run
public void run()
Description copied from class:Invoker.Invocation
It's time to execute.- Specified by:
run
in interfacejava.lang.Runnable
- Overrides:
run
in classInvoker.Invocation
-
_finally
public void _finally()
Description copied from class:Invoker.Invocation
Things to do in all cases after the invocation.- Overrides:
_finally
in classInvoker.Invocation
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-