org.cometd.server
Class BayeuxServerImpl

java.lang.Object
  extended by org.eclipse.jetty.util.component.AbstractLifeCycle
      extended by org.cometd.server.BayeuxServerImpl
All Implemented Interfaces:
Bayeux, BayeuxServer, org.eclipse.jetty.util.component.LifeCycle

public class BayeuxServerImpl
extends org.eclipse.jetty.util.component.AbstractLifeCycle
implements BayeuxServer

Options to configure the server are:

tickIntervalMsThe time in milliseconds between ticks to check for timeouts etc sweepIntervalMsThe time in milliseconds between sweeps of channels to remove invalid subscribers and non-persistent channels


Nested Class Summary
 
Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
org.eclipse.jetty.util.component.AbstractLifeCycle.AbstractLifeCycleListener
 
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.cometd.bayeux.Bayeux
Bayeux.BayeuxListener
 
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.LifeCycle
org.eclipse.jetty.util.component.LifeCycle.Listener
 
Field Summary
static int CONFIG_LOG_LEVEL
           
static int DEBUG_LOG_LEVEL
           
static int INFO_LOG_LEVEL
           
static String JSON_CONTEXT
           
static String LOG_LEVEL
           
static int OFF_LOG_LEVEL
           
 
Fields inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
FAILED, RUNNING, STARTED, STARTING, STOPPED, STOPPING
 
Fields inherited from interface org.cometd.bayeux.server.BayeuxServer
ATTRIBUTE
 
Constructor Summary
BayeuxServerImpl()
           
 
Method Summary
 void addExtension(BayeuxServer.Extension extension)
           
 void addListener(BayeuxServer.BayeuxServerListener listener)
           
protected  void addServerSession(ServerSessionImpl session)
           
 void addTransport(ServerTransport transport)
           
 void cancelTimeout(org.eclipse.jetty.util.thread.Timeout.Task task)
           
 boolean createIfAbsent(String channelName, ConfigurableServerChannel.Initializer... initializers)
           
protected  ServerMessage.Mutable createReply(ServerMessage.Mutable message)
           
protected  void doPublish(ServerSessionImpl from, ServerChannelImpl to, ServerMessage.Mutable mutable)
           
protected  void doStart()
           
protected  void doStop()
           
 String dump()
           
protected  void error(ServerMessage.Mutable reply, String error)
           
protected  boolean extendRecv(ServerSession from, ServerMessage.Mutable message)
           
 ServerMessage.Mutable extendReply(ServerSessionImpl from, ServerSessionImpl to, ServerMessage.Mutable reply)
           
protected  boolean extendSend(ServerSession from, ServerSession to, ServerMessage.Mutable message)
           
 void freeze(ServerMessage.Mutable mutable)
           
 List<String> getAllowedTransports()
           
 ServerChannel getChannel(String channelId)
           
 List<ServerChannelImpl> getChannelChildren(ChannelId channelId)
          Deprecated. because it scans all the existing channels and therefore is inefficient; if the functionality is needed, then we may consider adding it to ServerChannel.
 List<ServerChannel> getChannels()
           
 BayeuxContext getContext()
           
 ServerTransport getCurrentTransport()
           
 List<BayeuxServer.Extension> getExtensions()
           
 Set<String> getKnownTransportNames()
           
protected  List<BayeuxServer.BayeuxServerListener> getListeners()
           
 org.slf4j.Logger getLogger()
           
 Object getOption(String qualifiedName)
           
protected  long getOption(String name, long dft)
          Get an option value as a long
 Set<String> getOptionNames()
           
 Map<String,Object> getOptions()
           
 SecurityPolicy getSecurityPolicy()
           
 ServerSession getSession(String clientId)
           
 List<ServerSession> getSessions()
           
 ServerTransport getTransport(String transport)
           
 ServerMessage.Mutable handle(ServerSessionImpl session, ServerMessage.Mutable message)
          Extend and handle in incoming message.
protected  void initializeDefaultTransports()
          Initialize the default transports.
protected  void initializeJSONContext()
           
protected  void initializeMetaChannels()
           
 ChannelId newChannelId(String id)
           
 LocalSession newLocalSession(String idHint)
           
 ServerMessage.Mutable newMessage()
           
 ServerMessage.Mutable newMessage(ServerMessage tocopy)
           
protected  ServerSessionImpl newServerSession()
           
 long randomLong()
           
 void removeExtension(BayeuxServer.Extension extension)
           
 void removeListener(BayeuxServer.BayeuxServerListener listener)
           
protected  boolean removeServerChannel(ServerChannelImpl channel)
           
 boolean removeServerSession(ServerSession session, boolean timedout)
           
 void setAllowedTransports(List<String> allowed)
           
 void setAllowedTransports(String... allowed)
           
 void setCurrentTransport(AbstractServerTransport transport)
           
 void setOption(String qualifiedName, Object value)
           
 void setOptions(Map<String,Object> options)
           
 void setSecurityPolicy(SecurityPolicy securityPolicy)
           
 void setTransports(List<ServerTransport> transports)
           
 void setTransports(ServerTransport... transports)
           
 void startTimeout(org.eclipse.jetty.util.thread.Timeout.Task task, long interval)
           
 void sweep()
           
protected  void unknownSession(ServerMessage.Mutable reply)
           
 
Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
addLifeCycleListener, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG_LEVEL

public static final String LOG_LEVEL
See Also:
Constant Field Values

OFF_LOG_LEVEL

public static final int OFF_LOG_LEVEL
See Also:
Constant Field Values

CONFIG_LOG_LEVEL

public static final int CONFIG_LOG_LEVEL
See Also:
Constant Field Values

INFO_LOG_LEVEL

public static final int INFO_LOG_LEVEL
See Also:
Constant Field Values

DEBUG_LOG_LEVEL

public static final int DEBUG_LOG_LEVEL
See Also:
Constant Field Values

JSON_CONTEXT

public static final String JSON_CONTEXT
See Also:
Constant Field Values
Constructor Detail

BayeuxServerImpl

public BayeuxServerImpl()
Method Detail

getLogger

public org.slf4j.Logger getLogger()
Returns:
The Logger used by this BayeuxServer instance

doStart

protected void doStart()
                throws Exception
Overrides:
doStart in class org.eclipse.jetty.util.component.AbstractLifeCycle
Throws:
Exception

doStop

protected void doStop()
               throws Exception
Overrides:
doStop in class org.eclipse.jetty.util.component.AbstractLifeCycle
Throws:
Exception

initializeMetaChannels

protected void initializeMetaChannels()

initializeJSONContext

protected void initializeJSONContext()
                              throws Exception
Throws:
Exception

initializeDefaultTransports

protected void initializeDefaultTransports()
Initialize the default transports.

This method creates a JSONTransport and a JSONPTransport. If no allowed transport have been set then adds all known transports as allowed transports.


startTimeout

public void startTimeout(org.eclipse.jetty.util.thread.Timeout.Task task,
                         long interval)

cancelTimeout

public void cancelTimeout(org.eclipse.jetty.util.thread.Timeout.Task task)

newChannelId

public ChannelId newChannelId(String id)

getOptions

public Map<String,Object> getOptions()

getOption

public Object getOption(String qualifiedName)
Specified by:
getOption in interface Bayeux
See Also:
Bayeux.getOption(java.lang.String)

getOption

protected long getOption(String name,
                         long dft)
Get an option value as a long

Parameters:
name - The option name
dft - The default value
Returns:
long value

getOptionNames

public Set<String> getOptionNames()
Specified by:
getOptionNames in interface Bayeux
See Also:
Bayeux.getOptionNames()

setOption

public void setOption(String qualifiedName,
                      Object value)
Specified by:
setOption in interface Bayeux
See Also:
Bayeux.setOption(java.lang.String, java.lang.Object)

setOptions

public void setOptions(Map<String,Object> options)

randomLong

public long randomLong()

setCurrentTransport

public void setCurrentTransport(AbstractServerTransport transport)

getCurrentTransport

public ServerTransport getCurrentTransport()
Specified by:
getCurrentTransport in interface BayeuxServer

getContext

public BayeuxContext getContext()
Specified by:
getContext in interface BayeuxServer

getSecurityPolicy

public SecurityPolicy getSecurityPolicy()
Specified by:
getSecurityPolicy in interface BayeuxServer

createIfAbsent

public boolean createIfAbsent(String channelName,
                              ConfigurableServerChannel.Initializer... initializers)
Specified by:
createIfAbsent in interface BayeuxServer

getSessions

public List<ServerSession> getSessions()
Specified by:
getSessions in interface BayeuxServer

getSession

public ServerSession getSession(String clientId)
Specified by:
getSession in interface BayeuxServer

addServerSession

protected void addServerSession(ServerSessionImpl session)

removeServerSession

public boolean removeServerSession(ServerSession session,
                                   boolean timedout)
Parameters:
session - the session to remove
timedout - whether the remove reason is server-side expiration
Returns:
true if the session was removed and was connected

newServerSession

protected ServerSessionImpl newServerSession()

newLocalSession

public LocalSession newLocalSession(String idHint)
Specified by:
newLocalSession in interface BayeuxServer

newMessage

public ServerMessage.Mutable newMessage()
Specified by:
newMessage in interface BayeuxServer

newMessage

public ServerMessage.Mutable newMessage(ServerMessage tocopy)

setSecurityPolicy

public void setSecurityPolicy(SecurityPolicy securityPolicy)
Specified by:
setSecurityPolicy in interface BayeuxServer

addExtension

public void addExtension(BayeuxServer.Extension extension)
Specified by:
addExtension in interface BayeuxServer

removeExtension

public void removeExtension(BayeuxServer.Extension extension)
Specified by:
removeExtension in interface BayeuxServer

getExtensions

public List<BayeuxServer.Extension> getExtensions()
Specified by:
getExtensions in interface BayeuxServer

addListener

public void addListener(BayeuxServer.BayeuxServerListener listener)
Specified by:
addListener in interface BayeuxServer

getChannel

public ServerChannel getChannel(String channelId)
Specified by:
getChannel in interface BayeuxServer

getChannels

public List<ServerChannel> getChannels()
Specified by:
getChannels in interface BayeuxServer

getChannelChildren

@Deprecated
public List<ServerChannelImpl> getChannelChildren(ChannelId channelId)
Deprecated. because it scans all the existing channels and therefore is inefficient; if the functionality is needed, then we may consider adding it to ServerChannel.

Scans all the channels and returns those identified by a channel id that is a child of the given channelId.

Parameters:
channelId - the parent channel id used to look for children
Returns:
a list of channels identified by a channel id that is a child of the given channelId

removeListener

public void removeListener(BayeuxServer.BayeuxServerListener listener)
Specified by:
removeListener in interface BayeuxServer

handle

public ServerMessage.Mutable handle(ServerSessionImpl session,
                                    ServerMessage.Mutable message)
Extend and handle in incoming message.

Parameters:
session - The session if known
message - The message.
Returns:
An unextended reply message

doPublish

protected void doPublish(ServerSessionImpl from,
                         ServerChannelImpl to,
                         ServerMessage.Mutable mutable)

freeze

public void freeze(ServerMessage.Mutable mutable)

extendReply

public ServerMessage.Mutable extendReply(ServerSessionImpl from,
                                         ServerSessionImpl to,
                                         ServerMessage.Mutable reply)

extendRecv

protected boolean extendRecv(ServerSession from,
                             ServerMessage.Mutable message)

extendSend

protected boolean extendSend(ServerSession from,
                             ServerSession to,
                             ServerMessage.Mutable message)

removeServerChannel

protected boolean removeServerChannel(ServerChannelImpl channel)

getListeners

protected List<BayeuxServer.BayeuxServerListener> getListeners()

getKnownTransportNames

public Set<String> getKnownTransportNames()
Specified by:
getKnownTransportNames in interface Bayeux

getTransport

public ServerTransport getTransport(String transport)
Specified by:
getTransport in interface Bayeux

addTransport

public void addTransport(ServerTransport transport)

setTransports

public void setTransports(ServerTransport... transports)

setTransports

public void setTransports(List<ServerTransport> transports)

getAllowedTransports

public List<String> getAllowedTransports()
Specified by:
getAllowedTransports in interface Bayeux

setAllowedTransports

public void setAllowedTransports(String... allowed)

setAllowedTransports

public void setAllowedTransports(List<String> allowed)

unknownSession

protected void unknownSession(ServerMessage.Mutable reply)

error

protected void error(ServerMessage.Mutable reply,
                     String error)

createReply

protected ServerMessage.Mutable createReply(ServerMessage.Mutable message)

sweep

public void sweep()

dump

public String dump()


Copyright © 2008-2012 Dojo Foundation. All Rights Reserved.