kaos.core.service.transport.tcp
Class TCPMessageReceiver

java.lang.Object
  extended by kaos.core.service.transport.tcp.TCPMessageReceiver
All Implemented Interfaces:
java.io.Serializable

public class TCPMessageReceiver
extends java.lang.Object
implements java.io.Serializable

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.

Since:
1.0
See Also:
MessageTransportService, TransportSystem, Serialized Form

Constructor Summary
TCPMessageReceiver()
          Testing constructor
TCPMessageReceiver(MessageTransportService transportService)
          Normal constructor
 
Method Summary
 void acceptMessage(byte[] msg)
           
 void addMessageListener(MessageListener ml)
          Adds a MessageListener to the MessageReceiver for asynchronous message delivery.
 void bindToLocalLocator(Locator loc)
          The method which binds the MessageReceiver to a local locator.
 Locator getLocalLocator()
          Returns a local locator depending upon binding status.
 TransportMessage getMessage()
          A blocking read operation.
 TransportMessage getMessage(long wait_millis)
          A timed blocking read operation.
 MessageTransportService getMessageTransportService()
           
 int getNumberOfMessages()
          The number returned does not guarantee the actual number of messages available instantaneously.
static void main(java.lang.String[] args)
           
 void removeMessageListener(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
 

Constructor Detail

TCPMessageReceiver

public TCPMessageReceiver(MessageTransportService transportService)
Normal constructor


TCPMessageReceiver

public TCPMessageReceiver()
Testing constructor

Method Detail

getMessageTransportService

public MessageTransportService getMessageTransportService()
                                                   throws TransportFailure
Throws:
TransportFailure

bindToLocalLocator

public void bindToLocalLocator(Locator loc)
                        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 newly created and returned. This locator has the same host name, port number as that of this Receiver's transport service; but it has no name. Using it as it is will result in failure. If the receiver is bound, the locator used for binding is returned.

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

getNumberOfMessages

public int getNumberOfMessages()
                        throws TransportFailure
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 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 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.

addMessageListener

public void addMessageListener(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(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.

acceptMessage

public void acceptMessage(byte[] msg)

main

public static void main(java.lang.String[] args)