Class BackgroundRunner

  • Direct Known Subclasses:
    UIBackgroundRunnerRO, UIBackgroundRunnerRW

    public abstract class BackgroundRunner
    extends java.lang.Object
    The utility class which supports running of some task in request processor and after finishing transfer the code flow to AWT event dispatching thread.

    It can be used also for delayed task running, but in this case override getExecutorService() method to return some RequestProcessor with only one task running simultaneously.

    Author:
    Petr Hamernik
    • Constructor Detail

      • BackgroundRunner

        public BackgroundRunner()
      • BackgroundRunner

        public BackgroundRunner​(int delay)
    • Method Detail

      • start

        public Task start()
        Start runner.
        Returns:
        The background task handle.
      • getCreateLock

        protected final java.lang.Object getCreateLock()
        Returns:
        The locking object that guards creation of a new task. Use when you need to query task or other things computed during start()
      • createTask

        protected Task createTask()
        Returns:
        The locking object that guards creation of a new task. Use when you need to query task or other things computed during start()
      • failTask

        protected final void failTask​(java.lang.Exception exc)
        Finishes the task with the failure report passed as a parameter. The call sequence should be the same as if the task failed in its run() method. Note that during this call, the DFEnvironment may use a fake lock in the case that locking the DIF object has failed.
        Parameters:
        exc - The failure
      • processTheTask

        protected final void processTheTask()
      • interrupt

        public void interrupt()
      • getDelay

        protected int getDelay()
      • getExecutorService

        protected java.util.concurrent.ScheduledExecutorService getExecutorService()
        Which ScheduledExecutorService to use for running tasks. It's possible to return e.g. ScheduledExecutorService running only one task at once.
        Returns:
        returns ExecutorService for use in this bg runner
      • restart

        public void restart()
      • getTask

        public Task getTask()
      • phase1InRequestProcessor

        public abstract void phase1InRequestProcessor()
        This method code is executed in request processor.
      • phase2InAWT

        public void phase2InAWT()
        This method code is executed in AWT thread after phase1 finishes.
      • phase1Cancelled

        public boolean phase1Cancelled​(CancelException exc)
        Returns:
        when true this runner continues with AWT (second) phase. If false, the AWT phase is skipped.
      • phase1Exception

        public boolean phase1Exception​(java.lang.Exception exc)
        All subclasses must override this method and provide more user-friendly error notification.
        Returns:
        when true this runner continues with AWT (second) phase. If false, the AWT phase is skipped.
      • phase1FinallyInternal

        protected void phase1FinallyInternal()
      • phase1Finally

        public void phase1Finally()