Package io.ably.lib.realtime
Class Connection
- java.lang.Object
-
- io.ably.lib.util.EventEmitter<ConnectionEvent,ConnectionStateListener>
-
- io.ably.lib.realtime.Connection
-
public class Connection extends EventEmitter<ConnectionEvent,ConnectionStateListener>
Enables the management of a connection to Ably. Extends anEventEmitterobject.Spec: RTN4a, RTN4e, RTN4g
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class io.ably.lib.util.EventEmitter
EventEmitter.Filter
-
-
Field Summary
Fields Modifier and Type Field Description ConnectionManagerconnectionManagerjava.lang.StringidA unique public identifier for this connection, used to identify this member.java.lang.StringkeyA unique private connection key used to recover or resume a connection, assigned by Ably.ErrorInforeasonAnErrorInfoobject describing the last error received if a connection failure occurs.java.lang.StringrecoveryKeyThe recovery key string can be used by another client to recover this connection's state in the recover client options property.longserialThe serial number of the last message to be received on this connection, used automatically by the library when recovering or resuming a connection.ConnectionStatestateThe currentConnectionStateof the connection.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected voidapply(ConnectionStateListener listener, ConnectionEvent event, java.lang.Object... args)voidclose()Causes the connection to close, entering theConnectionState.closingstate.voidconnect()Explicitly calling connect() is unnecessary unless the autoConnect attribute of theClientOptionsobject is false.voidemit(ConnectionState state, ConnectionStateListener.ConnectionStateChange stateChange)Deprecated.voidemitUpdate(ErrorInfo errorInfo)voidon(ConnectionState state, ConnectionStateListener listener)Deprecated.voidonce(ConnectionState state, ConnectionStateListener listener)Deprecated.voidonConnectionStateChange(ConnectionStateListener.ConnectionStateChange stateChange)voidping(CompletionListener listener)When connected, sends a heartbeat ping to the Ably server and executes the callback with any error and the response time in milliseconds when a heartbeat ping request is echoed from the server.
-
-
-
Field Detail
-
state
public ConnectionState state
The currentConnectionStateof the connection.Spec: RTN4d
-
reason
public ErrorInfo reason
AnErrorInfoobject describing the last error received if a connection failure occurs.Spec: RTN14a
-
key
public java.lang.String key
A unique private connection key used to recover or resume a connection, assigned by Ably. When recovering a connection explicitly, the recoveryKey is used in the recover client options as it contains both the key and the last message serial. This private connection key can also be used by other REST clients to publish on behalf of this client. See the publishing over REST on behalf of a realtime client docs for more info.Spec: RTN9
-
recoveryKey
public java.lang.String recoveryKey
The recovery key string can be used by another client to recover this connection's state in the recover client options property. See connection state recover options for more information.Spec: RTN16b, RTN16c
-
id
public java.lang.String id
A unique public identifier for this connection, used to identify this member.Spec: RTN8
-
serial
public long serial
The serial number of the last message to be received on this connection, used automatically by the library when recovering or resuming a connection. When recovering a connection explicitly, the recoveryKey is used in the recover client options as it contains both the key and the last message serial.Spec: RTN10
-
connectionManager
public final ConnectionManager connectionManager
-
-
Method Detail
-
connect
public void connect()
Explicitly calling connect() is unnecessary unless the autoConnect attribute of theClientOptionsobject is false. Unless already connected or connecting, this method causes the connection to open, entering theConnectionState.connectingstate.Spec: RTC1b, RTN3, RTN11
-
ping
public void ping(CompletionListener listener)
When connected, sends a heartbeat ping to the Ably server and executes the callback with any error and the response time in milliseconds when a heartbeat ping request is echoed from the server. This can be useful for measuring true round-trip latency to the connected Ably server.- Parameters:
listener- A listener to be notified of success or failure.Spec: RTN13
-
close
public void close()
Causes the connection to close, entering theConnectionState.closingstate. Once closed, the library does not attempt to re-establish the connection without an explicit call toconnect().Spec: RTN12
-
onConnectionStateChange
public void onConnectionStateChange(ConnectionStateListener.ConnectionStateChange stateChange)
-
apply
protected void apply(ConnectionStateListener listener, ConnectionEvent event, java.lang.Object... args)
- Specified by:
applyin classEventEmitter<ConnectionEvent,ConnectionStateListener>
-
emitUpdate
public void emitUpdate(ErrorInfo errorInfo)
-
emit
@Deprecated public void emit(ConnectionState state, ConnectionStateListener.ConnectionStateChange stateChange)
Deprecated.
-
on
@Deprecated public void on(ConnectionState state, ConnectionStateListener listener)
Deprecated.
-
once
@Deprecated public void once(ConnectionState state, ConnectionStateListener listener)
Deprecated.
-
-