public interface Transport
Note: There is only one set of transport events available for the client. Setting a new set of transport state listeners will clear the previously set listeners.
Modifier and Type | Interface and Description |
---|---|
static interface |
Transport.TransportEvents |
Modifier and Type | Method and Description |
---|---|
default void |
events(Consumer<Transport.TransportEvents> events)
This method allows to atomically set a state listener using simple runnable.
|
void |
state(Consumer<Boolean> stateChange)
Set a state listener
|
static void |
waitForConnection(Transport transport)
Wait for the connection to be established
|
void state(Consumer<Boolean> stateChange)
The listener will be called immediately after setting with the last known state.
stateChange
- the listener to transport state changesdefault void events(Consumer<Transport.TransportEvents> events)
This method is intended to be used with Java lambdas where each state change (connected, disconnected) is mapped to one lambda. However, as the state change will be initially reported it might happen that the state actually changes between setting the connect and disconnect handler. This way there would be no way to properly report the initial state.
Setting the event handlers using this methods works by updating
the provided Transport.TransportEvents
fields inside the provided consumer. The
consumer will only be called once inside this method. The event listeners will
then be set atomically.
client.transport().events( events->
{ events.connected ( ()->
System.out.println ("Connected") ); events.disconnected ( ()->
System.out.println ("Disconnected") ); });
events
- code to update the Transport.TransportEvents
static void waitForConnection(Transport transport) throws InterruptedException
Note: This method will reset the transport listeners.
transport
- to wait onInterruptedException
- if the wait got interruptedCopyright © 2017. All rights reserved.