public interface ClientSessionChannel extends Channel
A client side channel representation.
A ClientSessionChannel is scoped to a particular ClientSession
that is obtained by a call to ClientSession.getChannel(String).
Typical usage examples are:
clientSession.getChannel("/foo/bar").subscribe(mySubscriptionListener);
clientSession.getChannel("/foo/bar").publish("Hello");
clientSession.getChannel("/meta/*").addListener(myMetaChannelListener);
| Modifier and Type | Interface and Description |
|---|---|
static interface |
ClientSessionChannel.ClientSessionChannelListener
Represents a listener on a
ClientSessionChannel. |
static interface |
ClientSessionChannel.MessageListener
A listener for messages on a
ClientSessionChannel. |
META, META_CONNECT, META_DISCONNECT, META_HANDSHAKE, META_SUBSCRIBE, META_UNSUBSCRIBE| Modifier and Type | Method and Description |
|---|---|
void |
addListener(ClientSessionChannel.ClientSessionChannelListener listener)
Adds a listener to this channel.
|
List<ClientSessionChannel.ClientSessionChannelListener> |
getListeners() |
ClientSession |
getSession() |
List<ClientSessionChannel.MessageListener> |
getSubscribers() |
boolean |
isReleased() |
void |
publish(Object data)
Publishes the given
data onto this channel. |
void |
publish(Object data,
ClientSessionChannel.MessageListener listener)
Publishes the given
data onto this channel, notifying the given
listener of the publish result, whether successful or unsuccessful. |
boolean |
release()
Releases this channel from its
ClientSession. |
void |
removeListener(ClientSessionChannel.ClientSessionChannelListener listener)
Removes the given
listener from this channel. |
void |
subscribe(ClientSessionChannel.MessageListener listener)
Subscribes the given
listener to receive messages sent to this channel. |
void |
unsubscribe()
Unsubscribes all subscribers registered on this channel.
|
void |
unsubscribe(ClientSessionChannel.MessageListener listener)
Unsubscribes the given
listener from receiving messages sent to this channel. |
getAttribute, getAttributeNames, getChannelId, getId, isBroadcast, isDeepWild, isMeta, isService, isWild, removeAttribute, setAttributevoid addListener(ClientSessionChannel.ClientSessionChannelListener listener)
Adds a listener to this channel.
If the listener is a ClientSessionChannel.MessageListener, it will be invoked
if a message arrives to this channel.
Adding a listener never involves communication with the server,
differently from subscribe(MessageListener).
Listeners are best suited to receive messages from
meta channels.
listener - the listener to addremoveListener(ClientSessionChannelListener)void removeListener(ClientSessionChannel.ClientSessionChannelListener listener)
Removes the given listener from this channel.
Removing a listener never involves communication with the server,
differently from unsubscribe(MessageListener).
listener - the listener to removeaddListener(ClientSessionChannelListener)List<ClientSessionChannel.ClientSessionChannelListener> getListeners()
addListener(ClientSessionChannelListener)ClientSession getSession()
void publish(Object data)
Publishes the given data onto this channel.
The data published must not be null and can be any object that
can be natively converted to JSON (numbers, strings, arrays, lists, maps),
or objects for which a JSON converter has been registered with the
infrastructure responsible of the JSON conversion.
data - the data to publishpublish(Object, MessageListener)void publish(Object data, ClientSessionChannel.MessageListener listener)
Publishes the given data onto this channel, notifying the given
listener of the publish result, whether successful or unsuccessful.
data - the data to publishlistener - the message listener to notify of the publish resultpublish(Object)void subscribe(ClientSessionChannel.MessageListener listener)
Subscribes the given listener to receive messages sent to this channel.
Subscription involves communication with the server only for the first listener subscribed to this channel. Listeners registered after the first will not cause a message being sent to the server.
listener - the listener to register and invoke when a message arrives on this channel.unsubscribe(MessageListener),
addListener(ClientSessionChannelListener)void unsubscribe(ClientSessionChannel.MessageListener listener)
Unsubscribes the given listener from receiving messages sent to this channel.
Unsubscription involves communication with the server only for the last listener unsubscribed from this channel.
listener - the listener to unsubscribesubscribe(MessageListener),
unsubscribe()void unsubscribe()
Unsubscribes all subscribers registered on this channel.
subscribe(MessageListener)List<ClientSessionChannel.MessageListener> getSubscribers()
subscribe(MessageListener)boolean release()
Releases this channel from its ClientSession.
If the release is successful, subsequent invocations of ClientSession.getChannel(String)
will return a new, different, instance of a ClientSessionChannel.
The release of a ClientSessionChannel is successful only if no listeners and no
subscribers are present at the moment of the release.
isReleased()boolean isReleased()
release()Copyright © 2008-2012 Dojo Foundation. All Rights Reserved.