org.robokind.api.messaging
Interface MessageBlockingReceiver<Msg,Rec,L extends Listener<Msg>>

All Known Implementing Classes:
DefaultMessageBlockingReceiver

public interface MessageBlockingReceiver<Msg,Rec,L extends Listener<Msg>>

Author:
Matthew Stevenson

Method Summary
 void addMessageListener(L listener)
          Adds a Listener to be notified when a Message has been received.
 int clearMessages()
          Removes any pending messages for this receiver.
 Msg fetchMessage(long timeout)
          Blocks while waiting for a Message.
 void removeMessageListener(L listener)
          Removes a Listener from being notified.
 void setAdapter(Adapter<Rec,Msg> adapter)
          Sets the Adapter used to convert Records to Messages.
 void setRecordReceiver(RecordBlockingReceiver<Rec> service)
          Sets the RecordAsyncReceiver used to receive Records.
 void start()
          Initializes and connects the MessageAsyncReceiver, and begins receiving Messages.
 void stop()
          Stops the MessageAsyncReceiver, making it unable to receive Messages.
 

Method Detail

setRecordReceiver

void setRecordReceiver(RecordBlockingReceiver<Rec> service)
Sets the RecordAsyncReceiver used to receive Records.

Parameters:
service - theRecordReceiver to set

setAdapter

void setAdapter(Adapter<Rec,Msg> adapter)
Sets the Adapter used to convert Records to Messages.

Parameters:
adapter - the Adapter to set

start

void start()
           throws Exception
Initializes and connects the MessageAsyncReceiver, and begins receiving Messages.

Throws:
Exception - if there is an error starting

stop

void stop()
Stops the MessageAsyncReceiver, making it unable to receive Messages.


fetchMessage

Msg fetchMessage(long timeout)
Blocks while waiting for a Message.

Parameters:
timeout - timeout length in milliseconds
Returns:
Message received from a MessageSender, null if no Message received before timeout

clearMessages

int clearMessages()
Removes any pending messages for this receiver. Returns the number of messages cleared.

Returns:
number of messages cleared

addMessageListener

void addMessageListener(L listener)
Adds a Listener to be notified when a Message has been received.

Parameters:
listener - the Listener to be notified

removeMessageListener

void removeMessageListener(L listener)
Removes a Listener from being notified.

Parameters:
listener - the Listener to remove


Copyright © 2011-2012. All Rights Reserved.