org.drupal.project.computing
Class DCommand

java.lang.Object
  extended by org.drupal.project.computing.DCommand
All Implemented Interfaces:
java.lang.Runnable, java.util.concurrent.Callable<DRecord>
Direct Known Subclasses:
DJyCommand, PingMe

public abstract class DCommand
extends java.lang.Object
implements java.lang.Runnable, java.util.concurrent.Callable<DRecord>

Individual command to be executed. Each command is also registered with a DApplication. A command doesn't necessarily know a DSite. If needed, it can get from DApplication. The Record class needs to know a DSite in order to do database operations. DCommand has no constructor. To initialize a DCommand, use the "create()" factory method, which also initialize things for all DCommand sub-classes. Sub-classes should implement the map* methods for further initialization.


Field Summary
protected  DApplication application
           
protected  java.util.logging.Logger logger
           
protected  DRecord record
           
 
Constructor Summary
DCommand()
           
 
Method Summary
protected  void after()
           
protected  void before()
           
 DRecord call()
          Impelments Callable::call().
static DCommand create(java.lang.Class<? extends DCommand> commandClass, DApplication application)
           
static DCommand create(java.lang.Class<? extends DCommand> commandClass, DApplication application, DRecord record)
          Create a command sub-class, and then initialize it.
protected abstract  void execute()
          The execution of DCommand sub-class doesn't have to care about DRecord.
protected  DApplication getApplication()
           
protected  DSite getDrupalSite()
          Each DCommand is associated with one DApplication, which means it's associated with one Drupal site.
 java.lang.String getIdentifier()
           
protected  DRecord getRecord()
           
abstract  void keepResults(DRecord record)
          Saves command results back to the record.
abstract  void mapArgs(java.lang.String[] args, DRecord record)
          Defines how to map the args to the given record.
abstract  void mapRecord(DRecord record)
          Defines how to map a record to the parameters in the command.
protected  void markProgress(float progress)
           
protected  void markStatus(DRecord.Status status)
           
protected  void printMessage(java.lang.String message)
           
 void run()
          Overrides Runnable.run().
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected java.util.logging.Logger logger

application

protected DApplication application

record

protected DRecord record
Constructor Detail

DCommand

public DCommand()
Method Detail

create

public static DCommand create(java.lang.Class<? extends DCommand> commandClass,
                              DApplication application,
                              DRecord record)
Create a command sub-class, and then initialize it.

Parameters:
commandClass -
application -
record -
Returns:

create

public static DCommand create(java.lang.Class<? extends DCommand> commandClass,
                              DApplication application)

getApplication

protected DApplication getApplication()

getRecord

protected DRecord getRecord()

getDrupalSite

protected DSite getDrupalSite()
Each DCommand is associated with one DApplication, which means it's associated with one Drupal site.

Returns:

getIdentifier

public java.lang.String getIdentifier()

markStatus

protected void markStatus(DRecord.Status status)
                   throws DConnectionException
Throws:
DConnectionException

markProgress

protected void markProgress(float progress)
                     throws DConnectionException
Throws:
DConnectionException

printMessage

protected void printMessage(java.lang.String message)

mapRecord

public abstract void mapRecord(DRecord record)
Defines how to map a record to the parameters in the command.

Parameters:
record -

mapArgs

public abstract void mapArgs(java.lang.String[] args,
                             DRecord record)
Defines how to map the args to the given record. DApplication will then run mapRecord() so there's no need to initialize the command here.

Parameters:
args -
record -

keepResults

public abstract void keepResults(DRecord record)
Saves command results back to the record. If you don't want to save results to the record, you don't need to write code here.


run

public void run()
Overrides Runnable.run(). Sub-class can either override this method, or override execute() instead. The latter is recommended. If override this method, the sub-class needs to handle "record". If only overrides execute(), no need to handle "record".

Specified by:
run in interface java.lang.Runnable

before

protected void before()

after

protected void after()

execute

protected abstract void execute()
                         throws DCommandExecutionException,
                                DConnectionException
The execution of DCommand sub-class doesn't have to care about DRecord.

Throws:
DCommandExecutionException
DConnectionException

call

public DRecord call()
Impelments Callable::call(). Usually you don't need to override this.

Specified by:
call in interface java.util.concurrent.Callable<DRecord>
Returns: