Class LongOperation

  • All Implemented Interfaces:
    Cancellable, java.lang.Runnable
    Direct Known Subclasses:
    ResultLongOperation

    public abstract class LongOperation
    extends java.lang.Object
    implements java.lang.Runnable, Cancellable
    Executes operation in background thread.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected boolean activate()
      activate the thread (and cached desktop) for UI updates call deactivate() once done updating the UI
      void cancel()
      set the cancelled flag and try to interrupt the thread
      protected void checkCancelled()
      Checks if the task thread has been interrupted.
      protected void deactivate()
      deactivate the current active (see: activate()) thread/desktop after updates are done
      protected abstract void execute()
      asynchronous callback for your long operation code
      boolean isCancelled()
      check the cancelled flag
      protected void onCancel()
      optional callback method when the task has been cancelled or was interrupted otherwise
      protected void onCleanup()
      Optional callback method when the task has completed (always called)
      protected void onException​(java.lang.Throwable exception)
      optional callback method when the task has completed with an uncaught Exception
      protected void onFinish()
      Callback method which is executed in Ui thread after long operation finishes.
      void run()  
      void start()
      launch the long operation
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • LongOperation

        public LongOperation​(CockpitThreadContextCreator cockpitThreadContextCreator)
        Parameters:
        cockpitThreadContextCreator - util used to copy ctx from ui thread to background thread.
    • Method Detail

      • execute

        protected abstract void execute()
                                 throws java.lang.InterruptedException
        asynchronous callback for your long operation code
        Throws:
        java.lang.InterruptedException - if operation has been Interrupted
      • onFinish

        protected void onFinish()
        Callback method which is executed in Ui thread after long operation finishes.
      • onCancel

        protected void onCancel()
        optional callback method when the task has been cancelled or was interrupted otherwise
      • onException

        protected void onException​(java.lang.Throwable exception)
        optional callback method when the task has completed with an uncaught Exception
        Parameters:
        exception - thrown exception
      • onCleanup

        protected void onCleanup()
        Optional callback method when the task has completed (always called)
      • cancel

        public final void cancel()
        set the cancelled flag and try to interrupt the thread
        Specified by:
        cancel in interface Cancellable
      • isCancelled

        public final boolean isCancelled()
        check the cancelled flag
        Returns:
        true if operation has been cancelled.
      • activate

        protected final boolean activate()
                                  throws java.lang.InterruptedException
        activate the thread (and cached desktop) for UI updates call deactivate() once done updating the UI
        Returns:
        true if desktop is activated.
        Throws:
        java.lang.InterruptedException - if it is interrupted by other thread
      • deactivate

        protected final void deactivate()
        deactivate the current active (see: activate()) thread/desktop after updates are done
      • checkCancelled

        protected final void checkCancelled()
                                     throws java.lang.InterruptedException
        Checks if the task thread has been interrupted. Use this to check whether or not to exit a busy operation in case.
        Throws:
        java.lang.InterruptedException - when the current task has been cancelled/interrupted
      • start

        public final void start()
        launch the long operation
      • run

        public final void run()
        Specified by:
        run in interface java.lang.Runnable