public abstract class ChannelBase extends EventEmitter<ChannelEvent,ChannelStateListener>
Presence object of a channel.| Modifier and Type | Class and Description |
|---|---|
static interface |
ChannelBase.MessageListener
An interface whereby a client maybe notified of message on a channel.
|
EventEmitter.Filter| Modifier and Type | Field and Description |
|---|---|
java.lang.String |
name
The channel name.
|
Presence |
presence
A
Presence object. |
ChannelProperties |
properties
A
ChannelProperties object. |
ErrorInfo |
reason
An
ErrorInfo object describing the last error which occurred on the channel, if any. |
ChannelState |
state
The current
ChannelState of the channel. |
| Modifier and Type | Method and Description |
|---|---|
protected void |
apply(ChannelStateListener listener,
ChannelEvent event,
java.lang.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 using
subscribe(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 using
subscribe(io.ably.lib.realtime.ChannelBase.MessageListener). |
void |
detach()
Detach from this channel.
|
void |
detach(CompletionListener listener)
Detach from this channel.
|
void |
emit(ChannelState state,
ChannelStateListener.ChannelStateChange channelStateChange) |
ChannelMode[] |
getModes() |
java.util.Map<java.lang.String,java.lang.String> |
getParams() |
PaginatedResult<Message> |
history(Param[] params)
Retrieves a
PaginatedResult object, containing an array of historical Message objects for the channel. |
void |
historyAsync(Param[] params,
Callback<AsyncPaginatedResult<Message>> callback)
Asynchronously retrieves a
PaginatedResult object, containing an array of historical Message objects for the channel. |
void |
markAsReleased()
Mark channel as released that means we can't perform any operation on this channel anymore
|
void |
on(ChannelState state,
ChannelStateListener listener) |
void |
once(ChannelState state,
ChannelStateListener listener) |
void |
publish(Message message)
Publishes a message to the channel.
|
void |
publish(Message[] messages)
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 |
publish(java.lang.String name,
java.lang.Object data)
Publishes a single message to the channel with the given event name and payload.
|
void |
publish(java.lang.String name,
java.lang.Object data,
CompletionListener listener)
Publishes a single message to the channel with the given event name and payload.
|
void |
setConnected(boolean reattachOnResumeFailure) |
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#errorReason
|
void |
setOptions(ChannelOptions options)
Sets the
ChannelOptions for the channel. |
void |
setOptions(ChannelOptions options,
CompletionListener listener)
Sets the
ChannelOptions 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(java.lang.String[] names,
ChannelBase.MessageListener listener)
Registers a listener for messages on this channel for multiple event name values.
|
void |
subscribe(java.lang.String name,
ChannelBase.MessageListener listener)
Registers a listener for messages with a given event name on this channel.
|
void |
sync() |
void |
unsubscribe()
Deregisters all listeners to messages on this channel.
|
void |
unsubscribe(ChannelBase.MessageListener listener)
Deregisters the given listener (for any/all event names).
|
void |
unsubscribe(java.lang.String[] names,
ChannelBase.MessageListener listener)
Deregisters the given listener from all event names in the array.
|
void |
unsubscribe(java.lang.String name,
ChannelBase.MessageListener listener)
Deregisters the given listener for the specified event name.
|
public final java.lang.String name
public ChannelState state
ChannelState of the channel.
Spec: RTL2b
public ErrorInfo reason
ErrorInfo object describing the last error which occurred on the channel, if any.
Spec: RTL4e
public ChannelProperties properties
ChannelProperties object.
Spec: CP1, RTL15
public void attach()
throws AblyException
subscribe(io.ably.lib.realtime.ChannelBase.MessageListener).
Any resulting channel state change will be emitted to any listeners registered using the
EventEmitter.on(Listener) or EventEmitter.once(Listener) methods.
As a convenience, attach() is called implicitly if subscribe(io.ably.lib.realtime.ChannelBase.MessageListener) for the channel is called,
or Presence.enter(java.lang.Object, io.ably.lib.realtime.CompletionListener) or Presence.subscribe(io.ably.lib.realtime.Presence.PresenceListener, io.ably.lib.realtime.CompletionListener) are called on the Presence object for this channel.
Spec: RTL4d
AblyExceptionpublic void attach(CompletionListener listener) throws AblyException
subscribe(io.ably.lib.realtime.ChannelBase.MessageListener).
Any resulting channel state change will be emitted to any listeners registered using the
EventEmitter.on(Listener) or EventEmitter.once(Listener) methods.
As a convenience, attach() is called implicitly if subscribe(io.ably.lib.realtime.ChannelBase.MessageListener) for the channel is called,
or Presence.enter(java.lang.Object, io.ably.lib.realtime.CompletionListener) or Presence.subscribe(io.ably.lib.realtime.Presence.PresenceListener, io.ably.lib.realtime.CompletionListener) are called on the Presence object for this channel.
Spec: RTL4d
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.
AblyExceptionpublic void detach()
throws AblyException
EventEmitter.on(Listener) or EventEmitter.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
AblyExceptionpublic void markAsReleased()
public void detach(CompletionListener listener) throws AblyException
EventEmitter.on(Listener) or EventEmitter.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
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.
AblyExceptionpublic void sync()
throws AblyException
AblyExceptionpublic void setConnected(boolean reattachOnResumeFailure)
public void setConnectionFailed(ErrorInfo reason)
public void setConnectionClosed(ErrorInfo reason)
public void setSuspended(ErrorInfo reason, boolean notifyStateChange)
protected void apply(ChannelStateListener listener, ChannelEvent event, java.lang.Object... args)
apply in class EventEmitter<ChannelEvent,ChannelStateListener>public void unsubscribe()
Spec: RTL8a, RTE5
public void subscribe(ChannelBase.MessageListener listener) throws AblyException
Spec: RTL7a
listener - A listener may optionally be passed in to this call to be notified of success or failure
of the channel attach() operation.
This listener is invoked on a background thread.
AblyExceptionpublic void unsubscribe(ChannelBase.MessageListener listener)
Spec: RTL8a
listener - An event listener function.
This listener is invoked on a background thread.
public void subscribe(java.lang.String name,
ChannelBase.MessageListener listener)
throws AblyException
Spec: RTL7b
name - The event name.listener - A listener may optionally be passed in to this call to be notified of success or failure
of the channel attach() operation.
This listener is invoked on a background thread.
AblyExceptionpublic void unsubscribe(java.lang.String name,
ChannelBase.MessageListener listener)
Spec: RTL8a
name - The event name.listener - An event listener function.
This listener is invoked on a background thread.
public void subscribe(java.lang.String[] names,
ChannelBase.MessageListener listener)
throws AblyException
Spec: RTL7a
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 channel attach() operation.
This listener is invoked on a background thread.
AblyExceptionpublic void unsubscribe(java.lang.String[] names,
ChannelBase.MessageListener listener)
Spec: RTL8a
names - An array of event names.listener - An event listener function.
This listener is invoked on a background thread.
public void publish(java.lang.String name,
java.lang.Object data)
throws AblyException
Spec: RTL6i
name - the event namedata - the message payloadAblyExceptionpublic void publish(Message message) throws AblyException
Spec: RTL6i
message - A Message object.AblyExceptionpublic void publish(Message[] messages) throws AblyException
Spec: RTL6i
messages - An array of Message objects.AblyExceptionpublic void publish(java.lang.String name,
java.lang.Object data,
CompletionListener listener)
throws AblyException
Spec: RTL6i
name - the event namedata - the message payloadlistener - 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.
AblyExceptionpublic void publish(Message message, CompletionListener listener) throws AblyException
Spec: RTL6i
message - A Message 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.
AblyExceptionpublic void publish(Message[] messages, CompletionListener listener) throws AblyException
Spec: RTL6i
messages - An array of Message 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.
AblyExceptionpublic PaginatedResult<Message> history(Param[] params) throws AblyException
PaginatedResult object, containing an array of historical Message 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
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.
PaginatedResult object containing an array of Message objects.AblyExceptionpublic void historyAsync(Param[] params, Callback<AsyncPaginatedResult<Message>> callback)
PaginatedResult object, containing an array of historical Message 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
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 with AsyncPaginatedResult object containing an array of Message objects.AblyExceptionpublic void setOptions(ChannelOptions options) throws AblyException
ChannelOptions for the channel.
Spec: RTL16
options - A ChannelOptions object.AblyExceptionpublic void setOptions(ChannelOptions options, CompletionListener listener) throws AblyException
ChannelOptions for the channel.
Spec: RTL16
options - A ChannelOptions object.listener - An optional listener may be provided to notify of the success or failure of the operation.AblyExceptionpublic java.util.Map<java.lang.String,java.lang.String> getParams()
public ChannelMode[] getModes()
public void emit(ChannelState state, ChannelStateListener.ChannelStateChange channelStateChange)
public void on(ChannelState state, ChannelStateListener listener)
public void once(ChannelState state, ChannelStateListener listener)