Package io.ably.lib.realtime
Class ChannelBase
- java.lang.Object
-
- io.ably.lib.util.EventEmitter<ChannelEvent,ChannelStateListener>
-
- io.ably.lib.realtime.ChannelBase
-
- Direct Known Subclasses:
Channel
public abstract class ChannelBase extends EventEmitter<ChannelEvent,ChannelStateListener>
A class representing a Channel belonging to this application. The Channel instance allows messages to be published and received, and controls the lifecycle of this instance's attachment to the channel.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceChannelBase.MessageListenerAn interface whereby a client maybe notified of messages changes on a channel.-
Nested classes/interfaces inherited from class io.ably.lib.util.EventEmitter
EventEmitter.Filter
-
-
Field Summary
Fields Modifier and Type Field Description java.lang.StringnameThe name of this channel.PresencepresenceThePresenceobject for this channel.ChannelPropertiespropertiesProperties of ChannelErrorInforeasonError information associated with a failed channel state.ChannelStatestateThe current channel state.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidapply(ChannelStateListener listener, ChannelEvent event, java.lang.Object... args)voidattach()Attach to this channel.voidattach(CompletionListener listener)Attach to this channel.voiddetach()Detach from this channel.voiddetach(CompletionListener listener)Detach from this channel.voidemit(ChannelState state, ChannelStateListener.ChannelStateChange channelStateChange)PaginatedResult<Message>history(Param[] params)Obtain recent history for this channel using the REST API.voidhistoryAsync(Param[] params, Callback<AsyncPaginatedResult<Message>> callback)voidon(ChannelState state, ChannelStateListener listener)voidonce(ChannelState state, ChannelStateListener listener)voidpublish(Message message)Publish a message on this channel.voidpublish(Message[] messages)Publish an array of messages on this channel.voidpublish(Message[] messages, CompletionListener listener)Publish an array of messages on this channel.voidpublish(Message message, CompletionListener listener)Publish a message on this channel.voidpublish(java.lang.String name, java.lang.Object data)Publish a message on this channel.voidpublish(java.lang.String name, java.lang.Object data, CompletionListener listener)Publish a message on this channel.voidsetConnected()voidsetConnectionClosed(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)Channel optionsvoidsetSuspended(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)Subscribe for messages on this channel.voidsubscribe(java.lang.String[] names, ChannelBase.MessageListener listener)Subscribe for messages with an array of event names on this channel.voidsubscribe(java.lang.String name, ChannelBase.MessageListener listener)Subscribe for messages with a specific event name on this channel.voidsync()voidunsubscribe()Unsubscribe all subscribed listeners from this channel.voidunsubscribe(ChannelBase.MessageListener listener)Unsubscribe a previously subscribed listener from this channel.voidunsubscribe(java.lang.String[] names, ChannelBase.MessageListener listener)Unsubscribe a previously subscribed event listener from this channel.voidunsubscribe(java.lang.String name, ChannelBase.MessageListener listener)Unsubscribe a previously subscribed event listener from this channel.
-
-
-
Field Detail
-
name
public final java.lang.String name
The name of this channel.
-
presence
public final Presence presence
ThePresenceobject for this channel. This controls this client's presence on the channel and may also be used to obtain presence information and change events for other members of the channel.
-
state
public ChannelState state
The current channel state.
-
reason
public ErrorInfo reason
Error information associated with a failed channel state.
-
properties
public ChannelProperties properties
Properties of Channel
-
-
Method Detail
-
attach
public void attach() throws AblyExceptionAttach to this channel. This call initiates the attach request, and the response is indicated asynchronously in the resulting state change. attach() is called implicitly when publishing or subscribing on this channel, so it is not usually necessary for a client to call attach() explicitly.- Throws:
AblyException
-
attach
public void attach(CompletionListener listener) throws AblyException
Attach to this channel. This call initiates the attach request, and the response is indicated asynchronously in the resulting state change. attach() is called implicitly when publishing or subscribing on this channel, so it is not usually necessary for a client to call attach() explicitly.- Parameters:
listener- When the channel is attached successfully or the attach fails and the ErrorInfo error is passed as an argument to the callback- Throws:
AblyException
-
detach
public void detach() throws AblyExceptionDetach from this channel. This call initiates the detach request, and the response is indicated asynchronously in the resulting state change.- Throws:
AblyException
-
detach
public void detach(CompletionListener listener) throws AblyException
Detach from this channel. This call initiates the detach request, and the response is indicated asynchronously in the resulting state change.- Throws:
AblyException
-
sync
public void sync() throws AblyException- Throws:
AblyException
-
setConnected
public void setConnected()
-
setConnectionFailed
public 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
-
setConnectionClosed
public void setConnectionClosed(ErrorInfo reason)
(RTL3b) If the connection state enters the CLOSED state, then an ATTACHING or ATTACHED channel state will transition to DETACHED.
-
setSuspended
public 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. (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
protected void apply(ChannelStateListener listener, ChannelEvent event, java.lang.Object... args)
- Specified by:
applyin classEventEmitter<ChannelEvent,ChannelStateListener>
-
unsubscribe
public void unsubscribe()
Unsubscribe all subscribed listeners from this channel.
Spec: RTL8a
-
subscribe
public void subscribe(ChannelBase.MessageListener listener) throws AblyException
Subscribe for messages on this channel. This implicitly attaches the channel if not already attached.- Parameters:
listener- : the MessageListener- Throws:
AblyException
-
unsubscribe
public void unsubscribe(ChannelBase.MessageListener listener)
Unsubscribe a previously subscribed listener from this channel.- Parameters:
listener- : the previously subscribed listener.
-
subscribe
public void subscribe(java.lang.String name, ChannelBase.MessageListener listener) throws AblyExceptionSubscribe for messages with a specific event name on this channel. This implicitly attaches the channel if not already attached.- Parameters:
name- : the event namelistener- : the MessageListener- Throws:
AblyException
-
unsubscribe
public void unsubscribe(java.lang.String name, ChannelBase.MessageListener listener)Unsubscribe a previously subscribed event listener from this channel.- Parameters:
name- : the event namelistener- : the previously subscribed listener.
-
subscribe
public void subscribe(java.lang.String[] names, ChannelBase.MessageListener listener) throws AblyExceptionSubscribe for messages with an array of event names on this channel. This implicitly attaches the channel if not already attached.- Parameters:
names- : the event nameslistener- : the MessageListener- Throws:
AblyException
-
unsubscribe
public void unsubscribe(java.lang.String[] names, ChannelBase.MessageListener listener)Unsubscribe a previously subscribed event listener from this channel.- Parameters:
names- : the event nameslistener- : the previously subscribed listener.
-
publish
public void publish(java.lang.String name, java.lang.Object data) throws AblyExceptionPublish a message on this channel. This implicitly attaches the channel if not already attached.- Parameters:
name- : the event namedata- : the message payload- Throws:
AblyException
-
publish
public void publish(Message message) throws AblyException
Publish a message on this channel. This implicitly attaches the channel if not already attached.- Parameters:
message- : the message- Throws:
AblyException
-
publish
public void publish(Message[] messages) throws AblyException
Publish an array of messages on this channel. This implicitly attaches the channel if not already attached.- Parameters:
messages- : the message- Throws:
AblyException
-
publish
public void publish(java.lang.String name, java.lang.Object data, CompletionListener listener) throws AblyExceptionPublish a message on this channel. This implicitly attaches the channel if not already attached.- Parameters:
name- : the event namedata- : the message payload. Seeio.ably.types.Datafor supported datatypeslistener- : a listener to be notified of the outcome of this message.- Throws:
AblyException
-
publish
public void publish(Message message, CompletionListener listener) throws AblyException
Publish a message on this channel. This implicitly attaches the channel if not already attached.- Parameters:
message- : the messagelistener- : a listener to be notified of the outcome of this message.- Throws:
AblyException
-
publish
public void publish(Message[] messages, CompletionListener listener) throws AblyException
Publish an array of messages on this channel. This implicitly attaches the channel if not already attached.- Parameters:
messages- : the messagelistener- : a listener to be notified of the outcome of this message.- Throws:
AblyException
-
history
public PaginatedResult<Message> history(Param[] params) throws AblyException
Obtain recent history for this channel using the REST API. The history provided relqtes to all clients of this application, not just this instance.- Parameters:
params- : the request params. See the Ably REST API documentation for more details.- Throws:
AblyException
-
historyAsync
public void historyAsync(Param[] params, Callback<AsyncPaginatedResult<Message>> callback)
-
setOptions
public void setOptions(ChannelOptions options) throws AblyException
Channel options- Throws:
AblyException
-
emit
public void emit(ChannelState state, ChannelStateListener.ChannelStateChange channelStateChange)
-
on
public void on(ChannelState state, ChannelStateListener listener)
-
once
public void once(ChannelState state, ChannelStateListener listener)
-
-