Class ChannelBase

    • Method Detail

      • detach

        public void detach​(CompletionListener listener)
                    throws AblyException
        Detach from this channel. Any resulting channel state change is emitted to any listeners registered using the 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

        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
      • setConnected

        public void setConnected​(boolean reattachOnResumeFailure)
      • 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()
        Deregisters all listeners to messages on this channel. This removes all earlier subscriptions.

        Spec: RTL8a, RTE5

      • subscribe

        public void subscribe​(ChannelBase.MessageListener listener)
                       throws AblyException
        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 channel attach() operation.

        This listener is invoked on a background thread.

        Throws:
        AblyException
      • unsubscribe

        public 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.

        This listener is invoked on a background thread.

      • subscribe

        public void subscribe​(java.lang.String name,
                              ChannelBase.MessageListener listener)
                       throws AblyException
        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 channel attach() operation.

        This listener is invoked on a background thread.

        Throws:
        AblyException
      • unsubscribe

        public void unsubscribe​(java.lang.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.

        This listener is invoked on a background thread.

      • subscribe

        public void subscribe​(java.lang.String[] names,
                              ChannelBase.MessageListener listener)
                       throws AblyException
        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 channel attach() operation.

        This listener is invoked on a background thread.

        Throws:
        AblyException
      • unsubscribe

        public void unsubscribe​(java.lang.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.

        This listener is invoked on a background thread.

      • publish

        public void publish​(java.lang.String name,
                            java.lang.Object data)
                     throws AblyException
        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

        public void publish​(Message message)
                     throws AblyException
        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.
        Throws:
        AblyException
      • publish

        public void publish​(Message[] messages)
                     throws AblyException
        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.
        Throws:
        AblyException
      • publish

        public void publish​(java.lang.String name,
                            java.lang.Object data,
                            CompletionListener listener)
                     throws AblyException
        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

        public void publish​(Message message,
                            CompletionListener listener)
                     throws AblyException
        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.

        This listener is invoked on a background thread.

        Throws:
        AblyException
      • publish

        public void publish​(Message[] messages,
                            CompletionListener listener)
                     throws AblyException
        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.

        This listener is invoked on a background thread.

        Throws:
        AblyException
      • history

        public PaginatedResult<Message> history​(Param[] params)
                                         throws AblyException
        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.

        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 PaginatedResult object containing an array of Message objects.
        Throws:
        AblyException
      • historyAsync

        public void historyAsync​(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.

        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.
        Throws:
        AblyException
      • getParams

        public java.util.Map<java.lang.String,​java.lang.String> getParams()