org.robokind.api.messaging
Class DefaultMessageBlockingReceiver<Msg,Rec>

java.lang.Object
  extended by org.robokind.api.messaging.DefaultMessageBlockingReceiver<Msg,Rec>
Type Parameters:
Msg - type of message to return
Rec - type of record to receive
All Implemented Interfaces:
MessageBlockingReceiver<Msg>

public class DefaultMessageBlockingReceiver<Msg,Rec>
extends Object
implements MessageBlockingReceiver<Msg>

Default implementation of the MessageBlockingReceiver. Blocks until a Record is received. Uses an Adapter to adapt Records to Messages and notifies Listeners.

Author:
Matthew Stevenson

Constructor Summary
DefaultMessageBlockingReceiver()
          Creates an empty DefaultMessageBlockingReceiver.
 
Method Summary
 void addMessageListener(Listener<Msg> 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.
protected  void fireMessageEvent(Msg message)
          Notifies listeners of a Message
 void removeMessageListener(Listener<Msg> 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> receiver)
          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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultMessageBlockingReceiver

public DefaultMessageBlockingReceiver()
Creates an empty DefaultMessageBlockingReceiver.

Method Detail

setRecordReceiver

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

Parameters:
service - theRecordReceiver to set

setAdapter

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

Parameters:
adapter - the Adapter to set

start

public void start()
Description copied from interface: MessageBlockingReceiver
Initializes and connects the MessageAsyncReceiver, and begins receiving Messages.

Specified by:
start in interface MessageBlockingReceiver<Msg>

stop

public void stop()
Description copied from interface: MessageBlockingReceiver
Stops the MessageAsyncReceiver, making it unable to receive Messages.

Specified by:
stop in interface MessageBlockingReceiver<Msg>

fetchMessage

public Msg fetchMessage(long timeout)
Description copied from interface: MessageBlockingReceiver
Blocks while waiting for a Message.

Specified by:
fetchMessage in interface MessageBlockingReceiver<Msg>
Parameters:
timeout - timeout length in milliseconds
Returns:
Message received from a MessageSender, null if no Message received before timeout

fireMessageEvent

protected void fireMessageEvent(Msg message)
Notifies listeners of a Message

Parameters:
message -

clearMessages

public int clearMessages()
Description copied from interface: MessageBlockingReceiver
Removes any pending messages for this receiver. Returns the number of messages cleared.

Specified by:
clearMessages in interface MessageBlockingReceiver<Msg>
Returns:
number of messages cleared

addMessageListener

public void addMessageListener(Listener<Msg> listener)
Description copied from interface: MessageBlockingReceiver
Adds a Listener to be notified when a Message has been received.

Specified by:
addMessageListener in interface MessageBlockingReceiver<Msg>
Parameters:
listener - the Listener to be notified

removeMessageListener

public void removeMessageListener(Listener<Msg> listener)
Description copied from interface: MessageBlockingReceiver
Removes a Listener from being notified.

Specified by:
removeMessageListener in interface MessageBlockingReceiver<Msg>
Parameters:
listener - the Listener to remove


Copyright © 2011-2012. All Rights Reserved.