-
public abstract class ChannelBase extends EventEmitter<ChannelEvent, ChannelStateListener>
Enables messages to be published and subscribed to. Also enables historic messages to be retrieved and provides access to the Presence object of a channel.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public interfaceChannelBase.MessageListenerAn interface whereby a client maybe notified of message on a channel.
-
Field Summary
Fields Modifier and Type Field Description public final Stringnamepublic final Presencepresencepublic ChannelStatestatepublic ErrorInforeasonpublic ChannelPropertiespropertiespublic final RealtimeAnnotationsannotationsChannelOptionsoptionsprivate Map<String, String>params
-
Method Summary
Modifier and Type Method Description voidsetState(ChannelState newState, ErrorInfo reason)ChannelOptionsgetOptions()voidsetOptions(ChannelOptions options)Sets the ChannelOptions for the channel. Map<String, String>getParams()RealtimeObjectsgetObjects()voidattach()Attach to this channel ensuring the channel is created in the Ably system and all messages publishedon the channel are received by any channel listeners registered using subscribe. voidattach(CompletionListener listener)Attach to this channel ensuring the channel is created in the Ably system and all messages publishedon the channel are received by any channel listeners registered using subscribe. voiddetach()Detach from this channel. voidmarkAsReleased()Mark channel as released that means we can't perform any operation on this channel anymore voiddetach(CompletionListener listener)Detach from this channel. voidsync()voidsetConnected()voidsetConnectionFailed(ErrorInfo reason)If the connection state enters the FAILED state, then an ATTACHINGor ATTACHED channel state will transition to FAILED and set theChannel#errorReason voidsetConnectionClosed(ErrorInfo reason)(RTL3b) If the connection state enters the CLOSED state, then anATTACHING or ATTACHED channel state will transition to DETACHED. synchronized voidsetSuspended(ErrorInfo reason, boolean notifyStateChange)(RTL3c) If the connection state enters the SUSPENDED state, then anATTACHING or ATTACHED channel state will transition to SUSPENDED.(RTN15c3) The client library should initiate an attach for channelsthat are in the SUSPENDED state. synchronized voidsetReinitialized()Internal(RTN11d) Resets channels back to initialized and clears error reason synchronized voidunsubscribe()Deregisters all listeners to messages on this channel.This removes all earlier subscriptions. synchronized voidsubscribe(ChannelBase.MessageListener listener)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. synchronized voidunsubscribe(ChannelBase.MessageListener listener)Deregisters the given listener (for any/all event names).This removes an earlier subscription. synchronized voidsubscribe(String name, ChannelBase.MessageListener listener)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. synchronized voidunsubscribe(String name, ChannelBase.MessageListener listener)Deregisters the given listener for the specified event name. synchronized voidsubscribe(Array<String> names, ChannelBase.MessageListener listener)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. synchronized voidunsubscribe(Array<String> names, ChannelBase.MessageListener listener)Deregisters the given listener from all event names in the array. voidpublish(String name, Object data)Publishes a single message to the channel with the given event name and payload. voidpublish(Message message)Publishes a message to the channel.When publish is called with this client library, it won't attempt to implicitly attach to the channel. voidpublish(Array<Message> messages)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. voidpublish(String name, Object data, CompletionListener listener)Publishes a single message to the channel with the given event name and payload. voidpublish(Message message, CompletionListener listener)Publishes a message to the channel.When publish is called with this client library, it won't attempt to implicitly attach to the channel. synchronized voidpublish(Array<Message> messages, CompletionListener listener)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. MessagegetMessage(String serial)Retrieves the latest version of a specific message by its serial identifier. voidgetMessageAsync(String serial, Callback<Message> callback)Asynchronously retrieves the latest version of a specific message by its serial identifier. voidupdateMessage(Message message, MessageOperation operation)Updates an existing message using patch semantics. voidupdateMessage(Message message)Updates an existing message using patch semantics. voidupdateMessageAsync(Message message, MessageOperation operation, CompletionListener listener)Asynchronously updates an existing message. voidupdateMessageAsync(Message message, CompletionListener listener)Asynchronously updates an existing message. voiddeleteMessage(Message message, MessageOperation operation)Marks a message as deleted. voiddeleteMessage(Message message)Marks a message as deleted. voiddeleteMessageAsync(Message message, MessageOperation operation, CompletionListener listener)Asynchronously marks a message as deleted. voiddeleteMessageAsync(Message message, CompletionListener listener)Asynchronously marks a message as deleted. PaginatedResult<Message>getMessageVersions(String serial, Array<Param> params)Retrieves all historical versions of a specific message. voidgetMessageVersionsAsync(String serial, Array<Param> params, Callback<AsyncPaginatedResult<Message>> callback)Asynchronously retrieves all historical versions of a specific message. PaginatedResult<Message>history(Array<Param> params)Retrieves a 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. voidhistoryAsync(Array<Param> params, Callback<AsyncPaginatedResult<Message>> callback)Asynchronously retrieves a 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. voidemit(ChannelState state, ChannelStateListener.ChannelStateChange channelStateChange)voidon(ChannelState state, ChannelStateListener listener)voidonce(ChannelState state, ChannelStateListener listener)voidsendProtocolMessage(ProtocolMessage protocolMessage, CompletionListener listener)(Internal) Sends a protocol message and provides a callback for completion. -
-
Method Detail
-
setState
void setState(ChannelState newState, ErrorInfo reason)
-
getOptions
ChannelOptions getOptions()
-
setOptions
void setOptions(ChannelOptions options)
Sets the ChannelOptions for the channel.
Spec: RTL16
- Parameters:
options- A ChannelOptions object.
-
getObjects
RealtimeObjects getObjects()
-
attach
void attach()
Attach to this channel ensuring the channel is created in the Ably system and all messages publishedon the channel are received by any channel listeners registered using subscribe.Any resulting channel state change will be emitted to any listeners registered using the on or once methods.As a convenience, attach() is called implicitly if subscribe for the channel is called,or enter or subscribe are called on the Presence object for this channel.
Spec: RTL4d
-
attach
void attach(CompletionListener listener)
Attach to this channel ensuring the channel is created in the Ably system and all messages publishedon the channel are received by any channel listeners registered using subscribe.Any resulting channel state change will be emitted to any listeners registered using the on or once methods.As a convenience, attach() is called implicitly if subscribe for the channel is called,or enter or subscribe are called on the Presence 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.
-
detach
void detach()
Detach from this channel.Any resulting channel state change is emitted to any listeners registered using the on or once methods.Once all clients globally have detached from the channel, the channel will be released in the Ably service within two minutes.
Spec: RTL5e
-
markAsReleased
void markAsReleased()
Mark channel as released that means we can't perform any operation on this channel anymore
-
detach
void detach(CompletionListener listener)
Detach from this channel.Any resulting channel state change is emitted to any listeners registered using the on or once 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.
-
sync
@Deprecated() void sync()
-
setConnected
void setConnected()
-
setConnectionFailed
void setConnectionFailed(ErrorInfo reason)
If the connection state enters the FAILED state, then an ATTACHINGor ATTACHED channel state will transition to FAILED and set theChannel#errorReason
-
setConnectionClosed
void setConnectionClosed(ErrorInfo reason)
(RTL3b) If the connection state enters the CLOSED state, then anATTACHING or ATTACHED channel state will transition to DETACHED.
-
setSuspended
synchronized void setSuspended(ErrorInfo reason, boolean notifyStateChange)
(RTL3c) If the connection state enters the SUSPENDED state, then anATTACHING or ATTACHED channel state will transition to SUSPENDED.(RTN15c3) The client library should initiate an attach for channelsthat are in the SUSPENDED state. For all channels in the ATTACHINGor ATTACHED state, the client library should fail any previously queuedmessages for that channel and initiate a new attach.This also gets called when a connection enters CONNECTED but with anon-fatal error for a failed reconnect (RTN16e).
-
setReinitialized
synchronized void setReinitialized()
Internal
(RTN11d) Resets channels back to initialized and clears error reason
-
unsubscribe
synchronized void unsubscribe()
Deregisters all listeners to messages on this channel.This removes all earlier subscriptions.
Spec: RTL8a, RTE5
-
subscribe
synchronized void subscribe(ChannelBase.MessageListener listener)
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 failureof the channel attach operation.
-
unsubscribe
synchronized void unsubscribe(ChannelBase.MessageListener listener)
Deregisters the given listener (for any/all event names).This removes an earlier subscription.
Spec: RTL8a
- Parameters:
listener- An event listener function.
-
subscribe
synchronized void subscribe(String name, ChannelBase.MessageListener listener)
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 failureof the channel attach operation.
-
unsubscribe
synchronized void unsubscribe(String name, ChannelBase.MessageListener listener)
Deregisters the given listener for the specified event name.This removes an earlier event-specific subscription
Spec: RTL8a
- Parameters:
name- The event name.listener- An event listener function.
-
subscribe
synchronized void subscribe(Array<String> names, ChannelBase.MessageListener listener)
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 failureof the channel attach operation.
-
unsubscribe
synchronized void unsubscribe(Array<String> names, ChannelBase.MessageListener listener)
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.
-
publish
void publish(String name, Object data)
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 namedata- the message payload
-
publish
void publish(Message message)
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- A Message object.
-
publish
void publish(Array<Message> messages)
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 of Message objects.
-
publish
void publish(String name, Object data, CompletionListener listener)
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 namedata- the message payloadlistener- A listener may optionally be passed in to this call to be notified of success or failure of the operation.
-
publish
void publish(Message message, CompletionListener listener)
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- A Message object.listener- A listener may optionally be passed in to this call to be notified of success or failure of the operation.
-
publish
synchronized void publish(Array<Message> messages, CompletionListener listener)
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 of Message objects.listener- A listener may optionally be passed in to this call to be notified of success or failure of the operation.
-
getMessage
Message getMessage(String serial)
Retrieves the latest version of a specific message by its serial identifier.
This method allows you to fetch the current state of a message, including any updatesor deletions that have been applied since its creation.
- Parameters:
serial- The unique serial identifier of the message to retrieve.
-
getMessageAsync
void getMessageAsync(String serial, Callback<Message> callback)
Asynchronously retrieves the latest version of a specific message by its serial identifier.
- Parameters:
serial- The unique serial identifier of the message to retrieve.callback- A callback to handle the result asynchronously.
-
updateMessage
void updateMessage(Message message, MessageOperation operation)
Updates an existing message using patch semantics.
Non-null fields in the provided message (name, data, extras) will replace the correspondingfields in the existing message, while null fields will be left unchanged.
- Parameters:
message- A Message object containing the fields to update and the serial identifier.Only non-null fields will be applied to the existing message.operation- operation metadata such as clientId, description, or metadata in the version field
-
updateMessage
void updateMessage(Message message)
Updates an existing message using patch semantics.
Non-null fields in the provided message (name, data, extras) will replace the correspondingfields in the existing message, while null fields will be left unchanged.
- Parameters:
message- A Message object containing the fields to update and the serial identifier.Only non-null fields will be applied to the existing message.
-
updateMessageAsync
void updateMessageAsync(Message message, MessageOperation operation, CompletionListener listener)
Asynchronously updates an existing message.
- Parameters:
message- A Message object containing the fields to update and the serial identifier.operation- operation metadata such as clientId, description, or metadata in the version fieldlistener- A listener to be notified of the outcome of this operation.
-
updateMessageAsync
void updateMessageAsync(Message message, CompletionListener listener)
Asynchronously updates an existing message.
- Parameters:
message- A Message object containing the fields to update and the serial identifier.listener- A listener to be notified of the outcome of this operation.
-
deleteMessage
void deleteMessage(Message message, MessageOperation operation)
Marks a message as deleted.
This operation does not remove the message from history; it marks it as deletedwhile preserving the full message history. The deleted message can still beretrieved and will have its action set to MESSAGE_DELETE.
- Parameters:
message- A Message message containing the serial identifier.operation- operation metadata such as clientId, description, or metadata in the version field
-
deleteMessage
void deleteMessage(Message message)
Marks a message as deleted.
This operation does not remove the message from history; it marks it as deletedwhile preserving the full message history. The deleted message can still beretrieved and will have its action set to MESSAGE_DELETE.
- Parameters:
message- A Message message containing the serial identifier.
-
deleteMessageAsync
void deleteMessageAsync(Message message, MessageOperation operation, CompletionListener listener)
Asynchronously marks a message as deleted.
- Parameters:
message- A Message object containing the serial identifier and operation metadata.operation- operation metadata such as clientId, description, or metadata in the version fieldlistener- A listener to be notified of the outcome of this operation.
-
deleteMessageAsync
void deleteMessageAsync(Message message, CompletionListener listener)
Asynchronously marks a message as deleted.
- Parameters:
message- A Message object containing the serial identifier and operation metadata.listener- A listener to be notified of the outcome of this operation.
-
getMessageVersions
PaginatedResult<Message> getMessageVersions(String serial, Array<Param> params)
Retrieves all historical versions of a specific message.
This method returns a paginated result containing all versions of the message,ordered chronologically. Each version includes metadata about when and by whomthe message was modified.
- Parameters:
serial- The unique serial identifier of the message.params- Query parameters for filtering or pagination (e.g., limit, start, end).
-
getMessageVersionsAsync
void getMessageVersionsAsync(String serial, Array<Param> params, Callback<AsyncPaginatedResult<Message>> callback)
Asynchronously retrieves all historical versions of a specific message.
- Parameters:
serial- The unique serial identifier of the message.params- Query parameters for filtering or pagination.callback- A callback to handle the result asynchronously.
-
history
PaginatedResult<Message> history(Array<Param> params)
Retrieves a 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
- Parameters:
params- the request params:start (RTL10a) - The time from which messages are retrieved, specified as milliseconds since the Unix epoch.
-
historyAsync
void historyAsync(Array<Param> params, Callback<AsyncPaginatedResult<Message>> callback)
Asynchronously retrieves a 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
- Parameters:
params- the request params:start (RTL10a) - The time from which messages are retrieved, specified as milliseconds since the Unix epoch.callback- Callback with AsyncPaginatedResult object containing an array of Message objects.
-
emit
void emit(ChannelState state, ChannelStateListener.ChannelStateChange channelStateChange)
-
on
void on(ChannelState state, ChannelStateListener listener)
-
once
void once(ChannelState state, ChannelStateListener listener)
-
sendProtocolMessage
void sendProtocolMessage(ProtocolMessage protocolMessage, CompletionListener listener)
(Internal) Sends a protocol message and provides a callback for completion.
- Parameters:
protocolMessage- the protocol message to be sentlistener- the listener to be notified upon completion of the message delivery
-
-
-
-