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 protected
ServerChannelImpl(BayeuxServerImpl bayeux, ChannelId id)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addAuthorizer(Authorizer authorizer)
Adds the givenAuthorizer
that grants or denies operations on this channel.void
addListener(ConfigurableServerChannel.ServerChannelListener listener)
protected java.util.List<Authorizer>
authorizers()
void
dump(java.lang.Appendable out, java.lang.String indent)
java.lang.Object
getAttribute(java.lang.String name)
Retrieves the value of named channel attribute.java.util.Set<java.lang.String>
getAttributeNames()
java.util.List<Authorizer>
getAuthorizers()
ChannelId
getChannelId()
java.lang.String
getId()
long
getLazyTimeout()
java.util.List<ConfigurableServerChannel.ServerChannelListener>
getListeners()
java.util.Set<ServerSession>
getSubscribers()
boolean
isBroadcast()
A broadcasting channel is a channel that is neither ameta channel
nor aservice channel
.boolean
isBroadcastToPublisher()
boolean
isDeepWild()
Tells whether a channel contains the deep wild characters '**', for example/foo/**
boolean
isLazy()
boolean
isMeta()
Tells whether the channel is a meta channel, that is if itsid
starts with"/meta/"
.boolean
isPersistent()
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 java.util.List<ConfigurableServerChannel.ServerChannelListener>
listeners()
void
publish(Session from, java.lang.Object data, Promise<java.lang.Boolean> promise)
Publishes the given information to this channel.void
publish(Session from, ServerMessage.Mutable mutable, Promise<java.lang.Boolean> promise)
Publishes the given message to this channel, delivering the message to all theServerSession
s subscribed to this channel.void
remove()
Removes this channel, and all the children channels.java.lang.Object
removeAttribute(java.lang.String name)
Removes a named channel attribute.void
removeAuthorizer(Authorizer authorizer)
Removes the givenAuthorizer
.void
removeListener(ConfigurableServerChannel.ServerChannelListener listener)
void
setAttribute(java.lang.String name, java.lang.Object value)
Sets a named channel attribute value.void
setBroadcastToPublisher(boolean broadcastToPublisher)
Sets whether a publisher that is also a subscriber to the channel will receive the messages it publishes on that channel.void
setLazy(boolean lazy)
A lazy channel marks all messages published to it as lazy.void
setLazyTimeout(long lazyTimeout)
Sets the lazy timeout for this channel.void
setPersistent(boolean persistent)
A persistent channel is not removed when the last subscription is removedboolean
subscribe(ServerSession session)
Subscribes the given session to this channel.protected boolean
subscribe(ServerSessionImpl session, ServerMessage message)
java.util.Set<ServerSession>
subscribers()
protected boolean
sweep()
java.lang.String
toString()
boolean
unsubscribe(ServerSession session)
Unsubscribes the given session from this channel.protected boolean
unsubscribe(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:ServerChannel
Subscribes the given session to this channel.
Subscriptions are effective for
broadcast channels
and 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:
subscribe
in 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:ServerChannel
Unsubscribes the given session from this channel.
Unsubscriptions are effective for
broadcast channels
and 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:
unsubscribe
in 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:
getSubscribers
in 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: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
-
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
-
isLazy
public boolean isLazy()
- Specified by:
isLazy
in interfaceConfigurableServerChannel
- Returns:
- whether the channel is lazy
- See Also:
ConfigurableServerChannel.setLazy(boolean)
-
isPersistent
public boolean isPersistent()
- Specified by:
isPersistent
in interfaceConfigurableServerChannel
- Returns:
- whether the channel is persistent
- See Also:
ConfigurableServerChannel.setPersistent(boolean)
-
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()
.
-
setLazy
public void setLazy(boolean lazy)
Description copied from interface:ConfigurableServerChannel
A lazy channel marks all messages published to it as lazy.- Specified by:
setLazy
in interfaceConfigurableServerChannel
- Parameters:
lazy
- whether the channel is lazy- See Also:
ConfigurableServerChannel.isLazy()
-
getLazyTimeout
public long getLazyTimeout()
- Specified by:
getLazyTimeout
in interfaceConfigurableServerChannel
- Returns:
- the lazy timeout for this channel
- See Also:
ConfigurableServerChannel.setLazyTimeout(long)
-
setLazyTimeout
public void setLazyTimeout(long lazyTimeout)
Description copied from interface:ConfigurableServerChannel
Sets the lazy timeout for this channel. A positive value makes the channel lazy, a negative value makes the channel non-lazy.- Specified by:
setLazyTimeout
in interfaceConfigurableServerChannel
- Parameters:
lazyTimeout
- the lazy timeout for this channel- See Also:
ConfigurableServerChannel.setLazy(boolean)
-
setPersistent
public void setPersistent(boolean persistent)
Description copied from interface:ConfigurableServerChannel
A persistent channel is not removed when the last subscription is removed- Specified by:
setPersistent
in interfaceConfigurableServerChannel
- Parameters:
persistent
- whether the channel is persistent- See Also:
ConfigurableServerChannel.isPersistent()
-
addListener
public void addListener(ConfigurableServerChannel.ServerChannelListener listener)
- Specified by:
addListener
in interfaceConfigurableServerChannel
- Parameters:
listener
- the listener to add- See Also:
ConfigurableServerChannel.removeListener(ServerChannelListener)
-
isBroadcastToPublisher
public boolean isBroadcastToPublisher()
- Specified by:
isBroadcastToPublisher
in interfaceConfigurableServerChannel
- Returns:
- whether the channel broadcasts messages back to the publisher
-
setBroadcastToPublisher
public void setBroadcastToPublisher(boolean broadcastToPublisher)
Description copied from interface:ConfigurableServerChannel
Sets whether a publisher that is also a subscriber to the channel will receive the messages it publishes on that channel.- Specified by:
setBroadcastToPublisher
in interfaceConfigurableServerChannel
- Parameters:
broadcastToPublisher
- whether the channel broadcasts messages back to the publisher
-
removeListener
public void removeListener(ConfigurableServerChannel.ServerChannelListener listener)
- Specified by:
removeListener
in interfaceConfigurableServerChannel
- Parameters:
listener
- the listener to remove- See Also:
ConfigurableServerChannel.addListener(ServerChannelListener)
-
getListeners
public java.util.List<ConfigurableServerChannel.ServerChannelListener> getListeners()
- Specified by:
getListeners
in 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:
getChannelId
in interfaceChannel
- Returns:
- The channel ID as a
ChannelId
-
getId
public java.lang.String getId()
-
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/"
.
-
publish
public void publish(Session from, ServerMessage.Mutable mutable, Promise<java.lang.Boolean> promise)
Description copied from interface:ServerChannel
Publishes the given message to this channel, delivering the message to all the
ServerSession
s subscribed to this channel.- Specified by:
publish
in 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:ServerChannel
Publishes the given information to this channel.
- Specified by:
publish
in 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:ServerChannel
Removes 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.ChannelListener
listeners.- Specified by:
remove
in interfaceServerChannel
-
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
-
addAuthorizer
public void addAuthorizer(Authorizer authorizer)
Description copied from interface:ConfigurableServerChannel
Adds the given
Authorizer
that 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:
addAuthorizer
in interfaceConfigurableServerChannel
- Parameters:
authorizer
- the Authorizer to add- See Also:
ConfigurableServerChannel.removeAuthorizer(Authorizer)
,Authorizer
-
removeAuthorizer
public void removeAuthorizer(Authorizer authorizer)
Description copied from interface:ConfigurableServerChannel
Removes the given
Authorizer
.- Specified by:
removeAuthorizer
in interfaceConfigurableServerChannel
- Parameters:
authorizer
- the Authorizer to remove- See Also:
ConfigurableServerChannel.addAuthorizer(Authorizer)
-
getAuthorizers
public java.util.List<Authorizer> getAuthorizers()
- Specified by:
getAuthorizers
in 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:
dump
in interfaceorg.eclipse.jetty.util.component.Dumpable
- Throws:
java.io.IOException
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-