org.apache.felix.deploymentadmin.spi

## Class Command

- java.lang.Object
- - org.apache.felix.deploymentadmin.spi.Command

All Implemented Interfaces:
  org.osgi.framework.Constants

Direct Known Subclasses:
  CommitResourceCommand, DropAllBundlesCommand, DropAllResourcesCommand, DropBundleCommand, DropResourceCommand, GetStorageAreaCommand, ProcessResourceCommand, SnapshotCommand, StartBundleCommand, StartCustomizerCommand, StopBundleCommand, UpdateCommand

    public abstract class Command
    extends Object
    implements Constants

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.

### Field Summary

### Fields inherited from interface org.apache.felix.deploymentadmin.Constants

`BUNDLE_LOCATION_PREFIX, BUNDLE_SYMBOLICNAME, BUNDLE_VERSION, CODE_BAD_HEADER, CODE_BUNDLE_NAME_ERROR, CODE_BUNDLE_SHARING_VIOLATION, CODE_CANCELLED, CODE_COMMIT_ERROR, CODE_FOREIGN_CUSTOMIZER, CODE_MISSING_BUNDLE, CODE_MISSING_FIXPACK_TARGET, CODE_MISSING_HEADER, CODE_MISSING_RESOURCE, CODE_NOT_A_JAR, CODE_ORDER_ERROR, CODE_OTHER_ERROR, CODE_PROCESSOR_NOT_FOUND, CODE_RESOURCE_SHARING_VIOLATION, CODE_SIGNING_ERROR, CODE_TIMEOUT, DEPLOYMENTPACKAGE_CUSTOMIZER, DEPLOYMENTPACKAGE_FIXPACK, DEPLOYMENTPACKAGE_ICON, DEPLOYMENTPACKAGE_MISSING, DEPLOYMENTPACKAGE_NAME, DEPLOYMENTPACKAGE_SYMBOLICMAME, DEPLOYMENTPACKAGE_VERSION, EVENTPROPERTY_DEPLOYMENTPACKAGE_CURRENTVERSION, EVENTPROPERTY_DEPLOYMENTPACKAGE_NAME, EVENTPROPERTY_DEPLOYMENTPACKAGE_NEXTVERSION, EVENTPROPERTY_DEPLOYMENTPACKAGE_READABLENAME, EVENTPROPERTY_SUCCESSFUL, EVENTTOPIC_COMPLETE, EVENTTOPIC_INSTALL, EVENTTOPIC_UNINSTALL, RESOURCE_PROCESSOR, SERVICE_PID`

### Fields inherited from interface org.osgi.framework.Constants

`ACTIVATION_LAZY, BUNDLE_ACTIVATIONPOLICY, BUNDLE_ACTIVATOR, BUNDLE_CATEGORY, BUNDLE_CLASSPATH, BUNDLE_CONTACTADDRESS, BUNDLE_COPYRIGHT, BUNDLE_DESCRIPTION, BUNDLE_DOCURL, BUNDLE_LOCALIZATION, BUNDLE_LOCALIZATION_DEFAULT_BASENAME, BUNDLE_MANIFESTVERSION, BUNDLE_NAME, BUNDLE_NATIVECODE, BUNDLE_NATIVECODE_LANGUAGE, BUNDLE_NATIVECODE_OSNAME, BUNDLE_NATIVECODE_OSVERSION, BUNDLE_NATIVECODE_PROCESSOR, BUNDLE_REQUIREDEXECUTIONENVIRONMENT, BUNDLE_SYMBOLICNAME_ATTRIBUTE, BUNDLE_UPDATELOCATION, BUNDLE_VENDOR, BUNDLE_VERSION_ATTRIBUTE, DYNAMICIMPORT_PACKAGE, EXCLUDE_DIRECTIVE, EXPORT_PACKAGE, EXPORT_SERVICE, EXTENSION_BOOTCLASSPATH, EXTENSION_DIRECTIVE, EXTENSION_FRAMEWORK, FRAGMENT_ATTACHMENT_ALWAYS, FRAGMENT_ATTACHMENT_DIRECTIVE, FRAGMENT_ATTACHMENT_NEVER, FRAGMENT_ATTACHMENT_RESOLVETIME, FRAGMENT_HOST, FRAMEWORK_BEGINNING_STARTLEVEL, FRAMEWORK_BOOTDELEGATION, FRAMEWORK_BUNDLE_PARENT, FRAMEWORK_BUNDLE_PARENT_APP, FRAMEWORK_BUNDLE_PARENT_BOOT, FRAMEWORK_BUNDLE_PARENT_EXT, FRAMEWORK_BUNDLE_PARENT_FRAMEWORK, FRAMEWORK_EXECPERMISSION, FRAMEWORK_EXECUTIONENVIRONMENT, FRAMEWORK_LANGUAGE, FRAMEWORK_LIBRARY_EXTENSIONS, FRAMEWORK_OS_NAME, FRAMEWORK_OS_VERSION, FRAMEWORK_PROCESSOR, FRAMEWORK_SECURITY, FRAMEWORK_SECURITY_OSGI, FRAMEWORK_STORAGE, FRAMEWORK_STORAGE_CLEAN, FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT, FRAMEWORK_SYSTEMPACKAGES, FRAMEWORK_SYSTEMPACKAGES_EXTRA, FRAMEWORK_TRUST_REPOSITORIES, FRAMEWORK_VENDOR, FRAMEWORK_VERSION, FRAMEWORK_WINDOWSYSTEM, IMPORT_PACKAGE, IMPORT_SERVICE, INCLUDE_DIRECTIVE, MANDATORY_DIRECTIVE, OBJECTCLASS, PACKAGE_SPECIFICATION_VERSION, REQUIRE_BUNDLE, RESOLUTION_DIRECTIVE, RESOLUTION_MANDATORY, RESOLUTION_OPTIONAL, SELECTION_FILTER_ATTRIBUTE, SERVICE_DESCRIPTION, SERVICE_ID, SERVICE_RANKING, SERVICE_VENDOR, SINGLETON_DIRECTIVE, SUPPORTS_BOOTCLASSPATH_EXTENSION, SUPPORTS_FRAMEWORK_EXTENSION, SUPPORTS_FRAMEWORK_FRAGMENT, SUPPORTS_FRAMEWORK_REQUIREBUNDLE, SYSTEM_BUNDLE_LOCATION, SYSTEM_BUNDLE_SYMBOLICNAME, USES_DIRECTIVE, VERSION_ATTRIBUTE, VISIBILITY_DIRECTIVE, VISIBILITY_PRIVATE, VISIBILITY_REEXPORT`

### Constructor Summary

Constructors
Constructor and Description
`Command()`

### Method Summary

All Methods Instance Methods Abstract Methods Concrete Methods
`protected void` `addCommit(org.apache.felix.deploymentadmin.spi.AbstractAction runnable)` Adds an action to be executed in case of a commit
`protected void` `addRollback(org.apache.felix.deploymentadmin.spi.AbstractAction 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(DeploymentSessionImpl session)` Commits all changes the command may have defined when it was executed by calling the `execute()` method.
`protected abstract void` `doExecute(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.
`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.
`protected void` `rollback(DeploymentSessionImpl session)` 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 final void execute(DeploymentSessionImpl session)
                       throws org.osgi.service.deploymentadmin.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:
  `org.osgi.service.deploymentadmin.DeploymentException` - Thrown if the command could not successfully execute.

#### doExecute

    protected abstract void doExecute(DeploymentSessionImpl session)
                               throws Exception

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:
  `Exception` - in case of this command could not terminate successfully.

#### rollback

    protected void rollback(DeploymentSessionImpl session)

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.

Parameters:
  `session` - the deployment session to rollback, should be used for logging purposes.

#### commit

    protected final void commit(DeploymentSessionImpl session)

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

Parameters:
  `session` - the deployment session to commit, should be used for logging purposes.

#### 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(org.apache.felix.deploymentadmin.spi.AbstractAction 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(org.apache.felix.deploymentadmin.spi.AbstractAction 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.