kaos.core.service.transport.grid
Class GridMessageReceiver

java.lang.Object
  extended by kaos.core.service.transport.grid.GridMessageReceiver

public class GridMessageReceiver
extends java.lang.Object

MessageReceiver is an endpoint created by a transport service. It is used as the means by which messages enter the agent. The agent can either receive message synchronously (via polling getMessage) or asynchronously (via the MessageListener callback). Prior to messaging use, the MessageReceiver must be bound to a local locator.

When using the MessageReceiver in a polling fashion the number of messages present (awaiting delivery) can be myEnumerated (count). The waiting message can be received by invoking one of the getMessage() methods.

See Also:
MessageTransportService, TransportSystem

Field Summary
 java.lang.String REMOTE_AGENT_REP
           
 
Constructor Summary
GridMessageReceiver(MessageTransportService transportService)
           
GridMessageReceiver(MessageTransportService transportService, java.lang.String serviceFileName)
           
 
Method Summary
 void addMessageListener(javax.agent.service.transport.MessageListener ml)
          Adds a MessageListener to the MessageReceiver for asynchronous message delivery.
 void bindToLocalLocator(Locator l)
          The method which binds the MessageReceiver to a local locator.
 AgentRep getAgentRep()
           
 Locator getLocalLocator()
          Returns a local locator depending upon binding status.
 javax.agent.TransportMessage getMessage()
          A blocking read operation.
 javax.agent.TransportMessage getMessage(long wait_millis)
          A timed blocking read operation.
 MessageTransportService getMessageTransportService()
           
 int getNumberOfMessages()
          The the number returned does not guarantee the actual number of messages available instantaneously.
 void messageAdded(Message msg)
          Implements the Grid MessageListener interface.
 void removeMessageListener(javax.agent.service.transport.MessageListener ml)
          Removes a MessageListener from the MessageReceiver.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

REMOTE_AGENT_REP

public java.lang.String REMOTE_AGENT_REP
Constructor Detail

GridMessageReceiver

public GridMessageReceiver(MessageTransportService transportService)

GridMessageReceiver

public GridMessageReceiver(MessageTransportService transportService,
                           java.lang.String serviceFileName)
Method Detail

getMessageTransportService

public MessageTransportService getMessageTransportService()
                                                   throws TransportFailure
Throws:
TransportFailure

bindToLocalLocator

public void bindToLocalLocator(Locator l)
                        throws NotLocatableException,
                               TransportFailure
The method which binds the MessageReceiver to a local locator.

Parameters:
l - the local Locator.
Throws:
NotLocatableException - if l is not a local locator.
TransportFailure - if the binding process fails.

getLocalLocator

public Locator getLocalLocator()
                        throws TransportFailure
Returns a local locator depending upon binding status. If the MessageReceiver is not bound, then the local locator is randomly created and returned. Otherwise, the locator used for binding is returned.

Returns:
Locator a local locator.
Throws:
TransportFailure - if any transport related failure occurs.

addMessageListener

public void addMessageListener(javax.agent.service.transport.MessageListener ml)
                        throws TransportFailure
Adds a MessageListener to the MessageReceiver for asynchronous message delivery.

Parameters:
ml - the MessageListener to callback with the incoming message.
Throws:
TransportFailure - if any transport related failure occurs.

removeMessageListener

public void removeMessageListener(javax.agent.service.transport.MessageListener ml)
                           throws TransportFailure
Removes a MessageListener from the MessageReceiver.

Parameters:
ml - the MessageListener to remove from the MessageReceiver.
Throws:
TransportFailure - if any transport related failure occurs.

getNumberOfMessages

public int getNumberOfMessages()
                        throws TransportFailure
The the number returned does not guarantee the actual number of messages available instantaneously.

Returns:
the number of messages destined for the agent.
Throws:
TransportFailure - if any transport related failure occurs.

getMessage

public javax.agent.TransportMessage getMessage()
                                        throws java.lang.InterruptedException,
                                               TransportFailure
A blocking read operation. This method will block awaiting the arrival of a transport message.

Returns:
TransportMessage the message destined for the agent.
Throws:
java.lang.InterruptedException - if the waiting thread is interrupted.
TransportFailure - if any transport related failure occurs.

getMessage

public javax.agent.TransportMessage getMessage(long wait_millis)
                                        throws java.lang.InterruptedException,
                                               TransportFailure
A timed blocking read operation. This method will block for the amount of time (in milliseconds) specified awaiting the arrival of a transport message.

Parameters:
wait_millis - the most the current thread should block for a message.
Returns:
TransportMessage the message destined for the agent, or null if the wait times out.
Throws:
java.lang.InterruptedException - if the waiting thread is interrupted.
TransportFailure - if any transport related failure occurs.

messageAdded

public void messageAdded(Message msg)
Implements the Grid MessageListener interface. It is called by the Grid when a message for this agent is received. Assumes that the incoming message has the Sender field filled in with the sender's AgentRep - if not, it ignores the message.


getAgentRep

public AgentRep getAgentRep()