Class ServerChannelImpl
- java.lang.Object
-
- org.cometd.server.ServerChannelImpl
-
- All Implemented Interfaces:
Channel,ConfigurableServerChannel,ServerChannel,org.eclipse.jetty.util.component.Dumpable
public class ServerChannelImpl extends java.lang.Object implements ServerChannel, org.eclipse.jetty.util.component.Dumpable
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.cometd.bayeux.server.ConfigurableServerChannel
ConfigurableServerChannel.Initializer, ConfigurableServerChannel.ServerChannelListener
-
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Dumpable
org.eclipse.jetty.util.component.Dumpable.DumpableContainer
-
Nested classes/interfaces inherited from interface org.cometd.bayeux.server.ServerChannel
ServerChannel.MessageListener, ServerChannel.SubscriptionListener
-
-
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 protectedServerChannelImpl(BayeuxServerImpl bayeux, ChannelId id)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddAuthorizer(Authorizer authorizer)Adds the givenAuthorizerthat grants or denies operations on this channel.voidaddListener(ConfigurableServerChannel.ServerChannelListener listener)protected java.util.List<Authorizer>authorizers()voiddump(java.lang.Appendable out, java.lang.String indent)java.lang.ObjectgetAttribute(java.lang.String name)Retrieves the value of named channel attribute.java.util.Set<java.lang.String>getAttributeNames()java.util.List<Authorizer>getAuthorizers()ChannelIdgetChannelId()java.lang.StringgetId()longgetLazyTimeout()java.util.List<ConfigurableServerChannel.ServerChannelListener>getListeners()java.util.Set<ServerSession>getSubscribers()booleanisBroadcast()A broadcasting channel is a channel that is neither ameta channelnor aservice channel.booleanisBroadcastToPublisher()booleanisDeepWild()Tells whether a channel contains the deep wild characters '**', for example/foo/**booleanisLazy()booleanisMeta()Tells whether the channel is a meta channel, that is if itsidstarts with"/meta/".booleanisPersistent()booleanisService()Tells whether the channel is a service channel, that is if itsidstarts with"/service/".booleanisWild()Tells whether a channel contains the wild character '*', for example/foo/*or if it isChannel.isDeepWild().protected java.util.List<ConfigurableServerChannel.ServerChannelListener>listeners()voidpublish(Session from, java.lang.Object data, Promise<java.lang.Boolean> promise)Publishes the given information to this channel.voidpublish(Session from, ServerMessage.Mutable mutable, Promise<java.lang.Boolean> promise)Publishes the given message to this channel, delivering the message to all theServerSessions subscribed to this channel.voidremove()Removes this channel, and all the children channels.java.lang.ObjectremoveAttribute(java.lang.String name)Removes a named channel attribute.voidremoveAuthorizer(Authorizer authorizer)Removes the givenAuthorizer.voidremoveListener(ConfigurableServerChannel.ServerChannelListener listener)voidsetAttribute(java.lang.String name, java.lang.Object value)Sets a named channel attribute value.voidsetBroadcastToPublisher(boolean broadcastToPublisher)Sets whether a publisher that is also a subscriber to the channel will receive the messages it publishes on that channel.voidsetLazy(boolean lazy)A lazy channel marks all messages published to it as lazy.voidsetLazyTimeout(long lazyTimeout)Sets the lazy timeout for this channel.voidsetPersistent(boolean persistent)A persistent channel is not removed when the last subscription is removedbooleansubscribe(ServerSession session)Subscribes the given session to this channel.protected booleansubscribe(ServerSessionImpl session, ServerMessage message)java.util.Set<ServerSession>subscribers()protected booleansweep()java.lang.StringtoString()booleanunsubscribe(ServerSession session)Unsubscribes the given session from this channel.protected booleanunsubscribe(ServerSessionImpl session, ServerMessage message)
-
-
-
Constructor Detail
-
ServerChannelImpl
protected ServerChannelImpl(BayeuxServerImpl bayeux, ChannelId id)
-
-
Method Detail
-
subscribe
public boolean subscribe(ServerSession session)
Description copied from interface:ServerChannelSubscribes the given session to this channel.
Subscriptions are effective for
broadcast channelsand are successful no-operations forservice channels.The subscription may fail if the session is already subscribed to the channel or if the session is expired or if the channel is a meta channel.
- Specified by:
subscribein interfaceServerChannel- Parameters:
session- the session to subscribe- Returns:
- whether the subscription succeeded
- See Also:
ServerChannel.unsubscribe(ServerSession)
-
subscribe
protected boolean subscribe(ServerSessionImpl session, ServerMessage message)
-
unsubscribe
public boolean unsubscribe(ServerSession session)
Description copied from interface:ServerChannelUnsubscribes the given session from this channel.
Unsubscriptions are effective for
broadcast channelsand are successful no-operations forservice channels.The unsubscription may fail if the session is already unsubscribed from the channel or if the session is expired or if the channel is a meta channel.
- Specified by:
unsubscribein interfaceServerChannel- Parameters:
session- the session to unsubscribe- Returns:
- whether the unsubscription succeeded
-
unsubscribe
protected boolean unsubscribe(ServerSessionImpl session, ServerMessage message)
-
getSubscribers
public java.util.Set<ServerSession> getSubscribers()
- Specified by:
getSubscribersin interfaceServerChannel- Returns:
- a snapshot of the set of subscribers of this channel
-
subscribers
public java.util.Set<ServerSession> subscribers()
-
isBroadcast
public boolean isBroadcast()
Description copied from interface:ChannelA broadcasting channel is a channel that is neither a
meta channelnor aservice channel.- Specified by:
isBroadcastin interfaceChannel- Returns:
- whether the channel is a broadcasting channel
-
isDeepWild
public boolean isDeepWild()
Description copied from interface:ChannelTells whether a channel contains the deep wild characters '**', for example
/foo/**- Specified by:
isDeepWildin interfaceChannel- Returns:
- true if the channel contains the '**' characters
-
isLazy
public boolean isLazy()
- Specified by:
isLazyin interfaceConfigurableServerChannel- Returns:
- whether the channel is lazy
- See Also:
ConfigurableServerChannel.setLazy(boolean)
-
isPersistent
public boolean isPersistent()
- Specified by:
isPersistentin interfaceConfigurableServerChannel- Returns:
- whether the channel is persistent
- See Also:
ConfigurableServerChannel.setPersistent(boolean)
-
isWild
public boolean isWild()
Description copied from interface:ChannelTells whether a channel contains the wild character '*', for example
/foo/*or if it isChannel.isDeepWild().
-
setLazy
public void setLazy(boolean lazy)
Description copied from interface:ConfigurableServerChannelA lazy channel marks all messages published to it as lazy.- Specified by:
setLazyin interfaceConfigurableServerChannel- Parameters:
lazy- whether the channel is lazy- See Also:
ConfigurableServerChannel.isLazy()
-
getLazyTimeout
public long getLazyTimeout()
- Specified by:
getLazyTimeoutin interfaceConfigurableServerChannel- Returns:
- the lazy timeout for this channel
- See Also:
ConfigurableServerChannel.setLazyTimeout(long)
-
setLazyTimeout
public void setLazyTimeout(long lazyTimeout)
Description copied from interface:ConfigurableServerChannelSets the lazy timeout for this channel. A positive value makes the channel lazy, a negative value makes the channel non-lazy.- Specified by:
setLazyTimeoutin interfaceConfigurableServerChannel- Parameters:
lazyTimeout- the lazy timeout for this channel- See Also:
ConfigurableServerChannel.setLazy(boolean)
-
setPersistent
public void setPersistent(boolean persistent)
Description copied from interface:ConfigurableServerChannelA persistent channel is not removed when the last subscription is removed- Specified by:
setPersistentin interfaceConfigurableServerChannel- Parameters:
persistent- whether the channel is persistent- See Also:
ConfigurableServerChannel.isPersistent()
-
addListener
public void addListener(ConfigurableServerChannel.ServerChannelListener listener)
- Specified by:
addListenerin interfaceConfigurableServerChannel- Parameters:
listener- the listener to add- See Also:
ConfigurableServerChannel.removeListener(ServerChannelListener)
-
isBroadcastToPublisher
public boolean isBroadcastToPublisher()
- Specified by:
isBroadcastToPublisherin interfaceConfigurableServerChannel- Returns:
- whether the channel broadcasts messages back to the publisher
-
setBroadcastToPublisher
public void setBroadcastToPublisher(boolean broadcastToPublisher)
Description copied from interface:ConfigurableServerChannelSets whether a publisher that is also a subscriber to the channel will receive the messages it publishes on that channel.- Specified by:
setBroadcastToPublisherin interfaceConfigurableServerChannel- Parameters:
broadcastToPublisher- whether the channel broadcasts messages back to the publisher
-
removeListener
public void removeListener(ConfigurableServerChannel.ServerChannelListener listener)
- Specified by:
removeListenerin interfaceConfigurableServerChannel- Parameters:
listener- the listener to remove- See Also:
ConfigurableServerChannel.addListener(ServerChannelListener)
-
getListeners
public java.util.List<ConfigurableServerChannel.ServerChannelListener> getListeners()
- Specified by:
getListenersin interfaceConfigurableServerChannel- Returns:
- an immutable list of listeners
- See Also:
ConfigurableServerChannel.addListener(ServerChannelListener)
-
listeners
protected java.util.List<ConfigurableServerChannel.ServerChannelListener> listeners()
-
getChannelId
public ChannelId getChannelId()
- Specified by:
getChannelIdin interfaceChannel- Returns:
- The channel ID as a
ChannelId
-
getId
public java.lang.String getId()
-
isMeta
public boolean isMeta()
Description copied from interface:ChannelTells whether the channel is a meta channel, that is if its
idstarts with"/meta/".
-
isService
public boolean isService()
Description copied from interface:ChannelTells whether the channel is a service channel, that is if its
idstarts with"/service/".
-
publish
public void publish(Session from, ServerMessage.Mutable mutable, Promise<java.lang.Boolean> promise)
Description copied from interface:ServerChannelPublishes the given message to this channel, delivering the message to all the
ServerSessions subscribed to this channel.- Specified by:
publishin interfaceServerChannel- Parameters:
from- the session from which the message originatesmutable- the message to publishpromise- the promise to notify whether the message has been published- See Also:
ServerChannel.publish(Session, Object, Promise)
-
publish
public void publish(Session from, java.lang.Object data, Promise<java.lang.Boolean> promise)
Description copied from interface:ServerChannelPublishes the given information to this channel.
- Specified by:
publishin interfaceServerChannel- Parameters:
from- the session from which the message originatesdata- the data of the messagepromise- the promise to notify whether the message has been published- See Also:
ServerChannel.publish(Session, ServerMessage.Mutable, Promise)
-
sweep
protected boolean sweep()
-
remove
public void remove()
Description copied from interface:ServerChannelRemoves this channel, and all the children channels.
If channel "/foo", "/foo/bar" and "/foo/blip" exist, removing channel "/foo" will remove also "/foo/bar" and "/foo/blip".
The removal will notify
BayeuxServer.ChannelListenerlisteners.- Specified by:
removein interfaceServerChannel
-
setAttribute
public void setAttribute(java.lang.String name, java.lang.Object value)Description copied from interface:ChannelSets a named channel attribute value.
Channel attributes are convenience data that allows arbitrary application data to be associated with a channel.
- Specified by:
setAttributein interfaceChannel- Parameters:
name- the attribute namevalue- the attribute value
-
getAttribute
public java.lang.Object getAttribute(java.lang.String name)
Description copied from interface:ChannelRetrieves the value of named channel attribute.
- Specified by:
getAttributein 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:
getAttributeNamesin interfaceChannel- Returns:
- the list of channel attribute names.
-
removeAttribute
public java.lang.Object removeAttribute(java.lang.String name)
Description copied from interface:ChannelRemoves a named channel attribute.
- Specified by:
removeAttributein interfaceChannel- Parameters:
name- the name of the attribute- Returns:
- the value of the attribute
-
addAuthorizer
public void addAuthorizer(Authorizer authorizer)
Description copied from interface:ConfigurableServerChannelAdds the given
Authorizerthat grants or denies operations on this channel.Operations must be granted by at least one Authorizer and must not be denied by any.
- Specified by:
addAuthorizerin interfaceConfigurableServerChannel- Parameters:
authorizer- the Authorizer to add- See Also:
ConfigurableServerChannel.removeAuthorizer(Authorizer),Authorizer
-
removeAuthorizer
public void removeAuthorizer(Authorizer authorizer)
Description copied from interface:ConfigurableServerChannelRemoves the given
Authorizer.- Specified by:
removeAuthorizerin interfaceConfigurableServerChannel- Parameters:
authorizer- the Authorizer to remove- See Also:
ConfigurableServerChannel.addAuthorizer(Authorizer)
-
getAuthorizers
public java.util.List<Authorizer> getAuthorizers()
- Specified by:
getAuthorizersin interfaceConfigurableServerChannel- Returns:
- an immutable list of authorizers for this channel
-
authorizers
protected java.util.List<Authorizer> authorizers()
-
dump
public void dump(java.lang.Appendable out, java.lang.String indent) throws java.io.IOException- Specified by:
dumpin interfaceorg.eclipse.jetty.util.component.Dumpable- Throws:
java.io.IOException
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-