public class Action extends java.lang.Object implements AtomicAction
| Constructor and Description |
|---|
Action() |
Action(ActionBlock perform,
ActionBlock backout,
ActionBlock cleanup) |
| Modifier and Type | Method and Description |
|---|---|
void |
add(ActionBlock perform,
ActionBlock backoutOrCleanup)
Adds an action as a step of this one.
|
void |
add(ActionBlock perform,
ActionBlock backout,
ActionBlock cleanup)
Adds an action as a step of this one.
|
void |
add(AtomicAction action)
Adds an action as a step of thid one.
|
void |
backout()
Backs out the completed action.
|
void |
cleanup()
Cleans up after all actions have completed.
|
static Action |
deleteFile(java.lang.String path,
java.lang.String tempDir)
Deletes the file/directory at the given path, if it exists.
|
int |
getFailedStep() |
java.lang.Exception |
getLastError() |
static Action |
moveAndReplaceFile(java.lang.String srcPath,
java.lang.String destPath,
java.lang.String tempDir)
Moves the file/directory to a new location, replacing anything that already exists there.
|
static Action |
moveFileToEmptyPath(java.lang.String srcPath,
java.lang.String destPath)
Moves the file/directory to a new location, which must not already exist.
|
void |
perform()
Performs the action.
|
void |
run()
Performs all the actions in order.
|
public Action()
public Action(ActionBlock perform, ActionBlock backout, ActionBlock cleanup)
public java.lang.Exception getLastError()
public int getFailedStep()
public void add(AtomicAction action)
action - public void add(ActionBlock perform, ActionBlock backout, ActionBlock cleanup)
perform - A block that tries to perform the action, or returns an error if it fails.
(If the block fails, it should clean up; the backOut will _not_ be called!)backout - A block that undoes the effect of the action; it will be called if a _later_
action fails, so that the system can be returned to the initial state.cleanup - A block that performs any necessary cleanup after all actions have been
performed (e.g. deleting a temporary file.)public void add(ActionBlock perform, ActionBlock backoutOrCleanup)
perform - A block that tries to perform the action, or returns an error if it fails.
(If the block fails, it should clean up; the backOut will _not_ be called!)backoutOrCleanup - A block that can be both backout and cleanup block.A backout block.public void run()
throws ActionException
ActionExceptionpublic void perform()
throws ActionException
AtomicActionperform in interface AtomicActionActionExceptionpublic void backout()
throws ActionException
AtomicActionbackout in interface AtomicActionActionExceptionpublic void cleanup()
throws ActionException
AtomicActioncleanup in interface AtomicActionActionExceptionpublic static Action deleteFile(java.lang.String path, java.lang.String tempDir)
path - Path to the file or directory to be deletedtempDir - Path to a tem directory used for backing out the deleted filepublic static Action moveFileToEmptyPath(java.lang.String srcPath, java.lang.String destPath)
srcPath - Source pathdestPath - Destination path which must not existpublic static Action moveAndReplaceFile(java.lang.String srcPath, java.lang.String destPath, java.lang.String tempDir)
srcPath - Source pathdestPath - Destination path to be replacedtempDir - Path to a temp directory used for backing out file deletion