Package play.jobs

Class 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 Detail

      • executor

        protected java.util.concurrent.ExecutorService executor
      • lastRun

        protected long lastRun
      • wasError

        protected boolean wasError
      • lastException

        protected java.lang.Throwable lastException
    • Constructor Detail

      • Job

        public Job()
    • Method Detail

      • 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 class Invoker.Invocation
        Throws:
        java.lang.Exception - Thrown if Invocation encounters any problems
      • now

        public F.Promise<V> now()
        Start this job now (well ASAP)
        Returns:
        the job completion
      • 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 class Invoker.Invocation
        Parameters:
        e - The exception
      • run

        public void run()
        Description copied from class: Invoker.Invocation
        It's time to execute.
        Specified by:
        run in interface java.lang.Runnable
        Overrides:
        run in class Invoker.Invocation
      • call

        public V call()
        Specified by:
        call in interface java.util.concurrent.Callable<V>
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object