kaos.core.csi.command
Class CommandImpl

java.lang.Object
  extended by kaos.core.csi.command.CommandImpl
All Implemented Interfaces:
Command

public class CommandImpl
extends java.lang.Object
implements Command

This class implements the Command interface, which defines sending commands to entities


Nested Class Summary
protected static class CommandImpl.OperationWaiter
          This class is used as a helper class to block Threads invoking the synchronous 'requestAction' methods.
 
Field Summary
protected  java.util.Hashtable _actionRequestors
           
protected  Locator _myLocator
           
protected  java.lang.String _nickname
           
protected  QueryRegistration _query
           
protected  TransportSupport _transport
           
protected  java.lang.String _transportName
           
protected  java.util.Hashtable _waiters
           
 
Method Summary
 void assertNotLocatable(boolean exp, java.lang.String msg)
           
 boolean equals(java.lang.Object obj)
          Two agents are equal if their respective hash codes are equal.
static Command getInstance(java.lang.String transportName)
          Retrieve an instance of Command.
static Command getInstance(java.lang.String transportName, java.lang.String nickName)
          Retrieve a reference to the Command.
 int hashCode()
          Determines the hash code for the AgentUsecase.
static void main(java.lang.String[] args)
           
 void onAborted(java.util.Calendar time, java.lang.Object reason, java.lang.String actionID, java.lang.String actionExecutorID)
          Forward the action aborted info from the given action executor to the feedback receiver associated with the requested action identified by the given actionID.
 void onAccepted(java.util.Calendar time, java.lang.Object acceptInfo, java.lang.String actionID, java.lang.String actionExecutorID)
          Forward the accept info by the action executor to the feedback receiver associated with the requested action identified by the given actionID.
 void onCompleted(java.util.Calendar time, java.lang.Object result, java.lang.String actionID, java.lang.String actionExecutorID)
          Forward the result of the action executed by the given action executor to the feedback receiver associated with the requested action identified by the given actionID.
 void onRefused(java.util.Calendar time, java.lang.Object reason, java.lang.String actionID, java.lang.String actionExecutorID)
          Forward the reason for refusal by the action executor to the feedback receiver associated with the requested action identified by the given actionID.
 void onStarted(java.util.Calendar time, java.lang.Object startedInfo, java.lang.String actionID, java.lang.String actionExecutorID)
          Forward the action started info from the given action executor to the feedback receiver associated with the requested action identified by the given actionID.
protected  void printDebugString(java.lang.String msg, int loggerDisplayLevel)
           
 void receiveMessage(TransportMessage tmsg)
          Implements the receiveMessage method mandated by the MessageListener interface.
protected  void removeWaiter(java.lang.String id)
           
 java.lang.String requestAction(FeedbackReceiver feedbackReceiver, KAoSEntityDescription receiverDesc, java.lang.String owlActionDescription)
          This method sends a command to an entity identified by the given receiverDesc to perform an action described by the given String, which is in the OWL format.
 java.lang.String requestAction(FeedbackReceiver feedbackReceiver, KAoSEntityDescription receiverDesc, java.lang.String actionName, java.util.HashMap properties)
          This method sends a command to an entity identified by the given receiverDesc to perform an action described by the given action name and properties.
 java.lang.String requestAction(FeedbackReceiver feedbackReceiver, java.lang.String receiverID, java.lang.String owlActionDescription)
          This method sends a command to an entity identified by the given receiverID to perform an action described by the given String, which is in the OWL format.
 java.lang.String requestAction(FeedbackReceiver feedbackReceiver, java.lang.String receiverID, java.lang.String actionName, java.util.HashMap properties)
          This method sends a command to an entity identified by the given receiverID to perform an action described by the given action name and properties.
 java.lang.Object requestAction(KAoSEntityDescription receiverDesc, java.lang.String actionName, java.util.HashMap properties)
          This method sends a command to an entity identified by the given receiverDesc to perform an action described by the given action name and roperties.
 java.lang.Object requestAction(java.lang.String receiverID, java.lang.String actionName, java.util.HashMap properties)
          This method sends a command to an entity identified by the given receiverID to perform an action described by the given action name and properties.
protected  MethodCallResultMsg satisfyRequest(MethodCallRequestMsg requestMsg)
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_myLocator

protected Locator _myLocator

_nickname

protected java.lang.String _nickname

_query

protected QueryRegistration _query

_transport

protected TransportSupport _transport

_transportName

protected java.lang.String _transportName

_actionRequestors

protected java.util.Hashtable _actionRequestors

_waiters

protected java.util.Hashtable _waiters
Method Detail

getInstance

public static Command getInstance(java.lang.String transportName)
                           throws java.lang.Exception
Retrieve an instance of Command.

Returns:
a singleton, Command.
Throws:
java.lang.Exception

getInstance

public static Command getInstance(java.lang.String transportName,
                                  java.lang.String nickName)
                           throws java.lang.Exception
Retrieve a reference to the Command.

Parameters:
transportName - is a String containing the name of the transport to use by the Command.
nickName - is a String containing the nick name of the Command that may be used by certain transport implementations, or null if not required by the transport.
Returns:
a reference to the Command
Throws:
java.lang.Exception

requestAction

public java.lang.String requestAction(FeedbackReceiver feedbackReceiver,
                                      java.lang.String receiverID,
                                      java.lang.String actionName,
                                      java.util.HashMap properties)
                               throws ActionFailureException,
                                      NotLocatableException,
                                      TransportFailure
This method sends a command to an entity identified by the given receiverID to perform an action described by the given action name and properties. Feedback from the action execution is sent to the given feedbackReceiver.

Specified by:
requestAction in interface Command
Parameters:
feedbackReceiver - is the FeedbackReceiver requesting the action. All feedback from the action execution will be sent to it.
receiverID - is the String that identifies the entity, which is requested to perform the action. The receiverID is the one that the action executor has registered with KAoS.
actionName - is a String representing the name of the action as defined in the associated ontology.
properties - is an HashMap of ontological Strings representing the desired properties of the action and the associated values.
Returns:
String containing the unique id of the requested action. This id will be used by the FeedbackReceiver to track the status of action execution.
Throws:
ActionFailureException - containing the reason for failure. See ontology to determine specific reasons available for a given action
NotLocatableException - when the entity reqested to perform the action cannot be located.
TransportFailure - when transport services fail.

requestAction

public java.lang.String requestAction(FeedbackReceiver feedbackReceiver,
                                      KAoSEntityDescription receiverDesc,
                                      java.lang.String actionName,
                                      java.util.HashMap properties)
                               throws ActionFailureException,
                                      NotLocatableException,
                                      TransportFailure
This method sends a command to an entity identified by the given receiverDesc to perform an action described by the given action name and properties. Feedback from the action execution is sent to the given feedbackReceiver.

Specified by:
requestAction in interface Command
Parameters:
feedbackReceiver - is the FeedbackReceiver requesting the action. All feedback from the action execution will be sent to it.
receiverDesc - is KAosEntityDescription of the entity, which is requested to perform the action.
actionName - is a String representing the name of the action as defined in the associated (with the action) ontology.
properties - is an HashMap of ontological Strings representing the desired properties of the action and the associated values.
Returns:
String containing the unique id of the requested action. This id will be used by the FeedbackReceiver to track the status of action execution.
Throws:
ActionFailureException - containing the reason for failure. See ontology to determine specific reasons available for a given action
NotLocatableException - when the entity reqested to perform the action cannot be located.
TransportFailure - when transport services fail.

requestAction

public java.lang.String requestAction(FeedbackReceiver feedbackReceiver,
                                      java.lang.String receiverID,
                                      java.lang.String owlActionDescription)
                               throws ActionFailureException,
                                      NotLocatableException,
                                      TransportFailure
This method sends a command to an entity identified by the given receiverID to perform an action described by the given String, which is in the OWL format. Feedback from the action execution is sent to the given feedbackReceiver.

Specified by:
requestAction in interface Command
Parameters:
feedbackReceiver - is the FeedbackReceiver requesting the action. All feedback from the action execution will be sent to it.
receiverID - is the String that identifies the entity, which is requested to perform the action. The receiverID is the one that the action executor has registered with KAoS.
owlActionDescription - is an OWL String that describes the action. It includes the actionname and all action properties and their values.
Returns:
String containing the unique id of the requested action. This id will be used by the FeedbackReceiver to track the status of action execution.
Throws:
ActionFailureException - containing the reason for failure. See ontology to determine specific reasons available for a given action
NotLocatableException - when the entity reqested to perform the action cannot be located.
TransportFailure - when transport services fail.

requestAction

public java.lang.String requestAction(FeedbackReceiver feedbackReceiver,
                                      KAoSEntityDescription receiverDesc,
                                      java.lang.String owlActionDescription)
                               throws ActionFailureException,
                                      NotLocatableException,
                                      TransportFailure
This method sends a command to an entity identified by the given receiverDesc to perform an action described by the given String, which is in the OWL format. Feedback from the action execution is sent to the given feedbackReceiver.

Specified by:
requestAction in interface Command
Parameters:
feedbackReceiver - is the FeedbackReceiver requesting the action. All feedback from the action execution will be sent to it.
receiverDesc - is KAosEntityDescription of the entity, which is requested to perform the action.
owlActionDescription - is an OWL String that describes the action. It includes the action name and all action properties and their values.
Returns:
String containing the unique id of the requested action. This id will be used by the FeedbackReceiver to track the status of action execution.
Throws:
ActionFailureException - containing the reason for failure. See ontology to determine specific reasons available for a given action
NotLocatableException - when the entity reqested to perform the action cannot be located.
TransportFailure - when transport services fail.

requestAction

public java.lang.Object requestAction(java.lang.String receiverID,
                                      java.lang.String actionName,
                                      java.util.HashMap properties)
                               throws ActionFailureException,
                                      NotLocatableException,
                                      TransportFailure
This method sends a command to an entity identified by the given receiverID to perform an action described by the given action name and properties. The result is returned synchronously to the caller.

Specified by:
requestAction in interface Command
Parameters:
receiverID - is the String that identifies the entity, which is requested to perform the action. The receiverID is the one that the action executor has registered with KAoS.
actionName - is a String representing the name of the action as defined in the associated ontology.
properties - is a HashMap of Strings representing names of the desired properties as defined in the associated ontology and their values.
Returns:
Object containing the result of the requested action.
Throws:
ActionFailureException - containing the reason for failure. See ontology to determine specific reasons available for a given action
NotLocatableException - when the entity reqested to perform the action cannot be located.
TransportFailure

requestAction

public java.lang.Object requestAction(KAoSEntityDescription receiverDesc,
                                      java.lang.String actionName,
                                      java.util.HashMap properties)
                               throws ActionFailureException,
                                      NotLocatableException,
                                      TransportFailure
This method sends a command to an entity identified by the given receiverDesc to perform an action described by the given action name and roperties. The result will be returned synchronously.

Specified by:
requestAction in interface Command
Parameters:
receiverDesc - is KAosEntityDescription of the entity, which is requested to perform the action.
actionName - is a String representing the name of the action as defined in the associated ontology.
properties - is a HashMap of Strings representing names of the desired properties as defined in the associated ontology and their values.
Returns:
Object containing result of the requested action.
Throws:
ActionFailureException - containing the reason for failure. See ontology to determine specific reasons available for a given action
NotLocatableException - when the entity reqested to perform the action cannot be located.
TransportFailure

receiveMessage

public void receiveMessage(TransportMessage tmsg)
Implements the receiveMessage method mandated by the MessageListener interface. This method prints the incoming TransportMessage to System.out.

See Also:
MessageListener, TransportMessage, "JAS Specification, Section(s) 3.4.2, 4.7.2"

equals

public boolean equals(java.lang.Object obj)
Two agents are equal if their respective hash codes are equal.

Overrides:
equals in class java.lang.Object
Returns:
true if obj equals this AgentUsecase.
See Also:
hashCode(), "JAS Specification, Section(s) 4.7.2"

hashCode

public int hashCode()
Determines the hash code for the AgentUsecase. The AgentUsecase hash code is simply the hash code of the represented agents AgentName. If the AgentName field has not yet been set, then the hash code is found from super.hashCode() .

Overrides:
hashCode in class java.lang.Object
Returns:
int the hashCode for this AgentUsecase.
See Also:
AgentName#hashCode, Object.hashCode(), "JAS Specification, Section(s) 4.7.2"

onAccepted

public void onAccepted(java.util.Calendar time,
                       java.lang.Object acceptInfo,
                       java.lang.String actionID,
                       java.lang.String actionExecutorID)
Forward the accept info by the action executor to the feedback receiver associated with the requested action identified by the given actionID.

Parameters:
time - Calendar time of acceptance.
acceptInfo - Object containing additional (optional) info about the acceptance.
actionID - String containing the id of the requested action/information.
actionExecutorID - String containing the name of the robot performing the action.

onRefused

public void onRefused(java.util.Calendar time,
                      java.lang.Object reason,
                      java.lang.String actionID,
                      java.lang.String actionExecutorID)
Forward the reason for refusal by the action executor to the feedback receiver associated with the requested action identified by the given actionID.

Parameters:
time - Calendar time of refusal.
reason - Object containing the reason for refusing the request.
actionID - String containing the id of the requested action/information.
actionExecutorID - String containing the name of the robot performing the action.

onCompleted

public void onCompleted(java.util.Calendar time,
                        java.lang.Object result,
                        java.lang.String actionID,
                        java.lang.String actionExecutorID)
Forward the result of the action executed by the given action executor to the feedback receiver associated with the requested action identified by the given actionID.

Parameters:
time - Calendar time of information/action completion.
result - Object containing the result of the requested action.
actionID - String containing the id of the requested action/information.
actionExecutorID - String containing the name of the robot performing the action.

onStarted

public void onStarted(java.util.Calendar time,
                      java.lang.Object startedInfo,
                      java.lang.String actionID,
                      java.lang.String actionExecutorID)
Forward the action started info from the given action executor to the feedback receiver associated with the requested action identified by the given actionID.

Parameters:
time - Calendar time of starting an action.
startedInfo - Object containing additional (optional) info about the start of the action.
actionID - String containing the id of the requested action/information.
actionExecutorID - String containing the name of the robot performing the action.

onAborted

public void onAborted(java.util.Calendar time,
                      java.lang.Object reason,
                      java.lang.String actionID,
                      java.lang.String actionExecutorID)
Forward the action aborted info from the given action executor to the feedback receiver associated with the requested action identified by the given actionID.

Parameters:
time - Calendar time of aborting an action.
reason - Object containing the reason for aborting an action.
actionID - String containing the id of the requested action/information.
actionExecutorID - String containing the name of the robot performing the action.

satisfyRequest

protected MethodCallResultMsg satisfyRequest(MethodCallRequestMsg requestMsg)

assertNotLocatable

public void assertNotLocatable(boolean exp,
                               java.lang.String msg)
                        throws NotLocatableException
Throws:
NotLocatableException - if exp is true.

removeWaiter

protected void removeWaiter(java.lang.String id)

printDebugString

protected void printDebugString(java.lang.String msg,
                                int loggerDisplayLevel)

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Throws:
java.lang.Exception