Class 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.
    • Field Detail

      • name

        public final java.lang.String name
        The name of this channel.
      • presence

        public final Presence presence
        The Presence object 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.
    • Method Detail

      • attach

        public void attach()
                    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.
        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 AblyException
        Detach 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
      • 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).
      • 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 AblyException
        Subscribe for messages with a specific event name on this channel. This implicitly attaches the channel if not already attached.
        Parameters:
        name - : the event name
        listener - : 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 name
        listener - : the previously subscribed listener.
      • subscribe

        public void subscribe​(java.lang.String[] names,
                              ChannelBase.MessageListener listener)
                       throws AblyException
        Subscribe for messages with an array of event names on this channel. This implicitly attaches the channel if not already attached.
        Parameters:
        names - : the event names
        listener - : 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 names
        listener - : the previously subscribed listener.
      • publish

        public void publish​(java.lang.String name,
                            java.lang.Object data)
                     throws AblyException
        Publish a message on this channel. This implicitly attaches the channel if not already attached.
        Parameters:
        name - : the event name
        data - : 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 AblyException
        Publish a message on this channel. This implicitly attaches the channel if not already attached.
        Parameters:
        name - : the event name
        data - : the message payload. See io.ably.types.Data for supported datatypes
        listener - : 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 message
        listener - : 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 message
        listener - : 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