kaos.dfra.dlik
Class DLIKImpl

java.lang.Object
  extended by kaos.core.util.MethodCallRequestHandler
      extended by kaos.core.csi.request.ActionMethodRequestHandler
          extended by kaos.dfra.dlik.DLIKImpl
All Implemented Interfaces:
AIDRequestReceiver, HashMapRequestReceiver, DLIK

public class DLIKImpl
extends ActionMethodRequestHandler
implements DLIK

Defines the DFRA Logical Interface to KAoS.

Author:
KAoS Team $Revision: 1.13 $

Field Summary
static java.lang.String DEFAULT_DFRA_CONTEXT
           
static java.lang.String DEFAULT_DFRA_ROLE
           
static java.lang.String DEFAULT_KAOS_TRANSPORT
           
static java.lang.String ROLE_PREFIX_URI
           
static java.lang.String ROLE_URI
           
 
Fields inherited from class kaos.core.csi.request.ActionMethodRequestHandler
_policyService
 
Fields inherited from class kaos.core.util.MethodCallRequestHandler
_agentDescription, _helper, _mts, _nickName, DEFAULT_NICKNAME, myLocator, myMessageReceiver, myMessageSender
 
Fields inherited from interface kaos.dfra.dlik.DLIK
NEGATIVE_DOMAIN_MODALITY, POSITIVE_DOMAIN_MODALITY
 
Method Summary
 void addCommandListener(CommandListener listener)
          Add the CommandListener to the list of those notified when a remote KAoS command is received.
 void assignAgentToRole(java.lang.String agentName, java.lang.String roleName, java.lang.String contextName)
          Assign an agent to an additional role (does not remove any existing roles).
protected  void checkForNullArgument(java.lang.Object arg, java.lang.String methodName, java.lang.String argName)
          Utility method: if the exp is true, then the arg is null.
 void checkPermission(java.lang.String actorGUID, java.lang.String attemptedActionName, java.util.HashMap actionProperties, java.lang.String conceptMappingName)
          Check permission for the action described by the given action name and properties.
 void deregisterAgent(java.lang.String agentName)
          Deregister the agent from KAoS.
 java.util.Properties getActionProperties(ActionInfo kaosAction)
          Convert a KAoS BasicActionDescription to a Properties object.
 java.util.List getActorsInRole(java.lang.String roleName)
          Query KAoS for all Actors registered in the given role
 KAoSAgentDescription getAgentDescriptionForGUID(java.lang.String agentGUID)
          Return a KAoSAgentDescription for an agent, whose GUID is specified.
 java.util.List getAgentDescriptionForNickname(java.lang.String agentNickname)
          Return a List of KAoSAgentDescriptions of agents, whose nickname is specified.
 java.util.List getAgentRoles(java.lang.String agentName)
          Gets the list of roles to which the agent is currently assigned.
 java.util.List getAgentsWithAttributes(java.util.Hashtable searchAttributes)
          Return a List of KAoSAgentDescriptions whose attributes match exactly all specified attributes.
 java.util.List getAllAgents()
          Return a List of guids of all agents registered in the KAoS Directory Service.
 DomainDescription getDomain(java.lang.String domainName)
          Return a DomainDescription of the domain, whose name is specified.
static DLIK getInstance()
          Retrieve an instance of DLIK.
 java.util.List<ActionInstanceDescription> getObligationsForTriggerCondition(java.lang.String actionActorGUID, java.lang.String triggerActionName, java.util.HashMap triggerActionProperties, java.lang.String conceptMappingName)
          Based on the specified trigger action actor, name and properties, select all applicable obligation ActionInstanceDescriptions.
 java.util.Vector getPoliciesForAgent(java.lang.String agentName)
          Get all of the obligations for an agent (all roles, all action types).
 java.util.List<ActionInstanceDescription> getPoliciesForAgentAction(java.lang.String agentName, java.lang.String actionType)
          Get all of the obligations of a specific action type for an agent.
 java.util.Vector getPoliciesForAgentRole(java.lang.String agentName, java.lang.String role, java.lang.String context)
          Get the obligations associated with a specific role for an agent (one role, all action types).
 java.util.List getTeamLeaders(java.lang.String teamURI)
           
 java.util.List getTeamsLedBy(java.lang.String agentId)
           
protected  void handleObjContent(java.lang.Object obj)
          Handle a message received that is not a Method call request (see reportIntruder())
 boolean isAgentMemberOfRole(java.lang.String agentName, java.lang.String roleName, java.lang.String contextName)
          Gets whether the agent is assigned the given role.
protected  void logMessage(java.lang.String msg, java.lang.Exception e, int logLevel)
           
protected  void logMessage(java.lang.String msg, int logLevel)
           
 KAoSAgentDescription registerAgent(java.lang.String agentName, java.lang.String roleName, java.lang.String contextName)
          Register an agent with KAoS, in its starting role.
 void registerTriggerConditionListener(java.lang.String triggerActionClassName, TriggerConditionListener listenerRef)
          Request registration of the specified TriggerConditionListener in the Guard's registry of trigger listeners.
 void removeAgentFromRole(java.lang.String agentName, java.lang.String roleName, java.lang.String contextName)
          Unassign an agent from a previously assigned Role.
 void removeCommandListener(CommandListener listener)
          Remove the CommandListener from the list of those notified when a remote KAoS command is received.
 void removeTeamLeader(java.lang.String agentId, java.lang.String teamURI)
           
 void reportIntruder(double latitude, double longitude)
          Send a message to the KAoS CMDR agent, the message contains the GPS coordinates of an intruder.
 void sendMessageTo(java.lang.String receiverName, java.io.Serializable messageContent)
          Send a message to a specified agent that is registered with KAoS.
 void setAsTeamLeader(java.lang.String agentId, java.lang.String teamURI)
           
 boolean setMapping(java.lang.String mappingName, java.lang.String fileNameLoc)
          Set the ontology mapping, whose name and location are given.
 java.lang.String StartScenario()
          Method called remotely (by TRIPS voice command) to tell the USF commander to start PhaseI of the demo.
 java.lang.String StartScenario(java.util.HashMap map)
           
 
Methods inherited from class kaos.core.csi.request.ActionMethodRequestHandler
bindToPolicyService, checkPermissionForAction, executeHashMapBasedAction, getPropertiesFromAID, processAIDRequest, processAIDRequest, processHashMapRequest, processHashMapRequest, processHashMapRequest, processHashMapRequest
 
Methods inherited from class kaos.core.util.MethodCallRequestHandler
bindToTransport, handleMsgContent, initialize, receiveMessage
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ROLE_URI

public static final java.lang.String ROLE_URI
See Also:
Constant Field Values

ROLE_PREFIX_URI

public static final java.lang.String ROLE_PREFIX_URI
See Also:
Constant Field Values

DEFAULT_DFRA_ROLE

public static final java.lang.String DEFAULT_DFRA_ROLE
See Also:
Constant Field Values

DEFAULT_DFRA_CONTEXT

public static final java.lang.String DEFAULT_DFRA_CONTEXT
See Also:
Constant Field Values

DEFAULT_KAOS_TRANSPORT

public static final java.lang.String DEFAULT_KAOS_TRANSPORT
See Also:
Constant Field Values
Method Detail

getInstance

public static DLIK getInstance()
                        throws java.lang.Exception
Retrieve an instance of DLIK.

Parameters:
transportName - String specifying the name of the transport to use for communication with the KAoS Directory Service.
Returns:
a singleton, DLIK.
Throws:
java.lang.Exception

registerAgent

public KAoSAgentDescription registerAgent(java.lang.String agentName,
                                          java.lang.String roleName,
                                          java.lang.String contextName)
                                   throws DirectoryFailure,
                                          GuardInstantiationException
Register an agent with KAoS, in its starting role.

Specified by:
registerAgent in interface DLIK
Parameters:
agentName -
roleName -
Returns:
Throws:
AlreadyRegisteredException
DirectoryFailure
GuardInstantiationException

setAsTeamLeader

public void setAsTeamLeader(java.lang.String agentId,
                            java.lang.String teamURI)
                     throws NotRegisteredException,
                            DirectoryFailure,
                            ModificationException
Throws:
NotRegisteredException
DirectoryFailure
ModificationException

removeTeamLeader

public void removeTeamLeader(java.lang.String agentId,
                             java.lang.String teamURI)
                      throws NotRegisteredException,
                             DirectoryFailure,
                             ModificationException
Throws:
NotRegisteredException
DirectoryFailure
ModificationException

getTeamLeaders

public java.util.List getTeamLeaders(java.lang.String teamURI)
                              throws DirectoryFailure,
                                     QueryFailure
Throws:
DirectoryFailure
QueryFailure

getTeamsLedBy

public java.util.List getTeamsLedBy(java.lang.String agentId)
                             throws DirectoryFailure,
                                    QueryFailure
Throws:
DirectoryFailure
QueryFailure

assignAgentToRole

public void assignAgentToRole(java.lang.String agentName,
                              java.lang.String roleName,
                              java.lang.String contextName)
                       throws AlreadyRegisteredException,
                              DirectoryFailure,
                              GuardInstantiationException
Assign an agent to an additional role (does not remove any existing roles).

Specified by:
assignAgentToRole in interface DLIK
Parameters:
agentName -
roleName -
Throws:
AlreadyRegisteredException
DirectoryFailure
GuardInstantiationException

removeAgentFromRole

public void removeAgentFromRole(java.lang.String agentName,
                                java.lang.String roleName,
                                java.lang.String contextName)
                         throws NotRegisteredException,
                                DirectoryFailure
Unassign an agent from a previously assigned Role.

Specified by:
removeAgentFromRole in interface DLIK
Parameters:
agentName -
roleName -
Throws:
NotRegisteredException
DirectoryFailure

deregisterAgent

public void deregisterAgent(java.lang.String agentName)
                     throws NotRegisteredException,
                            DirectoryFailure
Deregister the agent from KAoS.

Specified by:
deregisterAgent in interface DLIK
Parameters:
agentName -
Throws:
NotRegisteredException
DirectoryFailure

getPoliciesForAgent

public java.util.Vector getPoliciesForAgent(java.lang.String agentName)
                                     throws java.net.URISyntaxException
Description copied from interface: DLIK
Get all of the obligations for an agent (all roles, all action types). Get a Vector of KAoS which are the obliged actions from KAoS for the given agent based on the agent's role assignments.

Specified by:
getPoliciesForAgent in interface DLIK
Returns:
Vector
Throws:
java.net.URISyntaxException

getPoliciesForAgentRole

public java.util.Vector getPoliciesForAgentRole(java.lang.String agentName,
                                                java.lang.String role,
                                                java.lang.String context)
                                         throws java.net.URISyntaxException
Description copied from interface: DLIK
Get the obligations associated with a specific role for an agent (one role, all action types). Get a Vector of KAoS which are the obliged actions from KAoS for the given agent based on the agent's role assignments.

Specified by:
getPoliciesForAgentRole in interface DLIK
Returns:
Vector
Throws:
java.net.URISyntaxException

getPoliciesForAgentAction

public java.util.List<ActionInstanceDescription> getPoliciesForAgentAction(java.lang.String agentName,
                                                                           java.lang.String actionType)
                                                                    throws java.net.URISyntaxException
Description copied from interface: DLIK
Get all of the obligations of a specific action type for an agent. (all roles, one action type [AssignRole|NavigateAction|WaypointAction]). See http://ontology.ihmc.us/DFRARoles.owl for available action types (the subclasses of DFRAAction owl class) Get a Vector of KAoS which are the obliged actions from KAoS for the given agent based on the agent's role assignments.

Specified by:
getPoliciesForAgentAction in interface DLIK
Returns:
Vector
Throws:
java.net.URISyntaxException

getActionProperties

public java.util.Properties getActionProperties(ActionInfo kaosAction)
Description copied from interface: DLIK
Convert a KAoS BasicActionDescription to a Properties object.

Specified by:
getActionProperties in interface DLIK
Returns:

isAgentMemberOfRole

public boolean isAgentMemberOfRole(java.lang.String agentName,
                                   java.lang.String roleName,
                                   java.lang.String contextName)
                            throws DirectoryFailure
Gets whether the agent is assigned the given role.

Specified by:
isAgentMemberOfRole in interface DLIK
Returns:
true if the agent is registered in the role, otherwise false
Throws:
DirectoryFailure

getAgentRoles

public java.util.List getAgentRoles(java.lang.String agentName)
Gets the list of roles to which the agent is currently assigned.

Specified by:
getAgentRoles in interface DLIK
Returns:
List - KAoS URI's (e.g. http://ontology.ihmc.us/DFRARoles.owl#Scout)

addCommandListener

public void addCommandListener(CommandListener listener)
Add the CommandListener to the list of those notified when a remote KAoS command is received. e.g. 'StartScenario'

Specified by:
addCommandListener in interface DLIK
Parameters:
listener - - the CommandListener to add

removeCommandListener

public void removeCommandListener(CommandListener listener)
Remove the CommandListener from the list of those notified when a remote KAoS command is received. e.g. 'StartScenario'

Specified by:
removeCommandListener in interface DLIK
Parameters:
listener - - the CommandListener to add

reportIntruder

public void reportIntruder(double latitude,
                           double longitude)
                    throws DirectoryFailure,
                           SearchException,
                           NotLocatableException,
                           TransportFailure
Send a message to the KAoS CMDR agent, the message contains the GPS coordinates of an intruder. This is the demo transition from PhaseI(USF) to PhaseII(IHMC)

Specified by:
reportIntruder in interface DLIK
Parameters:
latitude -
longitude -
Throws:
DirectoryFailure
SearchException
NotLocatableException
TransportFailure

sendMessageTo

public void sendMessageTo(java.lang.String receiverName,
                          java.io.Serializable messageContent)
                   throws DirectoryFailure,
                          SearchException,
                          NotLocatableException,
                          TransportFailure
Send a message to a specified agent that is registered with KAoS.

Specified by:
sendMessageTo in interface DLIK
Parameters:
receiverName - - name recipient agent used to register with KAoS
messageContent - - any Serializable
Throws:
DirectoryFailure
SearchException
NotLocatableException
TransportFailure

handleObjContent

protected void handleObjContent(java.lang.Object obj)
Handle a message received that is not a Method call request (see reportIntruder())

Overrides:
handleObjContent in class MethodCallRequestHandler

StartScenario

public java.lang.String StartScenario()
                               throws java.lang.Exception
Method called remotely (by TRIPS voice command) to tell the USF commander to start PhaseI of the demo. Remote KAoS agents can invoke this method using: CSIFactory.getRequestManager().sendHashMapRequest("USF", "StartScenario"); //where "USF" is the name this agent used to register with kaos

Returns:
"Success"
Throws:
java.lang.Exception - if there are no CommandListeners registered with DLIK

StartScenario

public java.lang.String StartScenario(java.util.HashMap map)
                               throws java.lang.Exception
Throws:
java.lang.Exception

getDomain

public DomainDescription getDomain(java.lang.String domainName)
                            throws DirectoryFailure,
                                   NotRegisteredException
Return a DomainDescription of the domain, whose name is specified.

Specified by:
getDomain in interface DLIK
Parameters:
name - String specifying the name of the domain to lookup.
Throws:
DirectoryFailure - if the connection to the DS cannot be established.
NotRegisteredException - if the requested domain to be looked-up has not been registered in the DS.

getAgentDescriptionForGUID

public KAoSAgentDescription getAgentDescriptionForGUID(java.lang.String agentGUID)
                                                throws DirectoryFailure,
                                                       NotRegisteredException
Return a KAoSAgentDescription for an agent, whose GUID is specified.

Specified by:
getAgentDescriptionForGUID in interface DLIK
Parameters:
agentGUID - String specifying the guid of the agent to lookup.
Throws:
DirectoryFailure - if the connection to the DS cannot be established.
NotRegisteredException - if the agent to be looked-up has not been registered in the DS.

getAgentDescriptionForNickname

public java.util.List getAgentDescriptionForNickname(java.lang.String agentNickname)
                                              throws DirectoryFailure,
                                                     NotRegisteredException
Return a List of KAoSAgentDescriptions of agents, whose nickname is specified.

Specified by:
getAgentDescriptionForNickname in interface DLIK
Parameters:
agentNickname - String specifying the agentNickname of the agent(s) to lookup.
Throws:
DirectoryFailure - if the connection to the DS cannot be established.
NotRegisteredException - if no agents with the given nickname have been registered in the DS.

getAgentsWithAttributes

public java.util.List getAgentsWithAttributes(java.util.Hashtable searchAttributes)
                                       throws DirectoryFailure,
                                              NotRegisteredException
Return a List of KAoSAgentDescriptions whose attributes match exactly all specified attributes.

Specified by:
getAgentsWithAttributes in interface DLIK
Parameters:
searchAttributes - Hashtable containing attribute name => attribute value mappings. NOTE: the names of defaul tentity attributes are defined in interfaces: kaos.core.service.directory.KAoSEntityDescription kaos.core.service.directory.KAoSAgentDescription
Returns:
List of KAoSAgentDescriptions containing all attributes specified in the search attributes Hashtable.
Throws:
DirectoryFailure - if the connection to the DS cannot be established.
NoSuchActorException - if no actors matching the query properties could be found.
NotRegisteredException

getAllAgents

public java.util.List getAllAgents()
                            throws DirectoryFailure,
                                   SearchException
Return a List of guids of all agents registered in the KAoS Directory Service.

Specified by:
getAllAgents in interface DLIK
Returns:
List of guids of all agents registered in the DS.
Throws:
DirectoryFailure - if the connection to the DS cannot be established.
SearchException - if search failed.

checkPermission

public void checkPermission(java.lang.String actorGUID,
                            java.lang.String attemptedActionName,
                            java.util.HashMap actionProperties,
                            java.lang.String conceptMappingName)
                     throws KAoSSecurityException,
                            java.lang.NullPointerException,
                            ServiceFailure
Check permission for the action described by the given action name and properties. If the action is allowed exit quietly, otherwise throw the KAoSSecurityException or NullPointerException.

Specified by:
checkPermission in interface DLIK
Parameters:
actorGUID - String containing the GUID of the agent attempting to perform the action to check permission for.
attemptedActionName - String containing the ontological name of the attempted action. NOTE: many ontological names of actions and their properties are defined in: kaos.ontology.vocabulary.ActionConcepts
actionProperties - HashMap containing the ontological names and their values of properties of the attempted action.
conceptMappingName - String containing the mapping of vocabulary between DFRA and KAoS ontologies. Optional.
Throws:
KAoSSecurityException - if the attempted action is not allowed.
java.lang.NullPointerException - if - will be thrown if any of the required arguments is null (consistent with the semantics of Java checking permission).
ServiceFailure - if the policy service is not available.

registerTriggerConditionListener

public void registerTriggerConditionListener(java.lang.String triggerActionClassName,
                                             TriggerConditionListener listenerRef)
                                      throws TriggerConditionListenerRegistrationException
Request registration of the specified TriggerConditionListener in the Guard's registry of trigger listeners. Associate the listener with the specified trigger action, whose name is given.

Specified by:
registerTriggerConditionListener in interface DLIK
Parameters:
triggerActionClassName - String containing the name of the action class the given trigger listener is going to monitor.
listenerRef - TriggerConditionListener, an instance of a listener, which will be monitoring the action, whose name is given. When Guard receives a policy, whose action matches the triggerActionClassName, Guard will send an update to the listenerRef.
Throws:
TriggerConditionListenerRegistrationException - if the listener registration fails.

getObligationsForTriggerCondition

public java.util.List<ActionInstanceDescription> getObligationsForTriggerCondition(java.lang.String actionActorGUID,
                                                                                   java.lang.String triggerActionName,
                                                                                   java.util.HashMap triggerActionProperties,
                                                                                   java.lang.String conceptMappingName)
                                                                            throws ObligationViolationException,
                                                                                   ServiceFailure
Based on the specified trigger action actor, name and properties, select all applicable obligation ActionInstanceDescriptions. ActionInstanceDescriptions will be sorted in descending order by the priority of the matching obligation policy.

Specified by:
getObligationsForTriggerCondition in interface DLIK
Parameters:
actionActorGUID - String containing the GUID of the agent performing the trigger action.
triggerActionName - String containing the ontological name of the trigger action.
triggeraActionProperties - HashMap containing the ontological names and their values of properties of the trigger action.
conceptMappingName - String containing the mapping of vocabulary between DFRA and KAoS ontologies.
Returns:
A Vector of obligation ActionInstanceDescriptions for the trigger action. The returned control ActionInstanceDescriptions are sorted in descending sequence by their policy priority. Or, the method returns null, if a Thread waiting to complete execution of this method has been interrupted. The Thread's interrupted status will be re-established.
Throws:
ObligationViolationException - if obligation constraints are not satisfied.
ServiceFailure - if the policy service is not available.

setMapping

public boolean setMapping(java.lang.String mappingName,
                          java.lang.String fileNameLoc)
Set the ontology mapping, whose name and location are given.

Specified by:
setMapping in interface DLIK
Parameters:
mappingName - The String specifying the name of the mapping. *** Note *** This name has to be passed to KAoSActorImpl.setConceptMappingName(mappingName) before specifying the terms from the mappingName ontology.
fileNameLoc - The String specifying the name and path of the file containing the mapping.
Returns:
boolean indicating success(true)/failure(false) of the operation. Success means that the file containing the mapping has been found, read and the mapping has been stored.

logMessage

protected void logMessage(java.lang.String msg,
                          int logLevel)

logMessage

protected void logMessage(java.lang.String msg,
                          java.lang.Exception e,
                          int logLevel)

getActorsInRole

public java.util.List getActorsInRole(java.lang.String roleName)
                               throws DirectoryFailure,
                                      QueryFailure
Query KAoS for all Actors registered in the given role

Parameters:
roleName -
Returns:
List of KAoSAgentDescription objects
Throws:
DirectoryFailure
QueryFailure

checkForNullArgument

protected void checkForNullArgument(java.lang.Object arg,
                                    java.lang.String methodName,
                                    java.lang.String argName)
                             throws java.lang.IllegalArgumentException
Utility method: if the exp is true, then the arg is null.

Throws:
java.lang.IllegalArgumentException - if arg is null