Errai 3.0.1-SNAPSHOT

org.jboss.errai.bus.client.framework
Class ClientMessageBusImpl

java.lang.Object
  extended by org.jboss.errai.bus.client.framework.ClientMessageBusImpl
All Implemented Interfaces:
ClientMessageBus, MessageBus
Direct Known Subclasses:
LocationAwareClientMessageBus

public class ClientMessageBusImpl
extends Object
implements ClientMessageBus

The default client MessageBus implementation. This bus runs in the browser and automatically federates with the server immediately upon initialization.

Author:
Mike Brock

Field Summary
 MessageCallback serverForwarder
          Forwards every message received across the communication link to the remote server bus.
 
Constructor Summary
ClientMessageBusImpl()
           
 
Method Summary
 void addLifecycleListener(BusLifecycleListener l)
          Adds the given listener instance to this bus.
 void addSubscribeListener(SubscribeListener listener)
          Adds a subscription listener, so it is possible to add subscriptions to the client.
 void addTransportErrorHandler(TransportErrorHandler errorHandler)
          Adds a global transport error handler to deal with any errors which arise from communication between the bus and the server.
 void addUncaughtExceptionHandler(com.google.gwt.core.client.GWT.UncaughtExceptionHandler handler)
           
 void addUnsubscribeListener(UnsubscribeListener listener)
          Adds an unsubscribe listener, so it is possible for applications to remove subscriptions from the client
 void attachMonitor(BusMonitor monitor)
          Attach a monitor to the bus.
 boolean callErrorHandler(Message message, Throwable t)
           
 void clearProperties()
           
 void encodeAndTransmit(Message message)
           
 Collection<TransportHandler> getAllAvailableHandlers()
           
 Set<String> getAllRegisteredSubjects()
          Returns a set of all reject subjects in the bus.
 String getApplicationLocation(String serviceEntryPoint)
           
 String getClientId()
           
 String getInServiceEntryPoint()
           
 Set<String> getLocalServices()
           
 String getOutServiceEntryPoint()
           
 Set<String> getRemoteServices()
           
 String getSessionId()
           
 BusState getState()
           
 TransportHandler getTransportHandler()
           
 boolean handleTransportError(BusTransportError transportError)
           
 void init()
          Takes this message bus from the LOCAL_ONLY state into the CONNECTING state, as long as remote communication is enabled.
 boolean isSubscribed(String subject)
          Checks if subject is already listed in the subscriptions map
 void reconsiderTransport()
          When called, the MessageBus assumes that the currently active transport is no longer capable of operating.
 void removeAllUncaughtExceptionHandlers()
           
 void removeLifecycleListener(BusLifecycleListener l)
          Removes the given listener from this bus.
 void removeTransportErrorHandler(TransportErrorHandler errorHandler)
          Removes the given global transport error handler from this bus.
 void removeUncaughtExceptionHandler(com.google.gwt.core.client.GWT.UncaughtExceptionHandler handler)
           
 void send(Message message)
          Sends the message using it's encoded subject.
 void send(Message message, boolean fireListeners)
          Sends the specified message, and notifies the listeners.
 void sendGlobal(Message message)
          Globally send message to all receivers.
 void sendLocal(Message msg)
          Delivers the given message to all local callbacks that subscribe to its subject.
 void setProperty(String name, String value)
          Sets a property on the bus.
 void setState(BusState newState)
          Puts the bus in the given state, firing all necessary transition events with no reason field.
 void stop(boolean sendDisconnect)
          Takes this bus into the "local only" state.
 Subscription subscribe(String subject, MessageCallback callback)
          Add a subscription for the specified subject
 Subscription subscribeLocal(String subject, MessageCallback callback)
          Subscribe a listern locally, but do not advertise or make available the service to remote buses.
 Subscription subscribeShadow(String subject, MessageCallback callback)
          Declares a new shadow subscription.
 void unsubscribeAll(String subject)
          Removes all subscriptions attached to the specified subject
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serverForwarder

public final MessageCallback serverForwarder
Forwards every message received across the communication link to the remote server bus. This is the mechanism by which local messages are routed to the server bus.

One instance of this callback can be subscribed to any number of subjects simultaneously.

Constructor Detail

ClientMessageBusImpl

public ClientMessageBusImpl()
Method Detail

init

public void init()
Takes this message bus from the LOCAL_ONLY state into the CONNECTING state, as long as remote communication is enabled.

If this bus is not in the LOCAL_ONLY state when this method is called, this method has no effect.

Specified by:
init in interface ClientMessageBus
See Also:
BusToolsCli.isRemoteCommunicationEnabled(), BusLifecycleListener

stop

public void stop(boolean sendDisconnect)
Description copied from interface: ClientMessageBus
Takes this bus into the "local only" state.

Specified by:
stop in interface ClientMessageBus
Parameters:
sendDisconnect - if true, the server will be notified that we are breaking the connection. Else, no attempt will be made to notify the server.

getClientId

public String getClientId()

getSessionId

public String getSessionId()

unsubscribeAll

public void unsubscribeAll(String subject)
Removes all subscriptions attached to the specified subject

Specified by:
unsubscribeAll in interface MessageBus
Parameters:
subject - - the subject to have all it's subscriptions removed

subscribe

public Subscription subscribe(String subject,
                              MessageCallback callback)
Add a subscription for the specified subject

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

subscribeLocal

public Subscription subscribeLocal(String subject,
                                   MessageCallback callback)
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

subscribeShadow

public Subscription subscribeShadow(String subject,
                                    MessageCallback callback)
Description copied from interface: ClientMessageBus
Declares a new shadow subscription. Shadow subscriptions are specialized services that are responsible for handling the request of remote services when the bus is in a disconnected state.

When a message is sent by an application component to a remote service while the bus is physically disconnected from the server, the bus will consider shadow subscriptions with a matching subject name to deliver the message to.

Shadow subscriptions are considered routable in all bus states except CONNECTING.

Specified by:
subscribeShadow in interface ClientMessageBus
Parameters:
subject - the subject name.
Returns:

sendGlobal

public void sendGlobal(Message message)
Globally send message to all receivers.

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

send

public void send(Message message,
                 boolean fireListeners)
Sends the specified message, and notifies the listeners.

Specified by:
send in interface MessageBus
Parameters:
message - - the message to be sent
fireListeners - - true if the appropriate listeners should be fired

send

public void send(Message message)
Sends the message using it's encoded subject. If the bus has not been initialized, it will be added to postInitTasks.

Specified by:
send in interface MessageBus
Parameters:
message - -
Throws:
RuntimeException - - if message does not contain a ToSubject field or if the message's callback throws an error.

sendLocal

public void sendLocal(Message msg)
Description copied from interface: ClientMessageBus
Delivers the given message to all local callbacks that subscribe to its subject. Does not transmit the message to other buses.

Specified by:
sendLocal in interface ClientMessageBus
Parameters:
msg - The message to deliver to local subscribers.

callErrorHandler

public boolean callErrorHandler(Message message,
                                Throwable t)

encodeAndTransmit

public void encodeAndTransmit(Message message)

isSubscribed

public boolean isSubscribed(String subject)
Checks if subject is already listed in the subscriptions map

Specified by:
isSubscribed in interface MessageBus
Parameters:
subject - subject to look for
Returns:
true if the subject is already subscribed

handleTransportError

public boolean handleTransportError(BusTransportError transportError)

addSubscribeListener

public void addSubscribeListener(SubscribeListener listener)
Adds a subscription listener, so it is possible to add subscriptions to the client.

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

addUnsubscribeListener

public void addUnsubscribeListener(UnsubscribeListener listener)
Adds an unsubscribe listener, so it is possible for applications to remove subscriptions from the client

Specified by:
addUnsubscribeListener in interface MessageBus
Parameters:
listener - - unsubscribe listener

reconsiderTransport

public void reconsiderTransport()
When called, the MessageBus assumes that the currently active transport is no longer capable of operating. The MessageBus then find the best remaining handler and activates it.


attachMonitor

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

Specified by:
attachMonitor in interface MessageBus

getAllRegisteredSubjects

public Set<String> getAllRegisteredSubjects()
Description copied from interface: ClientMessageBus
Returns a set of all reject subjects in the bus.

Specified by:
getAllRegisteredSubjects in interface ClientMessageBus
Returns:
a set of all registered subjects.

addTransportErrorHandler

public void addTransportErrorHandler(TransportErrorHandler errorHandler)
Description copied from interface: ClientMessageBus
Adds a global transport error handler to deal with any errors which arise from communication between the bus and the server.

Specified by:
addTransportErrorHandler in interface ClientMessageBus
Parameters:
errorHandler - the error handler to add.

removeTransportErrorHandler

public void removeTransportErrorHandler(TransportErrorHandler errorHandler)
Description copied from interface: ClientMessageBus
Removes the given global transport error handler from this bus. Once removed, the given handler does not receive transport error notifications anymore.

Specified by:
removeTransportErrorHandler in interface ClientMessageBus
Parameters:
errorHandler - the error handler to remove. This method has no effect if the given handler is null or it was not already registered.

getState

public BusState getState()

getRemoteServices

public Set<String> getRemoteServices()

getLocalServices

public Set<String> getLocalServices()

getApplicationLocation

public String getApplicationLocation(String serviceEntryPoint)

getOutServiceEntryPoint

public String getOutServiceEntryPoint()

getInServiceEntryPoint

public String getInServiceEntryPoint()

addLifecycleListener

public void addLifecycleListener(BusLifecycleListener l)
Description copied from interface: ClientMessageBus
Adds the given listener instance to this bus. The listener will be notified each time the bus transitions to a different lifecycle state.

Specified by:
addLifecycleListener in interface ClientMessageBus
Parameters:
l - The listener that wants to receive lifecycle notifications. Must not be null. If the same listener is added more than once, it will receive the corresponding number of callbacks upon each lifecycle event.

removeLifecycleListener

public void removeLifecycleListener(BusLifecycleListener l)
Description copied from interface: ClientMessageBus
Removes the given listener from this bus. The listener will no longer receive lifecycle events from this bus.

Specified by:
removeLifecycleListener in interface ClientMessageBus
Parameters:
l - The listener to remove. If the listener was added more than one time, removing it will decrease by one the number of notifications that listener receices for each event. If the listener was not already registered to receive events, this method has no effect.

getTransportHandler

public TransportHandler getTransportHandler()

getAllAvailableHandlers

public Collection<TransportHandler> getAllAvailableHandlers()

setProperty

public void setProperty(String name,
                        String value)
Description copied from interface: ClientMessageBus
Sets a property on the bus.

Specified by:
setProperty in interface ClientMessageBus
Parameters:
name - the property name
value - the property value

clearProperties

public void clearProperties()
Specified by:
clearProperties in interface ClientMessageBus

setState

public void setState(BusState newState)
Puts the bus in the given state, firing all necessary transition events with no reason field.


addUncaughtExceptionHandler

public void addUncaughtExceptionHandler(com.google.gwt.core.client.GWT.UncaughtExceptionHandler handler)

removeUncaughtExceptionHandler

public void removeUncaughtExceptionHandler(com.google.gwt.core.client.GWT.UncaughtExceptionHandler handler)

removeAllUncaughtExceptionHandlers

public void removeAllUncaughtExceptionHandlers()

Errai 3.0.1-SNAPSHOT

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