Package com.im.commons.progress
Class BackgroundRunner
- java.lang.Object
-
- com.im.commons.progress.BackgroundRunner
-
- Direct Known Subclasses:
UIBackgroundRunnerRO,UIBackgroundRunnerRW
public abstract class BackgroundRunner extends java.lang.ObjectThe 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 someRequestProcessorwith only one task running simultaneously.- Author:
- Petr Hamernik
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classBackgroundRunner.BackgroundTaskImplementation of Task backed by ExecutorService provided by BackgroundTask or its descendant classes.
-
Constructor Summary
Constructors Constructor Description BackgroundRunner()BackgroundRunner(int delay)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected TaskcreateTask()protected voidfailTask(java.lang.Exception exc)Finishes the task with the failure report passed as a parameter.protected java.lang.ObjectgetCreateLock()protected intgetDelay()protected java.util.concurrent.ScheduledExecutorServicegetExecutorService()WhichScheduledExecutorServiceto use for running tasks.TaskgetTask()voidinterrupt()booleanphase1Cancelled(CancelException exc)booleanphase1Exception(java.lang.Exception exc)All subclasses must override this method and provide more user-friendly error notification.voidphase1Finally()protected voidphase1FinallyInternal()abstract voidphase1InRequestProcessor()This method code is executed in request processor.voidphase2InAWT()This method code is executed in AWT thread after phase1 finishes.protected voidprocessTheTask()voidrestart()Taskstart()Start runner.
-
-
-
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()
WhichScheduledExecutorServiceto use for running tasks. It's possible to return e.g.ScheduledExecutorServicerunning 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()
-
-