org.apache.felix.deploymentadmin.spi
Class Command

java.lang.Object
  extended by org.apache.felix.deploymentadmin.spi.Command
Direct Known Subclasses:
CommitResourceCommand, DropBundleCommand, DropResourceCommand, GetStorageAreaCommand, ProcessResourceCommand, SnapshotCommand, StartBundleCommand, StartCustomizerCommand, StopBundleCommand, UpdateCommand

public abstract class Command
extends Object

Commands describe a group of tasks to be executed within the execution a deployment session. A command that has already executed can be rolled back and a command that is currently in progress can be signaled to stop it's activities by canceling it.


Constructor Summary
Command()
           
 
Method Summary
protected  void addCommit(Runnable runnable)
          Adds an action to be executed in case of a commit
protected  void addRollback(Runnable runnable)
          Adds an action to be executed in case of a roll back.
 void cancel()
          Sets the command to being cancelled, this does not have an immediate effect.
protected  void commit()
          Commits all changes the command may have defined when it was executed by calling the execute() method.
abstract  void execute(DeploymentSessionImpl session)
          Executes the command, the specified DeploymentSession can be used to obtain various information about the deployment session which the command is part of.
protected  boolean isCancelled()
          Determines if the command was canceled.
 void rollback()
          Rolls back all actions that were added through the addRollback(Runnable r) method (in reverse adding order).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Command

public Command()
Method Detail

execute

public abstract void execute(DeploymentSessionImpl session)
                      throws DeploymentException
Executes the command, the specified DeploymentSession can be used to obtain various information about the deployment session which the command is part of.

Parameters:
session - The deployment session this command is part of.
Throws:
DeploymentException - Thrown if the command could not successfully execute.

rollback

public void rollback()
Rolls back all actions that were added through the addRollback(Runnable r) method (in reverse adding order). It is not guaranteed that the state of everything related to the command will be as if the command was never executed, a best effort should be made though.


commit

protected void commit()
Commits all changes the command may have defined when it was executed by calling the execute() method.


isCancelled

protected boolean isCancelled()
Determines if the command was canceled. This method should be used regularly by implementing classes to determine if their command was canceled, if so they should return as soon as possible from their operations.

Returns:
true if the command was canceled, false otherwise.

addRollback

protected void addRollback(Runnable runnable)
Adds an action to be executed in case of a roll back.

Parameters:
runnable - The runnable to be executed in case of a roll back.

addCommit

protected void addCommit(Runnable runnable)
Adds an action to be executed in case of a commit

Parameters:
runnable - The runnable to be executes in case of a commit.

cancel

public void cancel()
Sets the command to being cancelled, this does not have an immediate effect. Commands that are executing should check regularly if they were cancelled and if so they should make an effort to stop their operations as soon as possible followed by throwing an DeploymentException.CODE_CANCELLED exception.



Copyright © 2013 The Apache Software Foundation. All Rights Reserved.