Class ChannelBase
- Direct Known Subclasses:
 Channel
Presence object of a channel.- 
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceAn 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
FieldsModifier and TypeFieldDescriptionfinal RealtimeAnnotationsfinal StringThe channel name.final PresenceAPresenceobject.AChannelPropertiesobject.AnErrorInfoobject describing the last error which occurred on the channel, if any.The currentChannelStateof the channel. - 
Method Summary
Modifier and TypeMethodDescriptionprotected voidapply(ChannelStateListener listener, ChannelEvent event, Object... args) voidattach()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).voidattach(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 booleanChecks ifChannelOptions.attachOnSubscribeis true.voiddetach()Detach from this channel.voiddetach(CompletionListener listener) Detach from this channel.voidemit(ChannelState state, ChannelStateListener.ChannelStateChange channelStateChange) getModes()Retrieves aPaginatedResultobject, containing an array of historicalMessageobjects for the channel.voidhistoryAsync(Param[] params, Callback<AsyncPaginatedResult<Message>> callback) Asynchronously retrieves aPaginatedResultobject, containing an array of historicalMessageobjects for the channel.voidMark channel as released that means we can't perform any operation on this channel anymorevoidon(ChannelState state, ChannelStateListener listener) voidonce(ChannelState state, ChannelStateListener listener) voidPublishes a message to the channel.voidPublishes an array of messages to the channel.voidpublish(Message[] messages, CompletionListener listener) Publishes an array of messages to the channel.voidpublish(Message message, CompletionListener listener) Publishes a message to the channel.voidPublishes a single message to the channel with the given event name and payload.voidpublish(String name, Object data, CompletionListener listener) Publishes a single message to the channel with the given event name and payload.voidsendProtocolMessage(ProtocolMessage protocolMessage, CompletionListener listener) (Internal) Sends a protocol message and provides a callback for completion.voidvoidsetConnectionClosed(ErrorInfo reason) (RTL3b) If the connection state enters the CLOSED state, then an ATTACHING or ATTACHED channel state will transition to DETACHED.voidsetConnectionFailed(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#errorReasonvoidsetOptions(ChannelOptions options) Sets theChannelOptionsfor the channel.voidsetOptions(ChannelOptions options, CompletionListener listener) Sets theChannelOptionsfor the channel.voidInternalvoidsetSuspended(ErrorInfo reason, boolean notifyStateChange) (RTL3c) If the connection state enters the SUSPENDED state, then an ATTACHING or ATTACHED channel state will transition to SUSPENDED.voidsubscribe(ChannelBase.MessageListener listener) Registers a listener for messages on this channel.voidsubscribe(String[] names, ChannelBase.MessageListener listener) Registers a listener for messages on this channel for multiple event name values.voidsubscribe(String name, ChannelBase.MessageListener listener) Registers a listener for messages with a given event name on this channel.voidsync()Deprecated.voidDeregisters all listeners to messages on this channel.voidunsubscribe(ChannelBase.MessageListener listener) Deregisters the given listener (for any/all event names).voidunsubscribe(String[] names, ChannelBase.MessageListener listener) Deregisters the given listener from all event names in the array.voidunsubscribe(String name, ChannelBase.MessageListener listener) Deregisters the given listener for the specified event name. 
- 
Field Details
- 
name
The channel name. - 
presence
APresenceobject.Spec: RTL9
 - 
state
The currentChannelStateof the channel.Spec: RTL2b
 - 
reason
AnErrorInfoobject describing the last error which occurred on the channel, if any.Spec: RTL4e
 - 
properties
AChannelPropertiesobject.Spec: CP1, RTL15
 - 
annotations
 
 - 
 - 
Method Details
- 
getObjects
- 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 thePresenceobject 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 thePresenceobject 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). - 
setReinitialized
public void setReinitialized()Internal(RTN11d) Resets channels back to initialized and clears error reason
 - 
apply
- Specified by:
 - 
applyin 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.attachOnSubscribeis true.truewhenoptionsis 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- AMessageobject. - 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 ofMessageobjects. - 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- AMessageobject. - 
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 ofMessageobjects. - 
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 aPaginatedResultobject, containing an array of historicalMessageobjects 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 
PaginatedResultobject containing an array ofMessageobjects. - Throws:
 AblyException
 - 
historyAsync
Asynchronously retrieves aPaginatedResultobject, containing an array of historicalMessageobjects 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 withAsyncPaginatedResultobject containing an array ofMessageobjects. - Throws:
 AblyException
 - 
setOptions
Sets theChannelOptionsfor the channel.Spec: RTL16
- Parameters:
 - 
options- AChannelOptionsobject. - Throws:
 AblyException
 - 
setOptions
Sets theChannelOptionsfor the channel.Spec: RTL16
- Parameters:
 - 
options- AChannelOptionsobject. - 
listener- An optional listener may be provided to notify of the success or failure of the operation. - Throws:
 AblyException
 - 
getParams
 - 
getModes
 - 
getOptions
 - 
emit
 - 
on
 - 
once
 - 
sendProtocolMessage
public void sendProtocolMessage(ProtocolMessage protocolMessage, CompletionListener listener) throws AblyException (Internal) Sends a protocol message and provides a callback for completion.- Parameters:
 - 
protocolMessage- the protocol message to be sent - 
listener- the listener to be notified upon completion of the message delivery - Throws:
 AblyException
 
 -