kaos.core.example
Class KAoSUsecase10

java.lang.Object
  extended by kaos.core.example.KAoSUsecase10
Direct Known Subclasses:
KAoSUsecase20

public class KAoSUsecase10
extends java.lang.Object

$Revision: 1.2 $


Field Summary
protected  java.lang.String _agentNickname
           
protected  AgentDirectoryService ads
           
protected  AgentNamingService ans
           
protected static java.lang.String CONVERSATION_FLAG
           
protected  Locator lctr
           
protected static java.io.PrintStream LOGGER
           
protected  MessageTransportService mts
           
protected  AgentName name
           
protected  ServiceRoot sr
           
protected static java.lang.String[] STATEMENT
           
 
Constructor Summary
protected KAoSUsecase10(ServiceRoot sr, java.lang.String nickname)
          Instantiates a new Usecase with the provided ServiceRoot.
 
Method Summary
 AgentDirectoryService acquireAgentDirectoryService()
          Acquires the AgentDirectoryService from the ServiceRoot.
 AgentName acquireAgentName()
          Acquires a unique AgentName from the AgentNamingService.
 AgentNamingService acquireAgentNamingService()
          Acquires the AgentNamingService from the ServiceRoot.
 MessageTransportService acquireMessageTransportService()
          Acquires a MessageTransportService.
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()
          Returns a new local locator that has been bound with the MessageTransportService.
 boolean equals(java.lang.Object obj)
          Two use-cases are equal if their respective hash codes are equal.
 AgentDescription getAgentDescription()
          Creates a new AgentDescription for this Usecase.
 int hashCode()
          Determines the hash code for the use-case.
protected  void initialize()
          Initialize the Usecase (i.e.
static void main(java.lang.String[] args)
           
 void receiveMessage(TransportMessage tmsg)
          Implements the receiveMessage method mandated by the MessageListener interface.
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

sr

protected ServiceRoot sr

name

protected AgentName name

lctr

protected Locator lctr

ans

protected AgentNamingService ans

ads

protected AgentDirectoryService ads

mts

protected MessageTransportService mts

LOGGER

protected static final java.io.PrintStream LOGGER

CONVERSATION_FLAG

protected static final java.lang.String CONVERSATION_FLAG
See Also:
Constant Field Values

STATEMENT

protected static final java.lang.String[] STATEMENT

_agentNickname

protected java.lang.String _agentNickname
Constructor Detail

KAoSUsecase10

protected KAoSUsecase10(ServiceRoot sr,
                        java.lang.String nickname)
Instantiates a new Usecase with the provided ServiceRoot. The ServiceRoot argument is held by the Usecase. Therefore changes to the ServiceRoot, after Usecase instantiation, can affect the use-case behavior.

Parameters:
sr - the instantiating ServiceRoot (a reference is kept).
See Also:
ServiceRoot, "JAS Specification, Section(s) 2.2.2.1, 3.3"
Method Detail

receiveMessage

public void receiveMessage(TransportMessage tmsg)
Implements the receiveMessage method mandated by the MessageListener interface. This method simply 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 use-cases are equal if their respective hash codes are equal.

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

hashCode

public int hashCode()
Determines the hash code for the use-case. The use-case 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 Usecase.
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 MessageTransportService. The TransportSystem is gotten from the ServiceRoot and used to get the list of available MessageTransportServices. Assuming that the number of available MessageTransportServices is greater than zero, the first MessageTransportServic is used, otherwise null is returned.

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

bindToMessageTransportService

public Locator bindToMessageTransportService()
                                      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()
                           throws java.lang.Exception
Acquires a unique AgentName from the AgentNamingService.

Returns:
a unique AgentName
Throws:
java.lang.Exception
See Also:
AgentName, AgentNamingService#createAgentName, "JAS Specification, Section(s) 2.2.2.2, 4.6.1"

getAgentDescription

public AgentDescription getAgentDescription()
Creates a new AgentDescription for this Usecase. Utilizing the AgentDirectoryService an empty AgentDescription is obtained and then populated with various key-value pairs.

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

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"

initialize

protected void initialize()
                   throws java.lang.Exception
Initialize the Usecase (i.e. Agent). 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 AgentDirectoryService
  7. Build the AgentDescription
  8. Register the AgentDescription with the AgentDirectoryService

Throws:
java.lang.Exception
See Also:
acquireAgentNamingService(), acquireAgentName(), acquireMessageTransportService(), bindToMessageTransportService(), acquireAgentDirectoryService(), acquireAgentDirectoryService(), getAgentDescription(), AgentDirectoryService#register(AgentDescription), "JAS Specification, Section(s) 2.2.2.1 through 2.2.2.7"

main

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