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.Object
The 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 someRequestProcessor
with only one task running simultaneously.- Author:
- Petr Hamernik
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
BackgroundRunner.BackgroundTask
Implementation 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 Task
createTask()
protected void
failTask(java.lang.Exception exc)
Finishes the task with the failure report passed as a parameter.protected java.lang.Object
getCreateLock()
protected int
getDelay()
protected java.util.concurrent.ScheduledExecutorService
getExecutorService()
WhichScheduledExecutorService
to use for running tasks.Task
getTask()
void
interrupt()
boolean
phase1Cancelled(CancelException exc)
boolean
phase1Exception(java.lang.Exception exc)
All subclasses must override this method and provide more user-friendly error notification.void
phase1Finally()
protected void
phase1FinallyInternal()
abstract void
phase1InRequestProcessor()
This method code is executed in request processor.void
phase2InAWT()
This method code is executed in AWT thread after phase1 finishes.protected void
processTheTask()
void
restart()
Task
start()
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()
WhichScheduledExecutorService
to use for running tasks. It's possible to return e.g.ScheduledExecutorService
running 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()
-
-