public interface BusLifecycleListener
ClientMessageBus
has three conceptual states in its
lifecycle: local only, connecting, and connected. This
interface allows Errai applications to observe lifecycle state transitions in
the bus.
The bus lifecycle is as follows. Every time the bus transitions from one
state to another, the correspondingly named event is delivered to all
listeners:
The bus begins in the local only state, and automatically transitions to the connecting state unless configured not to. Therefore, unless remote communication is disabled by static global configuration, application code will first observe the bus in its connecting state. In the connecting state, the bus "wants" to be connected to the server, and it actively tries to establish a connection, reconnecting after communication disruptions as necessary. When in the connecting state, the bus will make a configurable number of attempts to reach the connected state. After this many retries, the bus will give up and fall back to the local only state.
Once the bus has established a connection with the server and exchanged the list of available topics with the server bus, the bus is in the connected state, and bidirectional communication between client and server is possible.
If there is a communication error when the bus is in the connected state, the bus falls back to the connecting state, where it attempts to reconnect to the server.
If you call {ClientMessageBus#stop()} or {ClientMessageBus#init()} from within one of these callback methods, be aware that this can cause another lifecycle event to be delivered before the current event has finished being delivered. This is especially important to avoid if your application employs more than one BusLifecycleListener, because some of these listeners will receive events out of order. An easy workaround for this problem is to wrap your bus.init() or bus.stop() call in a Timer with a delay of 1ms.
Modifier and Type | Method and Description |
---|---|
void |
busAssociating(BusLifecycleEvent e)
Indicates that the bus is about to transition from the local only to
the connecting state.
|
void |
busDisassociating(BusLifecycleEvent e)
Indicates that the bus is about to transition from the connecting to
the local only state.
|
void |
busOffline(BusLifecycleEvent e)
Indicates that the bus has just transitioned from the connected to
the connecting state.
|
void |
busOnline(BusLifecycleEvent e)
Indicates that the bus has just transitioned from the connecting to
the connected state.
|
void busAssociating(BusLifecycleEvent e)
e
- the object describing the event (includes a reference to the bus
that fired the event).void busDisassociating(BusLifecycleEvent e)
When you want to try to connect to the server again (for example, to fail
over to another server, after a set timeout has elapsed, or in response to
the user clicking a "Reconnect" button in the user interface), call
ClientMessageBusImpl.init()
. This will transition the bus back to
the connecting state.
e
- the object describing the event (includes a reference to the bus
that fired the event).void busOnline(BusLifecycleEvent e)
e
- the object describing the event (includes a reference to the bus
that fired the event).void busOffline(BusLifecycleEvent e)
busOnline(BusLifecycleEvent)
event.
If the bus gives up trying to reconnect, you will receive a
busDisassociating(BusLifecycleEvent)
event.
At the time when this event is delivered, messages intended for the remote bus will be enqueued for delivery when (and if) the bus goes back online.
e
- the object describing the event (includes a reference to the bus
that fired the event).Copyright © 2013-2015 JBoss, a division of Red Hat. All Rights Reserved.