Package tools.dynamia.zk.util
Class LongOperation
- java.lang.Object
-
- tools.dynamia.zk.util.LongOperation
-
- All Implemented Interfaces:
Runnable
- Direct Known Subclasses:
ResultLongOperation
public class LongOperation extends Object implements Runnable
-
-
Constructor Summary
Constructors Constructor Description LongOperation()LongOperation(org.springframework.core.task.TaskExecutor taskExecutor)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidactivate()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.static LongOperationcreate()static LongOperationcreate(org.springframework.core.task.TaskExecutor taskExecutor)protected voiddeactivate()deactivate the current active (see:activate()) thread/desktop after updates are doneprotected voidexecute()LongOperationexecute(tools.dynamia.commons.Callback executeCallback)asynchronous callback for your long operation codeprotected voidfinish()booleanisCancelled()check the cancelled flagLongOperationonCancel(tools.dynamia.commons.Callback onCancelCallback)optional callback method when the task has been cancelled or was interrupted otherwiseLongOperationonCleanup(tools.dynamia.commons.Callback onCleanupCallback)optional callback method when the task has completed (always called)LongOperationonException(Consumer<Exception> onExceptionConsumer)optional callback method when the task has completed with an uncaught ExcepionLongOperationonFinish(tools.dynamia.commons.Callback onFinishCallback)optional callback method when the task has completed successfullyLongOperationonStart(tools.dynamia.commons.Callback onStart)voidrun()protected voidrunCallback(tools.dynamia.commons.Callback callback)LongOperationstart()launch the long operationvoidupdateUI(tools.dynamia.commons.Callback callback)
-
-
-
Method Detail
-
onStart
public LongOperation onStart(tools.dynamia.commons.Callback onStart)
-
execute
public LongOperation execute(tools.dynamia.commons.Callback executeCallback)
asynchronous callback for your long operation code
-
onFinish
public LongOperation onFinish(tools.dynamia.commons.Callback onFinishCallback)
optional callback method when the task has completed successfully
-
onCancel
public LongOperation onCancel(tools.dynamia.commons.Callback onCancelCallback)
optional callback method when the task has been cancelled or was interrupted otherwise
-
onException
public LongOperation onException(Consumer<Exception> onExceptionConsumer)
optional callback method when the task has completed with an uncaught Excepion- Parameters:
onExceptionConsumer-
-
onCleanup
public LongOperation onCleanup(tools.dynamia.commons.Callback onCleanupCallback)
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
-
isCancelled
public final boolean isCancelled()
check the cancelled flag- Returns:
-
activate
protected final void activate() throws InterruptedExceptionactivate the thread (and cached desktop) for UI updates calldeactivate()once done updating the UI- Throws:
InterruptedException
-
deactivate
protected final void deactivate()
deactivate the current active (see:activate()) thread/desktop after updates are done
-
checkCancelled
protected final void checkCancelled() throws InterruptedExceptionChecks if the task thread has been interrupted. Use this to check whether or not to exit a busy operation in case.- Throws:
InterruptedException- when the current task has been cancelled/interrupted
-
start
public final LongOperation start()
launch the long operation
-
finish
protected void finish()
-
execute
protected void execute()
-
runCallback
protected void runCallback(tools.dynamia.commons.Callback callback)
-
updateUI
public void updateUI(tools.dynamia.commons.Callback callback)
-
create
public static LongOperation create()
-
create
public static LongOperation create(org.springframework.core.task.TaskExecutor taskExecutor)
-
-