Class AbstractClientSession.AbstractSessionChannel
- java.lang.Object
-
- org.cometd.common.AbstractClientSession.AbstractSessionChannel
-
- All Implemented Interfaces:
Channel
,ClientSessionChannel
,org.eclipse.jetty.util.component.Dumpable
- Direct Known Subclasses:
BayeuxClient.BayeuxClientChannel
,LocalSessionImpl.LocalChannel
- Enclosing class:
- AbstractClientSession
protected abstract class AbstractClientSession.AbstractSessionChannel extends java.lang.Object implements ClientSessionChannel, org.eclipse.jetty.util.component.Dumpable
A channel scoped to a
ClientSession
.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.cometd.bayeux.client.ClientSessionChannel
ClientSessionChannel.ClientSessionChannelListener, ClientSessionChannel.MessageListener
-
-
Field Summary
-
Fields inherited from interface org.cometd.bayeux.Channel
META, META_CONNECT, META_DISCONNECT, META_HANDSHAKE, META_SUBSCRIBE, META_UNSUBSCRIBE, SERVICE
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractSessionChannel(ChannelId id)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addListener(ClientSessionChannel.ClientSessionChannelListener listener)
Adds a listener to this channel.void
dump(java.lang.Appendable out, java.lang.String indent)
java.lang.String
dumpSelf()
java.lang.Object
getAttribute(java.lang.String name)
Retrieves the value of named channel attribute.java.util.Set<java.lang.String>
getAttributeNames()
ChannelId
getChannelId()
java.lang.String
getId()
java.util.List<ClientSessionChannel.ClientSessionChannelListener>
getListeners()
java.util.List<ClientSessionChannel.MessageListener>
getSubscribers()
boolean
isBroadcast()
A broadcasting channel is a channel that is neither ameta channel
nor aservice channel
.boolean
isDeepWild()
Tells whether a channel contains the deep wild characters '**', for example/foo/**
boolean
isMeta()
Tells whether the channel is a meta channel, that is if itsid
starts with"/meta/"
.boolean
isReleased()
boolean
isService()
Tells whether the channel is a service channel, that is if itsid
starts with"/service/"
.boolean
isWild()
Tells whether a channel contains the wild character '*', for example/foo/*
or if it isChannel.isDeepWild()
.protected void
nonFirstSubscribe(Message.Mutable message, ClientSessionChannel.MessageListener listener, ClientSession.MessageListener callback)
protected void
nonLastUnSubscribe(Message.Mutable message, ClientSessionChannel.MessageListener listener, ClientSession.MessageListener callback)
protected void
notifyMessageListeners(Message message)
protected void
notifyOnMessage(ClientSessionChannel.MessageListener listener, Message message)
void
publish(java.lang.Object data, ClientSession.MessageListener callback)
Publishes the givendata
onto this channel, notifying the givencallback
of the publish result, whether successful or unsuccessful.void
publish(Message.Mutable message, ClientSession.MessageListener callback)
Publishes the givenmessage
onto this channel, notifying the givencallback
of the publish result.boolean
release()
Releases this channel from itsClientSession
.java.lang.Object
removeAttribute(java.lang.String name)
Removes a named channel attribute.void
removeListener(ClientSessionChannel.ClientSessionChannelListener listener)
Removes the givenlistener
from this channel.protected void
resetSubscriptions()
protected void
sendSubscribe(Message.Mutable message, ClientSessionChannel.MessageListener listener, ClientSession.MessageListener callback)
protected void
sendUnSubscribe(Message.Mutable message, ClientSession.MessageListener callback)
Deprecated.protected void
sendUnSubscribe(Message.Mutable message, ClientSessionChannel.MessageListener listener, ClientSession.MessageListener callback)
void
setAttribute(java.lang.String name, java.lang.Object value)
Sets a named channel attribute value.boolean
subscribe(Message.Mutable message, ClientSessionChannel.MessageListener listener, ClientSession.MessageListener callback)
Subscribes the givenlistener
to receive messages sent to this channel.protected void
throwIfReleased()
java.lang.String
toString()
void
unsubscribe()
Unsubscribes all subscribers registered on this channel.boolean
unsubscribe(Message.Mutable message, ClientSessionChannel.MessageListener listener, ClientSession.MessageListener callback)
Unsubscribes the givenlistener
from receiving messages sent to this channel.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.cometd.bayeux.client.ClientSessionChannel
getSession, publish, subscribe, subscribe, unsubscribe, unsubscribe
-
-
-
-
Constructor Detail
-
AbstractSessionChannel
protected AbstractSessionChannel(ChannelId id)
-
-
Method Detail
-
getChannelId
public ChannelId getChannelId()
- Specified by:
getChannelId
in interfaceChannel
- Returns:
- The channel ID as a
ChannelId
-
addListener
public void addListener(ClientSessionChannel.ClientSessionChannelListener listener)
Description copied from interface:ClientSessionChannel
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
ClientSessionChannel.subscribe(MessageListener)
.Listeners are best suited to receive messages from
meta channels
.- Specified by:
addListener
in interfaceClientSessionChannel
- Parameters:
listener
- the listener to add- See Also:
ClientSessionChannel.removeListener(ClientSessionChannelListener)
-
removeListener
public void removeListener(ClientSessionChannel.ClientSessionChannelListener listener)
Description copied from interface:ClientSessionChannel
Removes the given
listener
from this channel.Removing a listener never involves communication with the server, differently from
ClientSessionChannel.unsubscribe(MessageListener)
.- Specified by:
removeListener
in interfaceClientSessionChannel
- Parameters:
listener
- the listener to remove- See Also:
ClientSessionChannel.addListener(ClientSessionChannelListener)
-
getListeners
public java.util.List<ClientSessionChannel.ClientSessionChannelListener> getListeners()
- Specified by:
getListeners
in interfaceClientSessionChannel
- Returns:
- an immutable snapshot of the listeners
- See Also:
ClientSessionChannel.addListener(ClientSessionChannelListener)
-
publish
public void publish(java.lang.Object data, ClientSession.MessageListener callback)
Description copied from interface:ClientSessionChannel
Publishes the given
data
onto this channel, notifying the givencallback
of the publish result, whether successful or unsuccessful.- Specified by:
publish
in interfaceClientSessionChannel
- Parameters:
data
- the data to publishcallback
- the message callback to notify of the publish result- See Also:
ClientSessionChannel.publish(Object)
,ClientSessionChannel.publish(Message.Mutable, ClientSession.MessageListener)
-
publish
public void publish(Message.Mutable message, ClientSession.MessageListener callback)
Description copied from interface:ClientSessionChannel
Publishes the given
message
onto this channel, notifying the givencallback
of the publish result.- Specified by:
publish
in interfaceClientSessionChannel
- Parameters:
message
- the message to publishcallback
- the message callback to notify of the publish result- See Also:
ClientSessionChannel.publish(Object, ClientSession.MessageListener)
-
subscribe
public boolean subscribe(Message.Mutable message, ClientSessionChannel.MessageListener listener, ClientSession.MessageListener callback)
Description copied from interface:ClientSessionChannel
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.
The callback parameter will be invoked upon acknowledgment of the subscription by the server, and therefore only for the first subscription to this channel.
- Specified by:
subscribe
in interfaceClientSessionChannel
- 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:
ClientSessionChannel.unsubscribe(MessageListener)
,ClientSessionChannel.addListener(ClientSessionChannelListener)
-
sendSubscribe
protected void sendSubscribe(Message.Mutable message, ClientSessionChannel.MessageListener listener, ClientSession.MessageListener callback)
-
nonFirstSubscribe
protected void nonFirstSubscribe(Message.Mutable message, ClientSessionChannel.MessageListener listener, ClientSession.MessageListener callback)
-
unsubscribe
public boolean unsubscribe(Message.Mutable message, ClientSessionChannel.MessageListener listener, ClientSession.MessageListener callback)
Description copied from interface:ClientSessionChannel
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.
The callback parameter will be invoked upon acknowledgment of the unsubscription by the server, and therefore only for the last unsubscription from this channel.
- Specified by:
unsubscribe
in interfaceClientSessionChannel
- 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:
ClientSessionChannel.subscribe(MessageListener)
,ClientSessionChannel.unsubscribe()
-
sendUnSubscribe
protected void sendUnSubscribe(Message.Mutable message, ClientSessionChannel.MessageListener listener, ClientSession.MessageListener callback)
-
sendUnSubscribe
@Deprecated protected void sendUnSubscribe(Message.Mutable message, ClientSession.MessageListener callback)
Deprecated.
-
nonLastUnSubscribe
protected void nonLastUnSubscribe(Message.Mutable message, ClientSessionChannel.MessageListener listener, ClientSession.MessageListener callback)
-
unsubscribe
public void unsubscribe()
Description copied from interface:ClientSessionChannel
Unsubscribes all subscribers registered on this channel.
- Specified by:
unsubscribe
in interfaceClientSessionChannel
- See Also:
ClientSessionChannel.subscribe(MessageListener)
-
getSubscribers
public java.util.List<ClientSessionChannel.MessageListener> getSubscribers()
- Specified by:
getSubscribers
in interfaceClientSessionChannel
- Returns:
- an immutable snapshot of the subscribers
- See Also:
ClientSessionChannel.subscribe(MessageListener)
-
release
public boolean release()
Description copied from interface:ClientSessionChannel
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.
- Specified by:
release
in interfaceClientSessionChannel
- Returns:
- true if the release was successful, false otherwise
- See Also:
ClientSessionChannel.isReleased()
-
isReleased
public boolean isReleased()
- Specified by:
isReleased
in interfaceClientSessionChannel
- Returns:
- whether this channel has been released
- See Also:
ClientSessionChannel.release()
-
resetSubscriptions
protected void resetSubscriptions()
-
getId
public java.lang.String getId()
-
isDeepWild
public boolean isDeepWild()
Description copied from interface:Channel
Tells whether a channel contains the deep wild characters '**', for example
/foo/**
- Specified by:
isDeepWild
in interfaceChannel
- Returns:
- true if the channel contains the '**' characters
-
isMeta
public boolean isMeta()
Description copied from interface:Channel
Tells whether the channel is a meta channel, that is if its
id
starts with"/meta/"
.
-
isService
public boolean isService()
Description copied from interface:Channel
Tells whether the channel is a service channel, that is if its
id
starts with"/service/"
.
-
isBroadcast
public boolean isBroadcast()
Description copied from interface:Channel
A broadcasting channel is a channel that is neither a
meta channel
nor aservice channel
.- Specified by:
isBroadcast
in interfaceChannel
- Returns:
- whether the channel is a broadcasting channel
-
isWild
public boolean isWild()
Description copied from interface:Channel
Tells whether a channel contains the wild character '*', for example
/foo/*
or if it isChannel.isDeepWild()
.
-
notifyMessageListeners
protected void notifyMessageListeners(Message message)
-
notifyOnMessage
protected void notifyOnMessage(ClientSessionChannel.MessageListener listener, Message message)
-
setAttribute
public void setAttribute(java.lang.String name, java.lang.Object value)
Description copied from interface:Channel
Sets a named channel attribute value.
Channel attributes are convenience data that allows arbitrary application data to be associated with a channel.
- Specified by:
setAttribute
in interfaceChannel
- Parameters:
name
- the attribute namevalue
- the attribute value
-
getAttribute
public java.lang.Object getAttribute(java.lang.String name)
Description copied from interface:Channel
Retrieves the value of named channel attribute.
- Specified by:
getAttribute
in interfaceChannel
- Parameters:
name
- the name of the attribute- Returns:
- the attribute value or null if the attribute is not present
-
getAttributeNames
public java.util.Set<java.lang.String> getAttributeNames()
- Specified by:
getAttributeNames
in interfaceChannel
- Returns:
- the list of channel attribute names.
-
removeAttribute
public java.lang.Object removeAttribute(java.lang.String name)
Description copied from interface:Channel
Removes a named channel attribute.
- Specified by:
removeAttribute
in interfaceChannel
- Parameters:
name
- the name of the attribute- Returns:
- the value of the attribute
-
throwIfReleased
protected void throwIfReleased()
-
dumpSelf
public java.lang.String dumpSelf()
- Specified by:
dumpSelf
in interfaceorg.eclipse.jetty.util.component.Dumpable
-
dump
public void dump(java.lang.Appendable out, java.lang.String indent) throws java.io.IOException
- Specified by:
dump
in interfaceorg.eclipse.jetty.util.component.Dumpable
- Throws:
java.io.IOException
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-