Errai 3.0.1-SNAPSHOT

org.jboss.errai.bus.server
Class ServerMessageBusImpl

java.lang.Object
  extended by org.jboss.errai.bus.server.ServerMessageBusImpl
All Implemented Interfaces:
MessageBus, ServerMessageBus

public class ServerMessageBusImpl
extends Object
implements ServerMessageBus

The ServerMessageBusImpl implements the ServerMessageBus, making it possible for the server to send and receive messages

Author:
Mike Brock

Nested Class Summary
 class ServerMessageBusImpl.RemoteMessageCallback
           
 
Constructor Summary
ServerMessageBusImpl(ErraiService service, ErraiServiceConfigurator config)
          Sets up the ServerMessageBusImpl with the configuration supplied.
 
Method Summary
 void addQueueClosedListener(QueueClosedListener listener)
          Register a QueueClosedListener with the bus.
 void addSubscribeListener(SubscribeListener listener)
          Adds subscription listener
 void addUnsubscribeListener(UnsubscribeListener listener)
          Adds unsubscription listener
 void associateNewQueue(QueueSession oldSession, QueueSession newSession)
           
 void attachMonitor(BusMonitor monitor)
          Attach a monitor to the bus.
 void closeQueue(MessageQueue queue)
          Closes the message queue
 void closeQueue(String sessionId)
          Closes the queue with sessionId
 void configure(ErraiServiceConfigurator config)
          Configures the server message bus with the specified ErraiServiceConfigurator.
 void finishInit()
           
 Message getDeadLetterMessage(String messageId)
           
 Map<QueueSession,MessageQueue> getMessageQueues()
          Gets all the message queues
 MessageQueue getQueue(QueueSession session)
          Gets the queue corresponding to the session id given
 MessageQueue getQueueBySession(String sessionId)
           
 Collection<MessageCallback> getReceivers(String subject)
          Get a collection of all receivers registered for a specificed subject
 ScheduledExecutorService getScheduler()
          Gets the scheduler being used within this message bus for housekeeping and other periodic or deferred tasks.
 QueueSession getSessionBySessionId(String id)
           
 boolean hasRemoteSubscription(String sessionId, String subject)
           
 boolean hasRemoteSubscriptions(String subject)
           
 boolean isSubscribed(String subject)
          Checks if a subscription exists for subject
 void remoteSubscribe(QueueSession sessionContext, MessageQueue queue, String subject)
          Adds a new remote subscription and fires subscription listeners
 void remoteUnsubscribe(QueueSession sessionContext, MessageQueue queue, String subject)
          Unsubscribes a remote subscription and fires the appropriate listeners
 boolean removeDeadLetterMessage(String messageId)
           
 void send(Message message)
          Sends the message
 void send(Message message, boolean fireListeners)
          Parses the message appropriately and enqueues it for delivery
 void sendGlobal(Message message)
          Sends a message globally to all subscriptions containing the same subject as the specified message.
 void stop()
          Stop the MessateBus.
 Subscription subscribe(String subject, MessageCallback receiver)
          Adds a subscription
 Subscription subscribeLocal(String subject, MessageCallback receiver)
          Subscribe a listern locally, but do not advertise or make available the service to remote buses.
 void unsubscribeAll(String subject)
          Unsubscribe all subscriptions attached to subject
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ServerMessageBusImpl

@Inject
public ServerMessageBusImpl(ErraiService service,
                                   ErraiServiceConfigurator config)
Sets up the ServerMessageBusImpl with the configuration supplied. Also, initializes the bus' callback functions, scheduler, and monitor

When deploying services on the server-side, it is possible to obtain references to the ErraiServiceConfigurator by declaring it as injection dependencies

Method Detail

configure

public void configure(ErraiServiceConfigurator config)
Configures the server message bus with the specified ErraiServiceConfigurator. Presently there are no configurable parameters.

Specified by:
configure in interface ServerMessageBus
Parameters:
config - - the configuration to use

sendGlobal

public void sendGlobal(Message message)
Sends a message globally to all subscriptions containing the same subject as the specified message.

Specified by:
sendGlobal in interface MessageBus
Parameters:
message - - The message to be sent.

send

public void send(Message message)
Sends the message

Specified by:
send in interface MessageBus
Parameters:
message - - the message to send

send

public void send(Message message,
                 boolean fireListeners)
Parses the message appropriately and enqueues it for delivery

Specified by:
send in interface MessageBus
Parameters:
message - - the message to be sent
fireListeners - - true if all listeners attached should be notified of delivery

getQueue

public MessageQueue getQueue(QueueSession session)
Gets the queue corresponding to the session id given

Specified by:
getQueue in interface ServerMessageBus
Parameters:
session - - the session id of the queue
Returns:
the message queue

closeQueue

public void closeQueue(String sessionId)
Closes the queue with sessionId

Specified by:
closeQueue in interface ServerMessageBus
Parameters:
sessionId - - the session context of the queue to close

closeQueue

public void closeQueue(MessageQueue queue)
Closes the message queue

Specified by:
closeQueue in interface ServerMessageBus
Parameters:
queue - - the message queue to close

subscribe

public Subscription subscribe(String subject,
                              MessageCallback receiver)
Adds a subscription

Specified by:
subscribe in interface MessageBus
Parameters:
subject - - the subject to subscribe to
receiver - - the callback function called when a message is dispatched

subscribeLocal

public Subscription subscribeLocal(String subject,
                                   MessageCallback receiver)
Description copied from interface: MessageBus
Subscribe a listern locally, but do not advertise or make available the service to remote buses.

Specified by:
subscribeLocal in interface MessageBus

remoteSubscribe

public void remoteSubscribe(QueueSession sessionContext,
                            MessageQueue queue,
                            String subject)
Adds a new remote subscription and fires subscription listeners

Parameters:
sessionContext - - session context of queue
queue - - the message queue
subject - - the subject to subscribe to

remoteUnsubscribe

public void remoteUnsubscribe(QueueSession sessionContext,
                              MessageQueue queue,
                              String subject)
Unsubscribes a remote subscription and fires the appropriate listeners

Parameters:
sessionContext - - session context of queue
queue - - the message queue
subject - - the subject to unsubscribe from

unsubscribeAll

public void unsubscribeAll(String subject)
Unsubscribe all subscriptions attached to subject

Specified by:
unsubscribeAll in interface MessageBus
Parameters:
subject - - the subject to unsubscribe from

isSubscribed

public boolean isSubscribed(String subject)
Checks if a subscription exists for subject

Specified by:
isSubscribed in interface MessageBus
Parameters:
subject - - the subject to search the subscriptions for
Returns:
true if a subscription exists

hasRemoteSubscriptions

public boolean hasRemoteSubscriptions(String subject)
Specified by:
hasRemoteSubscriptions in interface ServerMessageBus

hasRemoteSubscription

public boolean hasRemoteSubscription(String sessionId,
                                     String subject)
Specified by:
hasRemoteSubscription in interface ServerMessageBus

addSubscribeListener

public void addSubscribeListener(SubscribeListener listener)
Adds subscription listener

Specified by:
addSubscribeListener in interface MessageBus
Parameters:
listener - - subscription listener to add

addUnsubscribeListener

public void addUnsubscribeListener(UnsubscribeListener listener)
Adds unsubscription listener

Specified by:
addUnsubscribeListener in interface MessageBus
Parameters:
listener - - adds an unsubscription listener

associateNewQueue

public void associateNewQueue(QueueSession oldSession,
                              QueueSession newSession)
Specified by:
associateNewQueue in interface ServerMessageBus

getQueueBySession

public MessageQueue getQueueBySession(String sessionId)
Specified by:
getQueueBySession in interface ServerMessageBus

getSessionBySessionId

public QueueSession getSessionBySessionId(String id)
Specified by:
getSessionBySessionId in interface ServerMessageBus

getMessageQueues

public Map<QueueSession,MessageQueue> getMessageQueues()
Gets all the message queues

Specified by:
getMessageQueues in interface ServerMessageBus
Returns:
a map of the message queues that exist

getScheduler

public ScheduledExecutorService getScheduler()
Gets the scheduler being used within this message bus for housekeeping and other periodic or deferred tasks.

Specified by:
getScheduler in interface ServerMessageBus
Returns:
the scheduler

addQueueClosedListener

public void addQueueClosedListener(QueueClosedListener listener)
Description copied from interface: ServerMessageBus
Register a QueueClosedListener with the bus.

Specified by:
addQueueClosedListener in interface ServerMessageBus
Parameters:
listener - a instance of the listener

getReceivers

public Collection<MessageCallback> getReceivers(String subject)
Description copied from interface: ServerMessageBus
Get a collection of all receivers registered for a specificed subject

Specified by:
getReceivers in interface ServerMessageBus
Parameters:
subject - The subject.
Returns:

attachMonitor

public void attachMonitor(BusMonitor monitor)
Description copied from interface: MessageBus
Attach a monitor to the bus.

Specified by:
attachMonitor in interface MessageBus

getDeadLetterMessage

public Message getDeadLetterMessage(String messageId)
Specified by:
getDeadLetterMessage in interface ServerMessageBus

removeDeadLetterMessage

public boolean removeDeadLetterMessage(String messageId)
Specified by:
removeDeadLetterMessage in interface ServerMessageBus

stop

public void stop()
Description copied from interface: ServerMessageBus
Stop the MessateBus.

Specified by:
stop in interface ServerMessageBus

finishInit

public void finishInit()

Errai 3.0.1-SNAPSHOT

Copyright © 2013-2014 JBoss, a division of Red Hat. All Rights Reserved.