Class BayeuxServerImpl
- java.lang.Object
-
- org.eclipse.jetty.util.component.AbstractLifeCycle
-
- org.eclipse.jetty.util.component.ContainerLifeCycle
-
- org.cometd.server.BayeuxServerImpl
-
- All Implemented Interfaces:
Bayeux
,BayeuxServer
,org.eclipse.jetty.util.component.Container
,org.eclipse.jetty.util.component.Destroyable
,org.eclipse.jetty.util.component.Dumpable
,org.eclipse.jetty.util.component.Dumpable.DumpableContainer
,org.eclipse.jetty.util.component.LifeCycle
@ManagedObject("The CometD server") public class BayeuxServerImpl extends org.eclipse.jetty.util.component.ContainerLifeCycle implements BayeuxServer, org.eclipse.jetty.util.component.Dumpable
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
org.eclipse.jetty.util.component.AbstractLifeCycle.AbstractLifeCycleListener, org.eclipse.jetty.util.component.AbstractLifeCycle.StopException
-
Nested classes/interfaces inherited from interface org.cometd.bayeux.Bayeux
Bayeux.BayeuxListener, Bayeux.Validator
-
Nested classes/interfaces inherited from interface org.cometd.bayeux.server.BayeuxServer
BayeuxServer.BayeuxServerListener, BayeuxServer.ChannelListener, BayeuxServer.Extension, BayeuxServer.SessionListener, BayeuxServer.SubscriptionListener
-
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Container
org.eclipse.jetty.util.component.Container.InheritedListener, org.eclipse.jetty.util.component.Container.Listener
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
ALLOWED_TRANSPORTS_OPTION
static java.lang.String
BROADCAST_TO_PUBLISHER_OPTION
static java.lang.String
EXECUTOR_MAX_THREADS
static java.lang.String
SCHEDULER_THREADS
static java.lang.String
SWEEP_PERIOD_OPTION
static java.lang.String
SWEEP_THREADS_OPTION
static java.lang.String
TRANSPORTS_OPTION
static java.lang.String
VALIDATE_MESSAGE_FIELDS_OPTION
-
Fields inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
FAILED, STARTED, STARTING, STOPPED, STOPPING
-
Fields inherited from interface org.cometd.bayeux.server.BayeuxServer
ATTRIBUTE
-
-
Constructor Summary
Constructors Constructor Description BayeuxServerImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addExtension(BayeuxServer.Extension extension)
Adds the given extension to this Bayeux object.void
addListener(BayeuxServer.BayeuxServerListener listener)
Adds a listener to this Bayeux object.protected void
addServerSession(ServerSessionImpl session, ServerMessage message)
ServerTransport
addTransport(ServerTransport transport)
MarkedReference<ServerChannel>
createChannelIfAbsent(java.lang.String channelName, ConfigurableServerChannel.Initializer... initializers)
Creates aServerChannel
and initializes it atomically if the channel does not exist, or returns it if it already exists.protected ServerMessage.Mutable
createReply(ServerMessage.Mutable message)
protected void
doStart()
protected void
doStop()
void
dump(java.lang.Appendable out, java.lang.String indent)
protected void
error(ServerMessage.Mutable reply, java.lang.String error)
void
execute(java.lang.Runnable job)
protected void
extendOutgoing(ServerSession sender, ServerSession session, ServerMessage.Mutable message, Promise<java.lang.Boolean> promise)
void
extendReply(ServerSessionImpl sender, ServerSessionImpl session, ServerMessage.Mutable reply, Promise<ServerMessage.Mutable> promise)
protected AbstractHttpTransport
findHttpTransport(javax.servlet.http.HttpServletRequest request)
void
freeze(ServerMessage.Mutable mutable)
java.util.List<java.lang.String>
getAllowedTransports()
ServerChannel
getChannel(java.lang.String channelId)
java.util.List<ServerChannel>
getChannels()
java.util.concurrent.Executor
getExecutor()
java.util.List<BayeuxServer.Extension>
getExtensions()
JSONContextServer
getJSONContext()
java.util.Set<java.lang.String>
getKnownTransportNames()
java.util.Map<java.lang.String,java.lang.Object>
getLastSweepInfo()
protected java.util.List<BayeuxServer.BayeuxServerListener>
getListeners()
java.util.Map<java.lang.String,java.lang.Object>
getLongestSweepInfo()
java.lang.String
getName()
java.lang.Object
getOption(java.lang.String qualifiedName)
protected boolean
getOption(java.lang.String name, boolean dft)
protected long
getOption(java.lang.String name, long dft)
java.util.Set<java.lang.String>
getOptionNames()
java.util.Map<java.lang.String,java.lang.Object>
getOptions()
org.eclipse.jetty.util.thread.Scheduler
getScheduler()
SecurityPolicy
getSecurityPolicy()
ServerSession
getSession(java.lang.String clientId)
java.util.List<ServerSession>
getSessions()
long
getSweepPeriod()
int
getSweepThreads()
ServerTransport
getTransport(java.lang.String transport)
java.util.List<ServerTransport>
getTransports()
void
handle(ServerSessionImpl session, ServerMessage.Mutable message, Promise<ServerMessage.Mutable> promise)
protected void
initializeJSONContext()
protected void
initializeMetaChannels()
protected void
initializeServerTransports()
boolean
isBroadcastToPublisher()
boolean
isDetailedDump()
ChannelId
newChannelId(java.lang.String id)
LocalSession
newLocalSession(java.lang.String idHint)
Creates a newLocalSession
.ServerMessage.Mutable
newMessage()
ServerMessage.Mutable
newMessage(ServerMessage original)
ServerSessionImpl
newServerSession()
protected void
publish(ServerSessionImpl session, ServerChannelImpl channel, ServerMessage.Mutable message, boolean receiving, Promise<java.lang.Boolean> promise)
long
randomLong()
void
removeExtension(BayeuxServer.Extension extension)
Removes the given extension from this Bayeux object.void
removeListener(BayeuxServer.BayeuxServerListener listener)
Removes a listener from this Bayeux object.protected boolean
removeServerChannel(ServerChannelImpl channel)
boolean
removeServerSession(ServerSession session, boolean timeout)
boolean
removeSession(ServerSession session)
Removes the givensession
from this BayeuxServer.protected Promise<java.lang.Boolean>
resolveLoop(AsyncFoldLeft.Loop<java.lang.Boolean> loop)
org.eclipse.jetty.util.thread.Scheduler.Task
schedule(java.lang.Runnable task, long delay)
Entry point to schedule tasks in CometD.void
setAllowedTransports(java.lang.String... allowed)
void
setAllowedTransports(java.util.List<java.lang.String> allowed)
void
setDetailedDump(boolean detailedDump)
void
setExecutor(java.util.concurrent.Executor executor)
void
setOption(java.lang.String qualifiedName, java.lang.Object value)
void
setOptions(java.util.Map<java.lang.String,java.lang.Object> options)
void
setScheduler(org.eclipse.jetty.util.thread.Scheduler scheduler)
void
setSecurityPolicy(SecurityPolicy securityPolicy)
void
setSweepPeriod(long sweepPeriod)
void
setSweepThreads(int sweepThreads)
void
setTransports(java.util.List<ServerTransport> transports)
void
setTransports(ServerTransport... transports)
void
sweep()
protected void
unknownSession(ServerMessage.Mutable reply)
protected java.lang.String
validateMessage(ServerMessage.Mutable message)
-
Methods inherited from class org.eclipse.jetty.util.component.ContainerLifeCycle
addBean, addBean, addEventListener, addManaged, contains, destroy, dump, dump, dumpObjects, dumpStdErr, getBean, getBeans, getBeans, getContainedBeans, getContainedBeans, isAuto, isManaged, isUnmanaged, manage, removeBean, removeBeans, removeEventListener, setBeans, start, stop, unmanage, updateBean, updateBean, updateBeans, updateBeans
-
Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
getEventListeners, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, setEventListeners, start, stop, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
-
-
-
Field Detail
-
ALLOWED_TRANSPORTS_OPTION
public static final java.lang.String ALLOWED_TRANSPORTS_OPTION
- See Also:
- Constant Field Values
-
SWEEP_PERIOD_OPTION
public static final java.lang.String SWEEP_PERIOD_OPTION
- See Also:
- Constant Field Values
-
SWEEP_THREADS_OPTION
public static final java.lang.String SWEEP_THREADS_OPTION
- See Also:
- Constant Field Values
-
TRANSPORTS_OPTION
public static final java.lang.String TRANSPORTS_OPTION
- See Also:
- Constant Field Values
-
VALIDATE_MESSAGE_FIELDS_OPTION
public static final java.lang.String VALIDATE_MESSAGE_FIELDS_OPTION
- See Also:
- Constant Field Values
-
BROADCAST_TO_PUBLISHER_OPTION
public static final java.lang.String BROADCAST_TO_PUBLISHER_OPTION
- See Also:
- Constant Field Values
-
SCHEDULER_THREADS
public static final java.lang.String SCHEDULER_THREADS
- See Also:
- Constant Field Values
-
EXECUTOR_MAX_THREADS
public static final java.lang.String EXECUTOR_MAX_THREADS
- See Also:
- Constant Field Values
-
-
Method Detail
-
getName
public java.lang.String getName()
-
doStart
protected void doStart() throws java.lang.Exception
- Overrides:
doStart
in classorg.eclipse.jetty.util.component.ContainerLifeCycle
- Throws:
java.lang.Exception
-
doStop
protected void doStop() throws java.lang.Exception
- Overrides:
doStop
in classorg.eclipse.jetty.util.component.ContainerLifeCycle
- Throws:
java.lang.Exception
-
initializeMetaChannels
protected void initializeMetaChannels()
-
initializeJSONContext
protected void initializeJSONContext() throws java.lang.Exception
- Throws:
java.lang.Exception
-
initializeServerTransports
protected void initializeServerTransports()
-
setExecutor
public void setExecutor(java.util.concurrent.Executor executor)
-
getExecutor
public java.util.concurrent.Executor getExecutor()
-
execute
public void execute(java.lang.Runnable job)
-
setScheduler
public void setScheduler(org.eclipse.jetty.util.thread.Scheduler scheduler)
-
getScheduler
public org.eclipse.jetty.util.thread.Scheduler getScheduler()
-
schedule
public org.eclipse.jetty.util.thread.Scheduler.Task schedule(java.lang.Runnable task, long delay)
Entry point to schedule tasks in CometD.
Subclasses may override and run the task in a
Executor
, rather than in the scheduler thread.- Parameters:
task
- the task to scheduledelay
- the delay, in milliseconds, to run the task- Returns:
- the task promise
-
newChannelId
public ChannelId newChannelId(java.lang.String id)
-
getOptions
public java.util.Map<java.lang.String,java.lang.Object> getOptions()
-
getOption
@ManagedOperation(value="The value of the given configuration option", impact="INFO") public java.lang.Object getOption(@Name("optionName") java.lang.String qualifiedName)
- Specified by:
getOption
in interfaceBayeux
- Parameters:
qualifiedName
- the configuration option name- Returns:
- the configuration option with the given
qualifiedName
- See Also:
Bayeux.setOption(String, Object)
,Bayeux.getOptionNames()
-
getOption
protected long getOption(java.lang.String name, long dft)
-
getOption
protected boolean getOption(java.lang.String name, boolean dft)
-
getOptionNames
public java.util.Set<java.lang.String> getOptionNames()
- Specified by:
getOptionNames
in interfaceBayeux
- Returns:
- the set of configuration options
- See Also:
Bayeux.getOption(String)
-
setOption
public void setOption(java.lang.String qualifiedName, java.lang.Object value)
- Specified by:
setOption
in interfaceBayeux
- Parameters:
qualifiedName
- the configuration option namevalue
- the configuration option value- See Also:
Bayeux.getOption(String)
-
setOptions
public void setOptions(java.util.Map<java.lang.String,java.lang.Object> options)
-
randomLong
public long randomLong()
-
getSecurityPolicy
public SecurityPolicy getSecurityPolicy()
- Specified by:
getSecurityPolicy
in interfaceBayeuxServer
- Returns:
- the
SecurityPolicy
associated with this session - See Also:
BayeuxServer.setSecurityPolicy(SecurityPolicy)
-
getJSONContext
public JSONContextServer getJSONContext()
-
createChannelIfAbsent
public MarkedReference<ServerChannel> createChannelIfAbsent(java.lang.String channelName, ConfigurableServerChannel.Initializer... initializers)
Description copied from interface:BayeuxServer
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.
- Specified by:
createChannelIfAbsent
in interfaceBayeuxServer
- 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.
-
getSessions
public java.util.List<ServerSession> getSessions()
- Specified by:
getSessions
in interfaceBayeuxServer
- Returns:
- the list of
ServerSession
s known to this BayeuxServer object
-
getSession
public ServerSession getSession(java.lang.String clientId)
- Specified by:
getSession
in interfaceBayeuxServer
- Parameters:
clientId
- theServerSession
identifier- Returns:
- the
ServerSession
with the givenclientId
or null if no such valid session exists.
-
addServerSession
protected void addServerSession(ServerSessionImpl session, ServerMessage message)
-
removeSession
public boolean removeSession(ServerSession session)
Description copied from interface:BayeuxServer
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.
- Specified by:
removeSession
in interfaceBayeuxServer
- Parameters:
session
- the session to remove- Returns:
- true if the session was known to this BayeuxServer and was removed
-
removeServerSession
public boolean removeServerSession(ServerSession session, boolean timeout)
- Parameters:
session
- the session to removetimeout
- whether the session has been removed due to a timeout- Returns:
- true if the session was removed and was connected
-
newServerSession
public ServerSessionImpl newServerSession()
-
newLocalSession
public LocalSession newLocalSession(java.lang.String idHint)
Description copied from interface:BayeuxServer
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.- Specified by:
newLocalSession
in interfaceBayeuxServer
- Parameters:
idHint
- a hint to be included in the unique clientId of the session.- Returns:
- a new
LocalSession
-
newMessage
public ServerMessage.Mutable newMessage()
- Specified by:
newMessage
in interfaceBayeuxServer
- Returns:
- a new or recycled mutable message instance.
-
newMessage
public ServerMessage.Mutable newMessage(ServerMessage original)
-
setSecurityPolicy
public void setSecurityPolicy(SecurityPolicy securityPolicy)
- Specified by:
setSecurityPolicy
in interfaceBayeuxServer
- Parameters:
securityPolicy
- theSecurityPolicy
associated with this session- See Also:
BayeuxServer.getSecurityPolicy()
-
addExtension
public void addExtension(BayeuxServer.Extension extension)
Description copied from interface:BayeuxServer
Adds the given extension to this Bayeux object.
- Specified by:
addExtension
in interfaceBayeuxServer
- Parameters:
extension
- the extension to add- See Also:
BayeuxServer.removeExtension(Extension)
-
removeExtension
public void removeExtension(BayeuxServer.Extension extension)
Description copied from interface:BayeuxServer
Removes the given extension from this Bayeux object.
- Specified by:
removeExtension
in interfaceBayeuxServer
- Parameters:
extension
- the extension to remove- See Also:
BayeuxServer.addExtension(Extension)
-
getExtensions
public java.util.List<BayeuxServer.Extension> getExtensions()
- Specified by:
getExtensions
in interfaceBayeuxServer
- Returns:
- an immutable list of extensions present in this BayeuxServer instance
- See Also:
BayeuxServer.addExtension(Extension)
-
addListener
public void addListener(BayeuxServer.BayeuxServerListener listener)
Description copied from interface:BayeuxServer
Adds a listener to this Bayeux object.
- Specified by:
addListener
in interfaceBayeuxServer
- Parameters:
listener
- the listener to add- See Also:
BayeuxServer.removeListener(BayeuxServerListener)
-
getChannel
public ServerChannel getChannel(java.lang.String channelId)
- Specified by:
getChannel
in interfaceBayeuxServer
- Parameters:
channelId
- the channel identifier- Returns:
- a
ServerChannel
with the givenchannelId
, or null if no such channel exists - See Also:
BayeuxServer.createChannelIfAbsent(String, ConfigurableServerChannel.Initializer...)
-
getChannels
public java.util.List<ServerChannel> getChannels()
- Specified by:
getChannels
in interfaceBayeuxServer
- Returns:
- the list of channels known to this BayeuxServer object
-
removeListener
public void removeListener(BayeuxServer.BayeuxServerListener listener)
Description copied from interface:BayeuxServer
Removes a listener from this Bayeux object.
- Specified by:
removeListener
in interfaceBayeuxServer
- Parameters:
listener
- the listener to remove- See Also:
BayeuxServer.addListener(BayeuxServerListener)
-
handle
public void handle(ServerSessionImpl session, ServerMessage.Mutable message, Promise<ServerMessage.Mutable> promise)
-
validateMessage
protected java.lang.String validateMessage(ServerMessage.Mutable message)
-
publish
protected void publish(ServerSessionImpl session, ServerChannelImpl channel, ServerMessage.Mutable message, boolean receiving, Promise<java.lang.Boolean> promise)
-
resolveLoop
protected Promise<java.lang.Boolean> resolveLoop(AsyncFoldLeft.Loop<java.lang.Boolean> loop)
-
freeze
public void freeze(ServerMessage.Mutable mutable)
-
extendOutgoing
protected void extendOutgoing(ServerSession sender, ServerSession session, ServerMessage.Mutable message, Promise<java.lang.Boolean> promise)
-
extendReply
public void extendReply(ServerSessionImpl sender, ServerSessionImpl session, ServerMessage.Mutable reply, Promise<ServerMessage.Mutable> promise)
-
removeServerChannel
protected boolean removeServerChannel(ServerChannelImpl channel)
-
getListeners
protected java.util.List<BayeuxServer.BayeuxServerListener> getListeners()
-
getKnownTransportNames
public java.util.Set<java.lang.String> getKnownTransportNames()
- Specified by:
getKnownTransportNames
in interfaceBayeux
- Returns:
- the set of known transport names of this Bayeux object.
- See Also:
Bayeux.getAllowedTransports()
-
getTransport
public ServerTransport getTransport(java.lang.String transport)
- Specified by:
getTransport
in interfaceBayeux
- Parameters:
transport
- the transport name- Returns:
- the transport with the given name or null if no such transport exist
-
addTransport
public ServerTransport addTransport(ServerTransport transport)
-
setTransports
public void setTransports(ServerTransport... transports)
-
setTransports
public void setTransports(java.util.List<ServerTransport> transports)
-
getTransports
public java.util.List<ServerTransport> getTransports()
-
findHttpTransport
protected AbstractHttpTransport findHttpTransport(javax.servlet.http.HttpServletRequest request)
-
getAllowedTransports
@ManagedAttribute(value="The transports allowed by this CometD server", readonly=true) public java.util.List<java.lang.String> getAllowedTransports()
- Specified by:
getAllowedTransports
in interfaceBayeux
- Returns:
- the ordered list of transport names that will be used in the negotiation of transports with the other peer.
- See Also:
Bayeux.getKnownTransportNames()
-
setAllowedTransports
public void setAllowedTransports(java.lang.String... allowed)
-
setAllowedTransports
public void setAllowedTransports(java.util.List<java.lang.String> allowed)
-
isBroadcastToPublisher
@ManagedAttribute(value="Whether this CometD server broadcast messages to the publisher", readonly=true) public boolean isBroadcastToPublisher()
-
unknownSession
protected void unknownSession(ServerMessage.Mutable reply)
-
error
protected void error(ServerMessage.Mutable reply, java.lang.String error)
-
createReply
protected ServerMessage.Mutable createReply(ServerMessage.Mutable message)
-
sweep
@ManagedOperation(value="Sweeps channels and sessions of this CometD server", impact="ACTION") public void sweep()
-
isDetailedDump
@ManagedAttribute("Reports additional details in the dump() operation") public boolean isDetailedDump()
-
setDetailedDump
public void setDetailedDump(boolean detailedDump)
-
getSweepPeriod
@ManagedAttribute("The period, in milliseconds, of the sweeping activity performed by the server") public long getSweepPeriod()
-
setSweepPeriod
public void setSweepPeriod(long sweepPeriod)
-
getSweepThreads
@ManagedAttribute("The maximum number of threads that can be used by the sweeping activity performed by the server") public int getSweepThreads()
-
setSweepThreads
public void setSweepThreads(int sweepThreads)
-
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
- Overrides:
dump
in classorg.eclipse.jetty.util.component.ContainerLifeCycle
- Throws:
java.io.IOException
-
getLastSweepInfo
public java.util.Map<java.lang.String,java.lang.Object> getLastSweepInfo()
-
getLongestSweepInfo
public java.util.Map<java.lang.String,java.lang.Object> getLongestSweepInfo()
-
-