Interface ClientSessionChannel
-
- All Superinterfaces:
Channel
- All Known Implementing Classes:
AbstractClientSession.AbstractSessionChannel,BayeuxClient.BayeuxClientChannel,LocalSessionImpl.LocalChannel
public interface ClientSessionChannel extends Channel
A client side channel representation.
A
ClientSessionChannelis scoped to a particularClientSessionthat is obtained by a call toClientSession.getChannel(String).Typical usage examples are:
clientSession.getChannel("/foo/bar").subscribe(mySubscriptionListener); clientSession.getChannel("/foo/bar").publish("Hello"); clientSession.getChannel("/meta/*").addListener(myMetaChannelListener);
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interfaceClientSessionChannel.ClientSessionChannelListenerRepresents a listener on aClientSessionChannel.static interfaceClientSessionChannel.MessageListenerA listener for messages on aClientSessionChannel.
-
Field Summary
-
Fields inherited from interface org.cometd.bayeux.Channel
META, META_CONNECT, META_DISCONNECT, META_HANDSHAKE, META_SUBSCRIBE, META_UNSUBSCRIBE, SERVICE
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description voidaddListener(ClientSessionChannel.ClientSessionChannelListener listener)Adds a listener to this channel.java.util.List<ClientSessionChannel.ClientSessionChannelListener>getListeners()ClientSessiongetSession()java.util.List<ClientSessionChannel.MessageListener>getSubscribers()booleanisReleased()default voidpublish(java.lang.Object data)Publishes the givendataonto this channel.voidpublish(java.lang.Object data, ClientSession.MessageListener callback)Publishes the givendataonto this channel, notifying the givencallbackof the publish result, whether successful or unsuccessful.voidpublish(Message.Mutable message, ClientSession.MessageListener callback)Publishes the givenmessageonto this channel, notifying the givencallbackof the publish result.booleanrelease()Releases this channel from itsClientSession.voidremoveListener(ClientSessionChannel.ClientSessionChannelListener listener)Removes the givenlistenerfrom this channel.default booleansubscribe(ClientSessionChannel.MessageListener listener)Equivalent tosubscribe(listener, null).default booleansubscribe(ClientSessionChannel.MessageListener listener, ClientSession.MessageListener callback)Equivalent tosubscribe(null, listener, callback).booleansubscribe(Message.Mutable message, ClientSessionChannel.MessageListener listener, ClientSession.MessageListener callback)Subscribes the givenlistenerto receive messages sent to this channel.voidunsubscribe()Unsubscribes all subscribers registered on this channel.default booleanunsubscribe(ClientSessionChannel.MessageListener listener)Equivalent tounsubscribe(listener, null).default booleanunsubscribe(ClientSessionChannel.MessageListener listener, ClientSession.MessageListener callback)Equivalent tounsubscribe(null, listener, callback).booleanunsubscribe(Message.Mutable message, ClientSessionChannel.MessageListener listener, ClientSession.MessageListener callback)Unsubscribes the givenlistenerfrom receiving messages sent to this channel.-
Methods inherited from interface org.cometd.bayeux.Channel
getAttribute, getAttributeNames, getChannelId, getId, isBroadcast, isDeepWild, isMeta, isService, isWild, removeAttribute, setAttribute
-
-
-
-
Method Detail
-
addListener
void 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.- Parameters:
listener- the listener to add- See Also:
removeListener(ClientSessionChannelListener)
-
removeListener
void removeListener(ClientSessionChannel.ClientSessionChannelListener listener)
Removes the given
listenerfrom this channel.Removing a listener never involves communication with the server, differently from
unsubscribe(MessageListener).- Parameters:
listener- the listener to remove- See Also:
addListener(ClientSessionChannelListener)
-
getListeners
java.util.List<ClientSessionChannel.ClientSessionChannelListener> getListeners()
- Returns:
- an immutable snapshot of the listeners
- See Also:
addListener(ClientSessionChannelListener)
-
getSession
ClientSession getSession()
- Returns:
- the client session associated with this channel
-
publish
default void publish(java.lang.Object data)
Publishes the given
dataonto this channel.The
datapublished 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.- Parameters:
data- the data to publish- See Also:
publish(Object, ClientSession.MessageListener)
-
publish
void publish(java.lang.Object data, ClientSession.MessageListener callback)Publishes the given
dataonto this channel, notifying the givencallbackof the publish result, whether successful or unsuccessful.- Parameters:
data- the data to publishcallback- the message callback to notify of the publish result- See Also:
publish(Object),publish(Message.Mutable, ClientSession.MessageListener)
-
publish
void publish(Message.Mutable message, ClientSession.MessageListener callback)
Publishes the given
messageonto this channel, notifying the givencallbackof the publish result.- Parameters:
message- the message to publishcallback- the message callback to notify of the publish result- See Also:
publish(Object, ClientSession.MessageListener)
-
subscribe
default boolean subscribe(ClientSessionChannel.MessageListener listener)
Equivalent to
subscribe(listener, null).- Parameters:
listener- the listener to register and invoke when a message arrives on this channel.- Returns:
- whether the subscribe message has been sent
-
subscribe
default boolean subscribe(ClientSessionChannel.MessageListener listener, ClientSession.MessageListener callback)
Equivalent to
subscribe(null, listener, callback).- Parameters:
listener- the listener to register and invoke when a message arrives on this channelcallback- the callback to notify of the subscribe result- Returns:
- whether the subscribe message has been sent
-
subscribe
boolean subscribe(Message.Mutable message, ClientSessionChannel.MessageListener listener, ClientSession.MessageListener callback)
Subscribes the given
listenerto 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.
The callback parameter will be invoked upon acknowledgment of the subscription by the server, and therefore only for the first subscription to this channel.
- Parameters:
message- the subscription messagelistener- the listener to register and invoke when a message arrives on this channelcallback- the callback to notify of the subscribe result- Returns:
- whether the subscribe message has been sent
- See Also:
unsubscribe(MessageListener),addListener(ClientSessionChannelListener)
-
unsubscribe
default boolean unsubscribe(ClientSessionChannel.MessageListener listener)
Equivalent to
unsubscribe(listener, null).- Parameters:
listener- the listener to unsubscribe- Returns:
- whether the unsubscribe message has been sent
-
unsubscribe
default boolean unsubscribe(ClientSessionChannel.MessageListener listener, ClientSession.MessageListener callback)
Equivalent to
unsubscribe(null, listener, callback).- Parameters:
listener- the listener to unsubscribecallback- the callback to notify of the unsubscribe result- Returns:
- whether the unsubscribe message has been sent
-
unsubscribe
boolean unsubscribe(Message.Mutable message, ClientSessionChannel.MessageListener listener, ClientSession.MessageListener callback)
Unsubscribes the given
listenerfrom receiving messages sent to this channel.Unsubscription involves communication with the server only for the last listener unsubscribed from this channel.
The callback parameter will be invoked upon acknowledgment of the unsubscription by the server, and therefore only for the last unsubscription from this channel.
- Parameters:
message- the unsubscription messagelistener- the listener to unsubscribecallback- the callback to notify of the unsubscribe result- Returns:
- whether the unsubscribe message has been sent
- See Also:
subscribe(MessageListener),unsubscribe()
-
unsubscribe
void unsubscribe()
Unsubscribes all subscribers registered on this channel.
- See Also:
subscribe(MessageListener)
-
getSubscribers
java.util.List<ClientSessionChannel.MessageListener> getSubscribers()
- Returns:
- an immutable snapshot of the subscribers
- See Also:
subscribe(MessageListener)
-
release
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.
- Returns:
- true if the release was successful, false otherwise
- See Also:
isReleased()
-
isReleased
boolean isReleased()
- Returns:
- whether this channel has been released
- See Also:
release()
-
-