kaos.core.service.transport.corba
Class CorbaMessageReceiver

java.lang.Object
  extended by org.omg.PortableServer.Servant
      extended by kaos.core.service.transport.corba.CorbaReceiverPOA
          extended by kaos.core.service.transport.corba.CorbaMessageReceiver
All Implemented Interfaces:
java.io.Serializable, CorbaReceiverOperations, org.omg.CORBA.portable.InvokeHandler

public class CorbaMessageReceiver
extends CorbaReceiverPOA
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
CorbaMessageReceiver(MessageTransportService ts)
           
 
Method Summary
 void acceptMessage(byte[] msg)
          Implements the CorbaReceiver interface function.
 void addMessageListener(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.
 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.
 void removeMessageListener(MessageListener ml)
          Removes a MessageListener from the MessageReceiver.
 
Methods inherited from class kaos.core.service.transport.corba.CorbaReceiverPOA
_all_interfaces, _invoke, _this, _this
 
Methods inherited from class org.omg.PortableServer.Servant
_default_POA, _get_delegate, _get_interface_def, _is_a, _non_existent, _object_id, _orb, _poa, _set_delegate, _this_object, _this_object
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CorbaMessageReceiver

public CorbaMessageReceiver(MessageTransportService ts)
Method Detail

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 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.

getMessageTransportService

public MessageTransportService getMessageTransportService()
                                                   throws TransportFailure
Throws:
TransportFailure

acceptMessage

public void acceptMessage(byte[] msg)
Implements the CorbaReceiver interface function. This is the function that a remote Corba object calls when it has to send this Receiver a message.

Specified by:
acceptMessage in interface CorbaReceiverOperations
Parameters:
msg - the byte array that the remote object needs to send.

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.