Interface BayeuxServer
- All Superinterfaces:
Bayeux
- All Known Implementing Classes:
BayeuxServerImpl
The server-side Bayeux interface.
An instance of the BayeuxServer
interface is available
by default to web applications via the "org.cometd.bayeux" attribute
of the web application context (for Servlet environments,
the javax.servlet.ServletContext
).
The context attribute name can be configured as an option.
The BayeuxServer
APIs give access to the
ServerSession
s via the getSession(String)
method. It also allows new LocalSession
to be
created within the server using the newLocalSession(String)
method.
ServerChannel
instances may be accessed via the
getChannel(String)
method, but the server has
no direct relationship with ClientSessionChannel
s or
ClientSession
.
If subscription semantics is required, then
the newLocalSession(String)
method should be used to
create a LocalSession
that can subscribe and publish
like a client-side Bayeux session.
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic interface
Common base interface for all server-side Bayeux listeners.static interface
Specialized listener forServerChannel
events.static interface
Extension API forBayeuxServer
.static interface
Specialized listener forServerSession
events.static interface
Specialized listener forServerChannel
subscription events.Nested classes/interfaces inherited from interface org.cometd.bayeux.Bayeux
Bayeux.BayeuxListener, Bayeux.Validator
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addExtension
(BayeuxServer.Extension extension) Adds the given extension to this Bayeux object.void
addListener
(BayeuxServer.BayeuxServerListener listener) Adds a listener to this Bayeux object.createChannelIfAbsent
(String channelName, ConfigurableServerChannel.Initializer... initializers) Creates aServerChannel
and initializes it atomically if the channel does not exist, or returns it if it already exists.getChannel
(String channelId) getSession
(String clientId) getTransport
(String transport) newLocalSession
(String idHint) Creates a newLocalSession
.void
removeExtension
(BayeuxServer.Extension extension) Removes the given extension from this Bayeux object.void
Removes a listener from this Bayeux object.boolean
removeSession
(ServerSession session) Removes the givensession
from this BayeuxServer.void
setSecurityPolicy
(SecurityPolicy securityPolicy) Methods inherited from interface org.cometd.bayeux.Bayeux
getAllowedTransports, getKnownTransportNames, getOption, getOptionNames, setOption
-
Field Details
-
ATTRIBUTE
ServletContext attribute name used to obtain the Bayeux object- See Also:
-
-
Method Details
-
getTransport
- Specified by:
getTransport
in interfaceBayeux
- Parameters:
transport
- the transport name- Returns:
- the transport with the given name or null if no such transport exist
-
addExtension
Adds the given extension to this Bayeux object.
- Parameters:
extension
- the extension to add- See Also:
-
removeExtension
Removes the given extension from this Bayeux object.
- Parameters:
extension
- the extension to remove- See Also:
-
getExtensions
List<BayeuxServer.Extension> getExtensions()- Returns:
- an immutable list of extensions present in this BayeuxServer instance
- See Also:
-
addListener
Adds a listener to this Bayeux object.
- Parameters:
listener
- the listener to add- See Also:
-
removeListener
Removes a listener from this Bayeux object.
- Parameters:
listener
- the listener to remove- See Also:
-
getChannel
- Parameters:
channelId
- the channel identifier- Returns:
- a
ServerChannel
with the givenchannelId
, or null if no such channel exists - See Also:
-
getChannels
List<ServerChannel> getChannels()- Returns:
- the list of channels known to this BayeuxServer object
-
createChannelIfAbsent
MarkedReference<ServerChannel> createChannelIfAbsent(String channelName, ConfigurableServerChannel.Initializer... initializers) Creates a
ServerChannel
and initializes it atomically if the channel does not exist, or returns it if it already exists.This method can be used instead of adding a
BayeuxServer.ChannelListener
to atomically initialize a channel. Theinitializers
will be called before any other thread can access the new channel instance.This method should be used when a channel needs to be initialized (e.g. by adding listeners) before any publish or subscribes can occur on the channel, or before any other thread may concurrently create the same channel.
- Parameters:
channelName
- the channel nameinitializers
- the initializers invoked to configure the channel- Returns:
- a
MarkedReference
whose reference is the channel, and the mark signals whether the channel has been created because it did not exist before.
-
getSession
- Parameters:
clientId
- theServerSession
identifier- Returns:
- the
ServerSession
with the givenclientId
or null if no such valid session exists.
-
getSessions
List<ServerSession> getSessions()- Returns:
- the list of
ServerSession
s known to this BayeuxServer object
-
removeSession
Removes the given
session
from this BayeuxServer.This method triggers the invocation of all listeners that would be called if the session was disconnected or if the session timed out.
- Parameters:
session
- the session to remove- Returns:
- true if the session was known to this BayeuxServer and was removed
-
newLocalSession
Creates a new
LocalSession
.A
LocalSession
is a server-side ClientSession that allows server-side code to have special clients (resident within the same JVM) that can be used to publish and subscribe like a client-side session would do.- Parameters:
idHint
- a hint to be included in the unique clientId of the session.- Returns:
- a new
LocalSession
-
newMessage
ServerMessage.Mutable newMessage()- Returns:
- a new or recycled mutable message instance.
-
getSecurityPolicy
SecurityPolicy getSecurityPolicy()- Returns:
- the
SecurityPolicy
associated with this session - See Also:
-
setSecurityPolicy
- Parameters:
securityPolicy
- theSecurityPolicy
associated with this session- See Also:
-