Package com.im.commons.progress
Class UIBackgroundRunnerRW
- java.lang.Object
-
- com.im.commons.progress.BackgroundRunner
-
- com.im.commons.progress.UIBackgroundRunnerRW
-
public abstract class UIBackgroundRunnerRW extends BackgroundRunner
An extension ofUIBackgroundRunnerRO
which is able to lock the given DFLockable and use the lock in the background task. Lock is automatically released when action is finished.When the
DFLockable
is already locked, the background task will try to lock repeatedly, waitingLOCK_RETRY_DELAY
milliseconds between retries. The implementation will attempt to lock the DFLockable at mostMAX_LOCK_RETRIES
times.When the attempts to lock are exhausted, or the
DFLockable.isLockedForever()
indicates that the DFLockable can never be locked, the task will fail withAlreadyLockedException
. Thephase1Exception(java.lang.Exception)
andBackgroundRunner.phase1Finally()
will be called for proper error reporting and state cleanup.- Author:
- Petr Hamernik
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.im.commons.progress.BackgroundRunner
BackgroundRunner.BackgroundTask
-
-
Constructor Summary
Constructors Constructor Description UIBackgroundRunnerRW(DFLockable lockable, java.lang.String taskName, boolean cancellable)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Task
createTask()
DFEnvironmentRW
getEnvironment()
protected java.util.concurrent.ScheduledExecutorService
getExecutorService()
We need single thread executor service per lockable.boolean
phase1Cancelled(CancelException exc)
boolean
phase1Exception(java.lang.Exception exc)
All subclasses must override this method and provide more user-friendly error notification.protected void
phase1FinallyInternal()
-
Methods inherited from class com.im.commons.progress.BackgroundRunner
failTask, getCreateLock, getDelay, getTask, interrupt, phase1Finally, phase1InRequestProcessor, phase2InAWT, processTheTask, restart, start
-
-
-
-
Constructor Detail
-
UIBackgroundRunnerRW
public UIBackgroundRunnerRW(DFLockable lockable, java.lang.String taskName, boolean cancellable)
-
-
Method Detail
-
createTask
protected Task createTask()
- Overrides:
createTask
in classBackgroundRunner
- Returns:
- The locking object that guards creation of a new task. Use when you need to query task or other things computed during start()
-
getEnvironment
public DFEnvironmentRW getEnvironment()
-
phase1Cancelled
public boolean phase1Cancelled(CancelException exc)
- Overrides:
phase1Cancelled
in classBackgroundRunner
- Returns:
- when true this runner continues with AWT (second) phase. If false, the AWT phase is skipped.
-
phase1FinallyInternal
protected final void phase1FinallyInternal()
- Overrides:
phase1FinallyInternal
in classBackgroundRunner
-
getExecutorService
protected java.util.concurrent.ScheduledExecutorService getExecutorService()
We need single thread executor service per lockable.- Overrides:
getExecutorService
in classBackgroundRunner
- Returns:
- returns ExecutorService for use in this bg runner
-
phase1Exception
public boolean phase1Exception(java.lang.Exception exc)
Description copied from class:BackgroundRunner
All subclasses must override this method and provide more user-friendly error notification.- Overrides:
phase1Exception
in classBackgroundRunner
- Returns:
- when true this runner continues with AWT (second) phase. If false, the AWT phase is skipped.
-
-