Class CockpitNGBackgroundOperation

  • All Implemented Interfaces:
    Cancellable, java.lang.Runnable

    public class CockpitNGBackgroundOperation
    extends java.lang.Object
    implements java.lang.Runnable, Cancellable
    Backoffice background operation that is capable of performing long running tasks in background allowing the UI to remain responsive.
    After long running task is completed an operation to update
    the UI is scheduled via Executions.schedule(Desktop, EventListener, Event) method.

    The contract for background task is to execute normally and return the result or throw RuntimeException in case of error.

    Background task should not interact with ZK UI neither via Executions.schedule(Desktop, EventListener, Event) nor via Executions.activate(Desktop)
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void cancel()
      Cancels the operation.
      void run()  
      protected void runInternal​(org.zkoss.zk.ui.Desktop desktop)  
      protected void scheduleForUI​(java.lang.Object result, java.util.function.Consumer consumer)  
      • Methods inherited from class java.lang.Object

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

      • CockpitNGBackgroundOperation

        public CockpitNGBackgroundOperation​(org.zkoss.zk.ui.Desktop desktop,
                                            RequestOperationContextHolder.ContextRequest contextRequest,
                                            java.util.function.Supplier backgroundTask,
                                            java.util.function.Consumer<java.lang.Object> onSuccess,
                                            java.util.function.Consumer<java.lang.Exception> onError)
        Creates new instance of CockpitNGBackgroundOperation
        Parameters:
        contextRequest - context of currently running server request
        backgroundTask - long running task to be executed
        onSuccess - callback to be executed after background tasks finishes successfully.
        This callback will be scheduled for the UI thread via Executions.schedule(Desktop, EventListener, Event)
        onError - callback to be executed on background task error.
        This callback will be scheduled for the UI thread via Executions.schedule(Desktop, EventListener, Event)
    • Method Detail

      • run

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

        public void cancel()
        Description copied from interface: Cancellable
        Cancels the operation.
        Specified by:
        cancel in interface Cancellable
      • runInternal

        protected void runInternal​(org.zkoss.zk.ui.Desktop desktop)
      • scheduleForUI

        protected void scheduleForUI​(java.lang.Object result,
                                     java.util.function.Consumer consumer)