|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface IMultiTypedMessageReceiver
Receiver for multiple message types.
It is a service component which can receive and send messages of multiple types.
The following example shows how to create a service which can receive messages of various types:
// Create multityped receiver
IMultiTypedMessagesFactory aFactory = new MultiTypedMessagesFactory();
IMultiTypedMessageReceiver aReceiver = aFactory.createMultiTypedMessageReceiver();
// Register handlers for message types which can be received.
aReceiver.registerRequestMessageReceiver(myAlarmHandler, Alarm.class);
aReceiver.registerRequestMessageReceiver(myImageHandler, Image.class);
// Attach input channel and start listening. E.g. using TCP.
IMessagingSystemFactory aMessaging = new TcpMessagingSystemFactory();
IDuplexInputChannel anInputChannel = aMessaging.createDuplexInputChannel("tcp://127.0.0.1:9043/");
aReceiver.attachDuplexInputChannel(anInputChannel);
System.out.println("Service is running. Press ENTER to stop.");
new BufferedReader(new InputStreamReader(System.in)).readLine();
// Detach input channel and stop listening.
aReceiver.detachInputChannel();
The following code demonstrates how to implement handlers:
private void onAlarmMessage(object sender, TypedRequestReceivedEventArgs<Alarm> e)
{
// Get alarm message data.
Alarm anAlarm = e.getRequestMessage();
....
// Send response message.
aReceiver.sendResponseMessage(e.getResponseReceiverId(), aResponseMessage, ResponseMessage.class);
}
private void onImageMessage(object sender, TypedRequestReceivedEventArgs<Image> e)
{
// Get image message data.
Image anImage = e.getRequestMessage();
....
// Send response message.
aReceiver.sendResponseMessage(e.getResponseReceiverId(), aResponseMessage, ResponseMessage.class);
}
private EventHandler<TypedRequestReceivedEventArgs<Alarm>> myAlarmHandler =
new EventHandler<TypedRequestReceivedEventArgs<Alarm>>()
{
public void onEvent(Object sender, TypedRequestReceivedEventArgs<Alarm> e)
{
onAlarmMessage(sender, e);
}
};
private EventHandler<TypedRequestReceivedEventArgs<Image>> myImageHandler =
new EventHandler<TypedRequestReceivedEventArgs<Image>>()
{
public void onEvent(Object sender, TypedRequestReceivedEventArgs<Image> e)
{
onImageMessage(sender, e);
}
};
Method Summary | ||
---|---|---|
java.util.ArrayList<java.lang.Class<?>> |
getRegisteredRequestMessageTypes()
Returns the list of registered message types which can be received. |
|
|
registerRequestMessageReceiver(EventHandler<TypedRequestReceivedEventArgs<T>> handler,
java.lang.Class<T> clazz)
Registers message handler for specified message type. |
|
Event<ResponseReceiverEventArgs> |
responseReceiverConnected()
Raised when a new client is connected. |
|
Event<ResponseReceiverEventArgs> |
responseReceiverDisconnected()
Raised when a client closed the connection. |
|
|
sendResponseMessage(java.lang.String responseReceiverId,
TResponseMessage responseMessage,
java.lang.Class<TResponseMessage> clazz)
Sends the response message. |
|
|
unregisterRequestMessageReceiver(java.lang.Class<T> clazz)
Unregisters the message handler for the specified message type. |
Methods inherited from interface eneter.messaging.infrastructure.attachable.IAttachableDuplexInputChannel |
---|
attachDuplexInputChannel, detachDuplexInputChannel, getAttachedDuplexInputChannel, isDuplexInputChannelAttached |
Method Detail |
---|
Event<ResponseReceiverEventArgs> responseReceiverConnected()
Event<ResponseReceiverEventArgs> responseReceiverDisconnected()
<T> void registerRequestMessageReceiver(EventHandler<TypedRequestReceivedEventArgs<T>> handler, java.lang.Class<T> clazz) throws java.lang.Exception
handler
- message handler which shall be called when the specified message type is received.clazz
- type of the message.
java.lang.Exception
<T> void unregisterRequestMessageReceiver(java.lang.Class<T> clazz)
clazz
- type of the message.java.util.ArrayList<java.lang.Class<?>> getRegisteredRequestMessageTypes()
<TResponseMessage> void sendResponseMessage(java.lang.String responseReceiverId, TResponseMessage responseMessage, java.lang.Class<TResponseMessage> clazz) throws java.lang.Exception
responseReceiverId
- identifies the client. If responseReceiverId is * then the broadcast message
to all connected clients is sent.
// Send broadcast to all connected clients. aReceiver.sendResponseMessage("*", aBroadcastMessage, YourBroadcast.class);
responseMessage
- response messageclazz
- type of the response message
java.lang.Exception
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |