Class LongOperation
- java.lang.Object
-
- com.hybris.cockpitng.engine.operations.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.
-
-
Constructor Summary
Constructors Constructor Description LongOperation(CockpitThreadContextCreator cockpitThreadContextCreator)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected booleanactivate()activate the thread (and cached desktop) for UI updates calldeactivate()once done updating the UIvoidcancel()set the cancelled flag and try to interrupt the threadprotected voidcheckCancelled()Checks if the task thread has been interrupted.protected voiddeactivate()deactivate the current active (see:activate()) thread/desktop after updates are doneprotected abstract voidexecute()asynchronous callback for your long operation codebooleanisCancelled()check the cancelled flagprotected voidonCancel()optional callback method when the task has been cancelled or was interrupted otherwiseprotected voidonCleanup()Optional callback method when the task has completed (always called)protected voidonException(java.lang.Throwable exception)optional callback method when the task has completed with an uncaught Exceptionprotected voidonFinish()Callback method which is executed in Ui thread after long operation finishes.voidrun()voidstart()launch the long operation
-
-
-
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.InterruptedExceptionasynchronous 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:
cancelin interfaceCancellable
-
isCancelled
public final boolean isCancelled()
check the cancelled flag- Returns:
- true if operation has been cancelled.
-
activate
protected final boolean activate() throws java.lang.InterruptedExceptionactivate the thread (and cached desktop) for UI updates calldeactivate()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.InterruptedExceptionChecks 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:
runin interfacejava.lang.Runnable
-
-