kaos.core.service.boot
Class KAoSAgent

java.lang.Object
  extended by kaos.core.service.boot.KAoSAgent
All Implemented Interfaces:
KAoSAgentHelper
Direct Known Subclasses:
CommSpeedTestReceiver, Kaa, KAoSAgentMsgForwarder, KAoSGuardedUsecase1, KAoSmyGridEventHandlerWrapper, KAoSmyGridRepositoryWrapper, KAoSUsecase10New, TestClassifier, TestRobot

public class KAoSAgent
extends java.lang.Object
implements KAoSAgentHelper

$Revision: 1.5 $


Field Summary
protected  KAoSAgentDescription _agentDescription
           
protected  AgentDirectoryService _agentDirectoryService
           
protected  AgentNamingService _agentNamingService
           
protected  java.lang.String _agentNickname
           
protected  Locator _lctr
           
protected  Logger _logger
           
protected  MessageTransportService _messageTransportService
           
protected  AgentName _name
           
protected  KAoSServiceRoot _serviceRoot
           
 
Constructor Summary
KAoSAgent()
          Instantiates a new KAoS-aware agent using JAS services for transport, naming and agent directory.
 
Method Summary
 AgentDirectoryService acquireAgentDirectoryService()
          Acquires the AgentDirectoryService from the ServiceRoot.
 AgentName acquireAgentName(boolean useNicknameAsGuid)
          Acquires a unique AgentName from the AgentNamingService or, if requested, uses the agent nickname to create the AgentName.
 AgentNamingService acquireAgentNamingService()
          Acquires the AgentNamingService from the ServiceRoot.
 MessageTransportService acquireMessageTransportService()
          Acquires a preferred MessageTransportService from the ServiceRoot.
protected  void assertFalse(boolean exp, java.lang.String msg)
          Utility method: if exp is not false, then an Exception is generated using the provided message (msg) and then thrown.
protected  void assertTrue(boolean exp, java.lang.String msg)
          Utility method: if exp is not true, then an Exception is generated using the provided message (msg) and then thrown.
 Locator bindToMessageTransportService(JasBean env)
          Returns a new local locator that has been bound with the MessageTransportService.
 void checkPermission(java.lang.String action, java.util.HashMap properties)
          /** Check permission for the specified action with given parameters.
 TransportMessage createTransportMessage()
           
 boolean equals(java.lang.Object obj)
          Two agents are equal if their respective hash codes are equal.
protected  KAoSAgentDescription establishAgentDescription(java.util.Vector domainNames)
          Creates a new KAoSAgentDescription for this KAoSAgent.
 KAoSAgentDescription findAgentDescriptionForID(java.lang.String agentID)
           
 KAoSAgentDescription findAgentDescriptionForNickname(java.lang.String nickname)
           
 java.lang.String getAgentID()
           
 KAoSAgentDescription getKAoSAgentDescription()
          Returns the KAoSAgentDescription created by this helper.
 int hashCode()
          Determines the hash code for the KAoSAgent.
 void initialize(KAoSServiceRoot sr, JasBean agentInitInfo, java.util.Vector domainNames, java.lang.String nickname, boolean guarded, boolean useNicknameAsGuid)
          Initializes a new KAoSAgent with the provided arguments.
protected  void logMessage(java.lang.String msg, java.lang.Exception e, int logLevel)
           
protected  void logMessage(java.lang.String msg, int logLevel)
           
static void main(java.lang.String[] args)
           
protected  void printTransportMessage(TransportMessage tmsg)
           
 void receiveMessage(TransportMessage tmsg)
          Implements the receiveMessage method mandated by the MessageListener interface.
 void sendMessage(TransportMessage message)
           
protected  boolean verifyRegistration()
          Utility method that verifies agent registration by searching the AgentDirectoryService for its AgentDescription.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_name

protected AgentName _name

_lctr

protected Locator _lctr

_agentNamingService

protected AgentNamingService _agentNamingService

_agentDirectoryService

protected AgentDirectoryService _agentDirectoryService

_messageTransportService

protected MessageTransportService _messageTransportService

_serviceRoot

protected KAoSServiceRoot _serviceRoot

_agentNickname

protected java.lang.String _agentNickname

_agentDescription

protected KAoSAgentDescription _agentDescription

_logger

protected Logger _logger
Constructor Detail

KAoSAgent

public KAoSAgent()
Instantiates a new KAoS-aware agent using JAS services for transport, naming and agent directory.

Method Detail

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 KAoSAgent.
See Also:
hashCode(), "JAS Specification, Section(s) 4.7.2"

hashCode

public int hashCode()
Determines the hash code for the KAoSAgent. The KAoSAgent 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 KAoSAgent.
See Also:
AgentName#hashCode, Object.hashCode(), "JAS Specification, Section(s) 4.7.2"

acquireAgentNamingService

public AgentNamingService acquireAgentNamingService()
                                             throws java.lang.Exception
Acquires the AgentNamingService from the ServiceRoot. This method will throw an Exception if the AgentNamingService has previously been acquired.

Returns:
the acquired AgentNamingService
Throws:
java.lang.Exception - if the AgentNamingService is not null.
See Also:
ServiceRoot#getAgentNamingService, "JAS Specification, Section(s) 2.2.2.2, 4.6.1"

acquireAgentDirectoryService

public AgentDirectoryService acquireAgentDirectoryService()
                                                   throws java.lang.Exception
Acquires the AgentDirectoryService from the ServiceRoot. This method will throw an Exception if the AgentDirectoryService has previously been acquired.

Returns:
the acquired AgentDirectoryService
Throws:
java.lang.Exception - if the AgentDirectoryService is not null.
See Also:
ServiceRoot#getAgentDirectoryService, "JAS Specification, Section(s) 2.2.2.5, 4.5.1"

acquireMessageTransportService

public MessageTransportService acquireMessageTransportService()
                                                       throws java.lang.Exception
Acquires a preferred MessageTransportService from the ServiceRoot.

Returns:
the preferred MessageTransportService, or null.
Throws:
java.lang.Exception - if the MessageTransportService is not null.
See Also:
ServiceRoot#getTransportSystem, "JAS Specification, Section(s) 2.2.2.3, 4.7.5, 4.7.6"

bindToMessageTransportService

public Locator bindToMessageTransportService(JasBean env)
                                      throws java.lang.Exception
Returns a new local locator that has been bound with the MessageTransportService. Utilizing the MessageTransportService a new local Locator and MessageReceiver are obtained. The MessageReceiver then has this class added as a MessageListener, and is bound using the local Locator.

Returns:
the Locator by which the MessageReceiver is bound.
Throws:
java.lang.Exception
See Also:
MessageTransportService#newLocalLocator, Locator, MessageTransportService#newMessageReceiver, MessageReceiver, MessageListener, MessageReceiver#addMessageListener(MessageListener), MessageReceiver#bindToLocalLocator(Locator), "JAS Specification, Section(s) 2.2.2.4, 2.2.2.7, 4.7.3"

acquireAgentName

public AgentName acquireAgentName(boolean useNicknameAsGuid)
                           throws java.lang.Exception
Acquires a unique AgentName from the AgentNamingService or, if requested, uses the agent nickname to create the AgentName.

Returns:
a unique AgentName, or AgentName based on the agent's nickname.
Throws:
java.lang.Exception
See Also:
AgentName, AgentNamingService#createAgentName, "JAS Specification, Section(s) 2.2.2.2, 4.6.1"

establishAgentDescription

protected KAoSAgentDescription establishAgentDescription(java.util.Vector domainNames)
Creates a new KAoSAgentDescription for this KAoSAgent. Populates the description with various key-value pairs. KAoSAgentDescription extends the JAS AgentDescription in order to provide some KAoS-specific key-value pairs.

Returns:
an KAoSAgentDescription for this KAoSAgent.
See Also:
AgentDescription, AgentDirectoryService#createAgentDescription, "JAS Specification, Section(s) 2.2.2.6, 4.5.1"

initialize

public void initialize(KAoSServiceRoot sr,
                       JasBean agentInitInfo,
                       java.util.Vector domainNames,
                       java.lang.String nickname,
                       boolean guarded,
                       boolean useNicknameAsGuid)
                throws java.lang.Exception
Initializes a new KAoSAgent with the provided arguments. Note that theKAoSServiceRoot argument is held by the KAoSAgent. Therefore changes to the KAoSServiceRoot, after KAoSAgent instantiation, can affect the KAoSAgent behavior. Initialize the KAoSAgent. A specific sequence of actions is required to initialize an agent within the JAS environment. That sequence is expressed as...
  1. Acquire the AgentNamingService
  2. Acquire the AgentName from the AgentNamingService
  3. Acquire the MessageTransportService
  4. Acquire the local Locator from the MessageTransportService
  5. Bind the local Locator to the MessageTransportService
  6. Acquire the KAoSAgentDirectoryService
  7. Build the AgentDescription
  8. Register the AgentDescription with the KAoSAgentDirectoryService, or
  9. for guarded agents,ask the Guard the register the agent with
  10. the AKAoSgentDirectoryService.

Parameters:
KAoSServiceRoot - is the instantiating ServiceRoot (a reference is kept).
JasBean - contains additional information about the agent that may be passed to the transport system.
Vector - contains names of domains this agent wants to be a member of.
String - agent's nickname (a reference is kept).
boolean - indicates whether the agent is guarded.
boolean - indicates whether to use agent's nickname as its GUID.
Throws:
java.lang.Exception
See Also:
ServiceRoot, "JAS Specification, Section(s) 2.2.2.1, 3.3", acquireAgentNamingService(), acquireAgentName(boolean), acquireMessageTransportService(), bindToMessageTransportService(JasBean), acquireAgentDirectoryService(), acquireAgentDirectoryService(), establishAgentDescription(java.util.Vector), AgentDirectoryService#register(AgentDescription), "JAS Specification, Section(s) 2.2.2.1 through 2.2.2.7"

checkPermission

public void checkPermission(java.lang.String action,
                            java.util.HashMap properties)
                     throws KAoSSecurityException,
                            java.lang.NullPointerException,
                            ServiceFailure
/** Check permission for the specified action with given parameters. The actor of the action is KAoSAgent.

Specified by:
checkPermission in interface KAoSAgentHelper
Parameters:
action - Ontological name of the policy action.
properties - HashMap containing the names of properties as defined in ontologies and their values.
Throws:
KAoSSecurityException - if the permission is not granted.
java.lang.NullPointerException - if the specified action or properties are null.
ServiceFailure - if some of the security services are not available.

createTransportMessage

public TransportMessage createTransportMessage()
Specified by:
createTransportMessage in interface KAoSAgentHelper

getAgentID

public java.lang.String getAgentID()
Specified by:
getAgentID in interface KAoSAgentHelper

findAgentDescriptionForNickname

public KAoSAgentDescription findAgentDescriptionForNickname(java.lang.String nickname)
Specified by:
findAgentDescriptionForNickname in interface KAoSAgentHelper

findAgentDescriptionForID

public KAoSAgentDescription findAgentDescriptionForID(java.lang.String agentID)
Specified by:
findAgentDescriptionForID in interface KAoSAgentHelper

getKAoSAgentDescription

public KAoSAgentDescription getKAoSAgentDescription()
Description copied from interface: KAoSAgentHelper
Returns the KAoSAgentDescription created by this helper.

Specified by:
getKAoSAgentDescription in interface KAoSAgentHelper
Returns:
an KAoSAgentDescription for this KAoSAgentHelper.

sendMessage

public void sendMessage(TransportMessage message)
                 throws NotLocatableException,
                        TransportFailure
Specified by:
sendMessage in interface KAoSAgentHelper
Throws:
NotLocatableException
TransportFailure

assertTrue

protected void assertTrue(boolean exp,
                          java.lang.String msg)
                   throws java.lang.Exception
Utility method: if exp is not true, then an Exception is generated using the provided message (msg) and then thrown.

Throws:
java.lang.Exception - if exp is false.

assertFalse

protected void assertFalse(boolean exp,
                           java.lang.String msg)
                    throws java.lang.Exception
Utility method: if exp is not false, then an Exception is generated using the provided message (msg) and then thrown.

Throws:
java.lang.Exception - if exp is true.

verifyRegistration

protected boolean verifyRegistration()
Utility method that verifies agent registration by searching the AgentDirectoryService for its AgentDescription.

See Also:
"JAS Specification, Section(s) 4.5.1, 4.5.2"

printTransportMessage

protected void printTransportMessage(TransportMessage tmsg)

logMessage

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

logMessage

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

main

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