public class DuplexBrokerFactory extends java.lang.Object implements IDuplexBrokerFactory
// Create Tcp based messaging.
IMessagingSystemFactory aMessagingFactory = new TcpMessagingSystemFactory();
// Create duplex input channel listening to messages.
IDuplexInputChannel anInputChannel = aMessagingFactory.createDuplexInputChannel("tcp://127.0.0.1:7980/");
// Create the factory for the broker.
IDuplexBrokerFactory aBrokerFactory = new DuplexBrokerFactory();
// Create the broker.
IDuplexBroker aBroker = aBrokerFactory.createBroker();
// Attach the Tcp duplex input channel to the broker and start listening.
aBroker.attachDuplexInputChannel(anInputChannel);
// Create Tcp based messaging for the silverlight client.
IMessagingSystemFactory aTcpMessagingFactory = new TcpMessagingSystemFactory();
// Create duplex output channel to send and receive messages.
myOutputChannel = aTcpMessagingFactory.createDuplexOutputChannel("tcp://127.0.0.1:7980/");
// Create the broker client
IDuplexBrokerFactory aDuplexBrokerFactory = new DuplexBrokerFactory();
myBrokerClient = aDuplexBrokerFactory.createBrokerClient();
// Handler to process notification messages.
myBrokerClient.brokerMessageReceived().subscribe(myNotifyMessageReceived);
// Attach the channel to the broker client to be able to send and receive messages.
myBrokerClient.attachDuplexOutputChannel(myOutputChannel);
// Subscribe in broker to receive chat messages.
myBrokerClient.subscribe("MyChatMessageType");
...
// Send message to the broker. The broker will then forward it to all subscribers.
XmlStringSerializer anXmlSerializer = new XmlStringSerializer();
Object aSerializedChatMessage = anXmlSerializer.Serialize(aChatMessage, ChatMessage.class);
myBrokerClient.sendMessage("MyChatMessageType", aSerializedChatMessage);
Constructor and Description |
---|
DuplexBrokerFactory()
Constructs the broker factory with optimized custom serializer.
|
DuplexBrokerFactory(ISerializer serializer)
Constructs the broker factory with specified serializer.
|
Modifier and Type | Method and Description |
---|---|
IDuplexBroker |
createBroker()
Creates the broker.
|
IDuplexBrokerClient |
createBrokerClient()
Creates the broker client.
|
AuthorizeBrokerRequestCallback |
getBrokerRequestAuthorizer()
Gets callback for authorizing request messages received from DuplexBrokerClient.
|
boolean |
getIsPublisherNotified()
Gets the flag whether the publisher which sent a message shall be notified in case it is subscribed to the same message.
|
ISerializer |
getSerializer()
Returns the serializer which is used to serialize/deserialize
BrokerMessate . |
GetSerializerCallback |
getSerializerProvider()
Gets callback for retrieving serializer based on response receiver id.
|
DuplexBrokerFactory |
setBrokerRequestAuthorizer(AuthorizeBrokerRequestCallback authorizeCallaback)
Sets callback for authorizing request messages received from DuplexBrokerClient.
|
DuplexBrokerFactory |
setIsPublisherNotified(boolean isPublisherNotified)
Sets the flag whether the publisher which sent a message shall be notified in case it is subscribed to the same message.
|
DuplexBrokerFactory |
setSerializer(ISerializer serializer)
Sets the serializer to serialize/deserialize
BrokerMessage . |
DuplexBrokerFactory |
setSerializerProvider(GetSerializerCallback serializerProvider)
Sets callback for retrieving serializer based on response receiver id.
|
public DuplexBrokerFactory()
public DuplexBrokerFactory(ISerializer serializer)
serializer
- serializer used by the brokerpublic IDuplexBrokerClient createBrokerClient() throws java.lang.Exception
IDuplexBrokerFactory
createBrokerClient
in interface IDuplexBrokerFactory
java.lang.Exception
public IDuplexBroker createBroker() throws java.lang.Exception
IDuplexBrokerFactory
createBroker
in interface IDuplexBrokerFactory
java.lang.Exception
public DuplexBrokerFactory setSerializer(ISerializer serializer)
BrokerMessage
.
BrokerMessage
is used for the communication with the broker.serializer
- serializerpublic ISerializer getSerializer()
BrokerMessate
.public GetSerializerCallback getSerializerProvider()
public DuplexBrokerFactory setSerializerProvider(GetSerializerCallback serializerProvider)
serializerProvider
- public AuthorizeBrokerRequestCallback getBrokerRequestAuthorizer()
public DuplexBrokerFactory setBrokerRequestAuthorizer(AuthorizeBrokerRequestCallback authorizeCallaback)
authorizeCallaback
- public DuplexBrokerFactory setIsPublisherNotified(boolean isPublisherNotified)
isPublisherNotified
- true if the DuplexBrokerClient which sent the message shall be notified too.public boolean getIsPublisherNotified()