Class AbstractShutDownTask
- All Implemented Interfaces:
PropertyChangeListener
,Runnable
,Callable<Boolean>
,EventListener
,ShutDownTask
- Direct Known Subclasses:
CbusEventTableShutdownTask
,QuietShutDownTask
,SwingShutDownTask
,WarrantShutdownTask
public abstract class AbstractShutDownTask extends Object implements ShutDownTask
This implementation provides a "doRun" property with a protected getter and
setter to allow subclasses to set the "doRun" property to true inside
call()
so that the property can be checked inside ShutDownTask.run()
to
determine if anything should be done during shut down.
-
Constructor Summary
Constructors Constructor Description AbstractShutDownTask(String name)
Constructor specifies the name -
Method Summary
Modifier and Type Method Description Boolean
call()
Ask if shut down is allowed.boolean
execute()
Take the necessary action.String
getName()
Name to be provided to the user when information about this task is presented.boolean
isComplete()
AdviseShutDownManager
s that the task is complete.boolean
isDoRun()
Check if action should be taken inShutDownTask.run()
method.boolean
isParallel()
AdviseShutDownManager
s ifShutDownTask.execute()
may return before the task is complete.boolean
isShutdownAllowed()
Ask if shut down is allowed.void
propertyChange(PropertyChangeEvent evt)
Note that overriding implementations should call this implementation to set the doRun property correctly.void
setDoRun(boolean flag)
Set if action should be taken inShutDownTask.run()
method.
-
Constructor Details
-
AbstractShutDownTask
Constructor specifies the name- Parameters:
name
- Name to give this task
-
-
Method Details
-
isShutdownAllowed
Ask if shut down is allowed.The shut down manager must call this method first on all the tasks before starting to execute the method execute() on the tasks.
If this method returns false on any task, the shut down process must be aborted.
- Specified by:
isShutdownAllowed
in interfaceShutDownTask
- Returns:
- true if it is OK to shut down, false to abort shut down.
-
call
Ask if shut down is allowed.The shut down manager calls this method first on all the tasks before starting to execute the method
ShutDownTask.run()
on the tasks.If this method returns false on any task, the shut down process must be aborted. This implementation merely sets the "doRun" property to true, and should be overridden for any real checking. Note that overriding implementations should call
setDoRun(boolean)
correctly.- Specified by:
call
in interfaceCallable<Boolean>
- Specified by:
call
in interfaceShutDownTask
- Returns:
- true if it is OK to shut down, false to abort shut down.
-
execute
Take the necessary action.If the task is lengthy and can easily confirm that it should proceed (i.e., prompt the user to save, not save, or cancel shutting down), and spin itself off into a new thread, it should do so.
Note if a task is parallel, this method should return after any tests that might cause the shutdown to be aborted.
- Specified by:
execute
in interfaceShutDownTask
- Returns:
- true if the shutdown should continue, false to abort.
-
getName
Description copied from interface:ShutDownTask
Name to be provided to the user when information about this task is presented.- Specified by:
getName
in interfaceShutDownTask
- Returns:
- the name
-
isParallel
Description copied from interface:ShutDownTask
AdviseShutDownManager
s ifShutDownTask.execute()
may return before the task is complete.Note if a task is parallel,
ShutDownTask.execute()
should return after any tests that might cause the shutdown to be aborted.- Specified by:
isParallel
in interfaceShutDownTask
- Returns:
- true if the task is run within its own Thread
-
isComplete
Description copied from interface:ShutDownTask
AdviseShutDownManager
s that the task is complete.- Specified by:
isComplete
in interfaceShutDownTask
- Returns:
- true if the task is complete
-
propertyChange
Note that overriding implementations should call this implementation to set the doRun property correctly.- Specified by:
propertyChange
in interfacePropertyChangeListener
-
isDoRun
Check if action should be taken inShutDownTask.run()
method. This defaults to false, although the default implementation ofcall()
sets this to true.- Returns:
- true if action should be taken; false otherwise
-
setDoRun
Set if action should be taken inShutDownTask.run()
method. Overriding implementations ofcall()
must call this to setisDoRun()
to true.- Parameters:
flag
- true if action should be taken; false otherwise
-