Class ChannelBase
- Direct Known Subclasses:
Channel
Presence
object of a channel.-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
An interface whereby a client maybe notified of message on a channel.Nested classes/interfaces inherited from class io.ably.lib.util.EventEmitter
EventEmitter.Filter
-
Field Summary
Modifier and TypeFieldDescriptionfinal String
The channel name.final Presence
APresence
object.AChannelProperties
object.AnErrorInfo
object describing the last error which occurred on the channel, if any.The currentChannelState
of the channel. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
apply
(ChannelStateListener listener, ChannelEvent event, Object... args) void
attach()
Attach to this channel ensuring the channel is created in the Ably system and all messages published on the channel are received by any channel listeners registered usingsubscribe(io.ably.lib.realtime.ChannelBase.MessageListener)
.void
attach
(CompletionListener listener) Attach to this channel ensuring the channel is created in the Ably system and all messages published on the channel are received by any channel listeners registered usingsubscribe(io.ably.lib.realtime.ChannelBase.MessageListener)
.protected boolean
Checks ifChannelOptions.attachOnSubscribe
is true.void
detach()
Detach from this channel.void
detach
(CompletionListener listener) Detach from this channel.void
emit
(ChannelState state, ChannelStateListener.ChannelStateChange channelStateChange) getModes()
Retrieves aPaginatedResult
object, containing an array of historicalMessage
objects for the channel.void
historyAsync
(Param[] params, Callback<AsyncPaginatedResult<Message>> callback) Asynchronously retrieves aPaginatedResult
object, containing an array of historicalMessage
objects for the channel.void
Mark channel as released that means we can't perform any operation on this channel anymorevoid
on
(ChannelState state, ChannelStateListener listener) void
once
(ChannelState state, ChannelStateListener listener) void
Publishes a message to the channel.void
Publishes an array of messages to the channel.void
publish
(Message[] messages, CompletionListener listener) Publishes an array of messages to the channel.void
publish
(Message message, CompletionListener listener) Publishes a message to the channel.void
Publishes a single message to the channel with the given event name and payload.void
publish
(String name, Object data, CompletionListener listener) Publishes a single message to the channel with the given event name and payload.void
void
setConnectionClosed
(ErrorInfo reason) (RTL3b) If the connection state enters the CLOSED state, then an ATTACHING or ATTACHED channel state will transition to DETACHED.void
setConnectionFailed
(ErrorInfo reason) If the connection state enters the FAILED state, then an ATTACHING or ATTACHED channel state will transition to FAILED and set the Channel#errorReasonvoid
setOptions
(ChannelOptions options) Sets theChannelOptions
for the channel.void
setOptions
(ChannelOptions options, CompletionListener listener) Sets theChannelOptions
for the channel.void
setSuspended
(ErrorInfo reason, boolean notifyStateChange) (RTL3c) If the connection state enters the SUSPENDED state, then an ATTACHING or ATTACHED channel state will transition to SUSPENDED.void
subscribe
(ChannelBase.MessageListener listener) Registers a listener for messages on this channel.void
subscribe
(String[] names, ChannelBase.MessageListener listener) Registers a listener for messages on this channel for multiple event name values.void
subscribe
(String name, ChannelBase.MessageListener listener) Registers a listener for messages with a given event name on this channel.void
sync()
Deprecated.void
Deregisters all listeners to messages on this channel.void
unsubscribe
(ChannelBase.MessageListener listener) Deregisters the given listener (for any/all event names).void
unsubscribe
(String[] names, ChannelBase.MessageListener listener) Deregisters the given listener from all event names in the array.void
unsubscribe
(String name, ChannelBase.MessageListener listener) Deregisters the given listener for the specified event name.
-
Field Details
-
name
The channel name. -
presence
APresence
object.Spec: RTL9
-
state
The currentChannelState
of the channel.Spec: RTL2b
-
reason
AnErrorInfo
object describing the last error which occurred on the channel, if any.Spec: RTL4e
-
properties
AChannelProperties
object.Spec: CP1, RTL15
-
-
Method Details
-
attach
Attach to this channel ensuring the channel is created in the Ably system and all messages published on the channel are received by any channel listeners registered usingsubscribe(io.ably.lib.realtime.ChannelBase.MessageListener)
. Any resulting channel state change will be emitted to any listeners registered using theEventEmitter.on(Listener)
orEventEmitter.once(Listener)
methods. As a convenience, attach() is called implicitly ifsubscribe(io.ably.lib.realtime.ChannelBase.MessageListener)
for the channel is called, orPresence.enter(java.lang.Object, io.ably.lib.realtime.CompletionListener)
orPresence.subscribe(io.ably.lib.realtime.Presence.PresenceListener, io.ably.lib.realtime.CompletionListener)
are called on thePresence
object for this channel.Spec: RTL4d
- Throws:
AblyException
-
attach
Attach to this channel ensuring the channel is created in the Ably system and all messages published on the channel are received by any channel listeners registered usingsubscribe(io.ably.lib.realtime.ChannelBase.MessageListener)
. Any resulting channel state change will be emitted to any listeners registered using theEventEmitter.on(Listener)
orEventEmitter.once(Listener)
methods. As a convenience, attach() is called implicitly ifsubscribe(io.ably.lib.realtime.ChannelBase.MessageListener)
for the channel is called, orPresence.enter(java.lang.Object, io.ably.lib.realtime.CompletionListener)
orPresence.subscribe(io.ably.lib.realtime.Presence.PresenceListener, io.ably.lib.realtime.CompletionListener)
are called on thePresence
object for this channel.Spec: RTL4d
- Parameters:
-
listener
- A callback may optionally be passed in to this call to be notified of success or failure of the operation.This listener is invoked on a background thread.
- Throws:
AblyException
-
detach
Detach from this channel. Any resulting channel state change is emitted to any listeners registered using theEventEmitter.on(Listener)
orEventEmitter.once(Listener)
methods. Once all clients globally have detached from the channel, the channel will be released in the Ably service within two minutes.Spec: RTL5e
- Throws:
AblyException
-
markAsReleased
public void markAsReleased()Mark channel as released that means we can't perform any operation on this channel anymore -
detach
Detach from this channel. Any resulting channel state change is emitted to any listeners registered using theEventEmitter.on(Listener)
orEventEmitter.once(Listener)
methods. Once all clients globally have detached from the channel, the channel will be released in the Ably service within two minutes.Spec: RTL5e
- Parameters:
-
listener
- A callback may optionally be passed in to this call to be notified of success or failure of the operation.This listener is invoked on a background thread.
- Throws:
AblyException
-
sync
Deprecated.- Throws:
AblyException
-
setConnected
public void setConnected() -
setConnectionFailed
If the connection state enters the FAILED state, then an ATTACHING or ATTACHED channel state will transition to FAILED and set the Channel#errorReason -
setConnectionClosed
(RTL3b) If the connection state enters the CLOSED state, then an ATTACHING or ATTACHED channel state will transition to DETACHED. -
setSuspended
(RTL3c) If the connection state enters the SUSPENDED state, then an ATTACHING or ATTACHED channel state will transition to SUSPENDED. (RTN15c3) The client library should initiate an attach for channels that are in the SUSPENDED state. For all channels in the ATTACHING or ATTACHED state, the client library should fail any previously queued messages for that channel and initiate a new attach. This also gets called when a connection enters CONNECTED but with a non-fatal error for a failed reconnect (RTN16e). -
apply
- Specified by:
-
apply
in classEventEmitter<ChannelEvent,
ChannelStateListener>
-
unsubscribe
public void unsubscribe()Deregisters all listeners to messages on this channel. This removes all earlier subscriptions.Spec: RTL8a, RTE5
-
attachOnSubscribeEnabled
protected boolean attachOnSubscribeEnabled()Checks if
Defaults toChannelOptions.attachOnSubscribe
is true.true
whenoptions
is null.Spec: TB4, RTL7g, RTL7h, RTP6d, RTP6e
-
subscribe
Registers a listener for messages on this channel. The caller supplies a listener function, which is called each time one or more messages arrives on the channel.Spec: RTL7a
- Parameters:
-
listener
- A listener may optionally be passed in to this call to be notified of success or failure of the channelattach()
operation.This listener is invoked on a background thread.
- Throws:
AblyException
-
unsubscribe
Deregisters the given listener (for any/all event names). This removes an earlier subscription.Spec: RTL8a
- Parameters:
-
listener
- An event listener function.This listener is invoked on a background thread.
-
subscribe
Registers a listener for messages with a given event name on this channel. The caller supplies a listener function, which is called each time one or more matching messages arrives on the channel.Spec: RTL7b
- Parameters:
-
name
- The event name. -
listener
- A listener may optionally be passed in to this call to be notified of success or failure of the channelattach()
operation.This listener is invoked on a background thread.
- Throws:
AblyException
-
unsubscribe
Deregisters the given listener for the specified event name. This removes an earlier event-specific subscriptionSpec: RTL8a
- Parameters:
-
name
- The event name. -
listener
- An event listener function.This listener is invoked on a background thread.
-
subscribe
Registers a listener for messages on this channel for multiple event name values. The caller supplies a listener function, which is called each time one or more matching messages arrives on the channel.Spec: RTL7a
- Parameters:
-
names
- An array of event names. -
listener
- A listener may optionally be passed in to this call to be notified of success or failure of the channelattach()
operation.This listener is invoked on a background thread.
- Throws:
AblyException
-
unsubscribe
Deregisters the given listener from all event names in the array.Spec: RTL8a
- Parameters:
-
names
- An array of event names. -
listener
- An event listener function.This listener is invoked on a background thread.
-
publish
Publishes a single message to the channel with the given event name and payload. When publish is called with this client library, it won't attempt to implicitly attach to the channel, so long as transient publishing is available in the library. Otherwise, the client will implicitly attach.Spec: RTL6i
- Parameters:
-
name
- the event name -
data
- the message payload - Throws:
AblyException
-
publish
Publishes a message to the channel. When publish is called with this client library, it won't attempt to implicitly attach to the channel.Spec: RTL6i
- Parameters:
-
message
- AMessage
object. - Throws:
AblyException
-
publish
Publishes an array of messages to the channel. When publish is called with this client library, it won't attempt to implicitly attach to the channel.Spec: RTL6i
- Parameters:
-
messages
- An array ofMessage
objects. - Throws:
AblyException
-
publish
Publishes a single message to the channel with the given event name and payload. When publish is called with this client library, it won't attempt to implicitly attach to the channel, so long as transient publishing is available in the library. Otherwise, the client will implicitly attach.Spec: RTL6i
- Parameters:
-
name
- the event name -
data
- the message payload -
listener
- A listener may optionally be passed in to this call to be notified of success or failure of the operation.This listener is invoked on a background thread.
- Throws:
AblyException
-
publish
Publishes a message to the channel. When publish is called with this client library, it won't attempt to implicitly attach to the channel.Spec: RTL6i
- Parameters:
-
message
- AMessage
object. -
listener
- A listener may optionally be passed in to this call to be notified of success or failure of the operation.This listener is invoked on a background thread.
- Throws:
AblyException
-
publish
Publishes an array of messages to the channel. When publish is called with this client library, it won't attempt to implicitly attach to the channel.Spec: RTL6i
- Parameters:
-
messages
- An array ofMessage
objects. -
listener
- A listener may optionally be passed in to this call to be notified of success or failure of the operation.This listener is invoked on a background thread.
- Throws:
AblyException
-
history
Retrieves aPaginatedResult
object, containing an array of historicalMessage
objects for the channel. If the channel is configured to persist messages, then messages can be retrieved from history for up to 72 hours in the past. If not, messages can only be retrieved from history for up to two minutes in the past.Spec: RSL2a
- Parameters:
-
params
- the request params:start (RTL10a) - The time from which messages are retrieved, specified as milliseconds since the Unix epoch.
end (RTL10a) - The time until messages are retrieved, specified as milliseconds since the Unix epoch.
direction (RTL10a) - The order for which messages are returned in. Valid values are backwards which orders messages from most recent to oldest, or forwards which orders messages from oldest to most recent. The default is backwards.
limit (RTL10a) - An upper limit on the number of messages returned. The default is 100, and the maximum is 1000.
untilAttach (RTL10b) - When true, ensures message history is up until the point of the channel being attached. See continuous history for more info. Requires the direction to be backwards. If the channel is not attached, or if direction is set to forwards, this option results in an error.
- Returns:
- A
PaginatedResult
object containing an array ofMessage
objects. - Throws:
AblyException
-
historyAsync
Asynchronously retrieves aPaginatedResult
object, containing an array of historicalMessage
objects for the channel. If the channel is configured to persist messages, then messages can be retrieved from history for up to 72 hours in the past. If not, messages can only be retrieved from history for up to two minutes in the past.Spec: RSL2a
- Parameters:
-
params
- the request params:start (RTL10a) - The time from which messages are retrieved, specified as milliseconds since the Unix epoch.
end (RTL10a) - The time until messages are retrieved, specified as milliseconds since the Unix epoch.
direction (RTL10a) - The order for which messages are returned in. Valid values are backwards which orders messages from most recent to oldest, or forwards which orders messages from oldest to most recent. The default is backwards.
limit (RTL10a) - An upper limit on the number of messages returned. The default is 100, and the maximum is 1000.
untilAttach (RTL10b) - When true, ensures message history is up until the point of the channel being attached. See continuous history for more info. Requires the direction to be backwards. If the channel is not attached, or if direction is set to forwards, this option results in an error.
-
callback
- Callback withAsyncPaginatedResult
object containing an array ofMessage
objects. - Throws:
AblyException
-
setOptions
Sets theChannelOptions
for the channel.Spec: RTL16
- Parameters:
-
options
- AChannelOptions
object. - Throws:
AblyException
-
setOptions
Sets theChannelOptions
for the channel.Spec: RTL16
- Parameters:
-
options
- AChannelOptions
object. -
listener
- An optional listener may be provided to notify of the success or failure of the operation. - Throws:
AblyException
-
getParams
-
getModes
-
emit
-
on
-
once
-