org.cometd.server
Class AbstractBayeux

java.lang.Object
  extended by org.cometd.server.MessagePool
      extended by org.cometd.server.AbstractBayeux
All Implemented Interfaces:
Bayeux
Direct Known Subclasses:
ContinuationBayeux

public abstract class AbstractBayeux
extends MessagePool
implements Bayeux

Author:
gregw, aabeling: added JSONP transport

Nested Class Summary
protected  class AbstractBayeux.ConnectHandler
           
static class AbstractBayeux.DefaultPolicy
           
protected  class AbstractBayeux.DisconnectHandler
           
protected  class AbstractBayeux.Handler
           
protected  class AbstractBayeux.HandshakeHandler
           
protected  class AbstractBayeux.MetaPublishHandler
           
protected  class AbstractBayeux.PingHandler
           
protected  class AbstractBayeux.PublishHandler
           
protected  class AbstractBayeux.ServiceChannel
           
protected  class AbstractBayeux.SubscribeHandler
           
protected  class AbstractBayeux.UnsubscribeHandler
           
 
Field Summary
protected  JSON.Literal _advice
           
protected  int _adviceVersion
           
protected  java.util.concurrent.ConcurrentHashMap<java.lang.String,java.util.List<java.lang.String>> _browser2client
           
protected  java.util.concurrent.ConcurrentHashMap<java.lang.String,ChannelId> _channelIdCache
           
protected  java.util.List<ChannelBayeuxListener> _channelListeners
           
protected  java.util.List<ClientBayeuxListener> _clientListeners
           
protected  Extension[] _extensions
           
protected  java.lang.Object _handshakeAdvice
           
protected  boolean _initialized
           
protected  long _interval
           
protected  int _logLevel
           
protected  int _maxClientQueue
           
protected  long _maxInterval
           
protected  int _maxLazyLatency
           
protected  AbstractBayeux.Handler _metaPublishHandler
           
protected  JSON.Literal _multiFrameAdvice
           
protected  int _multiFrameInterval
           
protected  AbstractBayeux.Handler _publishHandler
           
protected  java.util.Random _random
           
protected  JSON.Literal _replyExt
           
protected  java.lang.ThreadLocal<javax.servlet.http.HttpServletRequest> _request
           
protected  boolean _requestAvailable
           
protected  SecurityPolicy _securityPolicy
           
protected  long _timeout
           
protected  JSON.Literal _transports
           
static ChannelId META_CLIENT_ID
           
static ChannelId META_CONNECT_ID
           
static ChannelId META_DISCONNECT_ID
           
static ChannelId META_HANDSHAKE_ID
           
static ChannelId META_ID
           
static ChannelId META_PING_ID
           
static ChannelId META_STATUS_ID
           
static ChannelId META_SUBSCRIBE_ID
           
static ChannelId META_UNSUBSCRIBE_ID
           
 
Fields inherited from interface org.cometd.Bayeux
ADVICE_FIELD, ATTRIBUTE, CHANNEL_FIELD, CLIENT_FIELD, CONNECTION_TYPE_FIELD, DATA_FIELD, ERROR_FIELD, EXT_FIELD, HANDSHAKE_RESPONSE, ID_FIELD, INTERVAL_FIELD, JSON_COMMENT_FILTERED_FIELD, JSON_CONTENT_TYPE, JSONP_DEFAULT_NAME, JSONP_PARAMETER, MESSAGE_PARAMETER, META, META_CLIENT, META_CONNECT, META_DISCONNECT, META_HANDSHAKE, META_PING, META_SLASH, META_STATUS, META_SUBSCRIBE, META_UNSUBSCRIBE, MIN_VERSION_FIELD, NONE_RESPONSE, RECONNECT_FIELD, RETRY_RESPONSE, SERVICE, SERVICE_SLASH, SUBSCRIPTION_FIELD, SUCCESSFUL_FIELD, SUPPORTED_CONNECTION_TYPES_FIELD, TIMESTAMP_FIELD, TRANSPORT_CALLBACK_POLL, TRANSPORT_FIELD, TRANSPORT_FLASH, TRANSPORT_IFRAME, TRANSPORT_LONG_POLL, VERSION_FIELD
 
Constructor Summary
protected AbstractBayeux()
           
 
Method Summary
protected  void addChannel(ChannelImpl channel)
           
protected  void addClient(ClientImpl client, java.lang.String idPrefix)
           
 void addExtension(Extension ext)
          Adds a bayeux extension.
 void addListener(BayeuxListener listener)
          Adds a bayeux listener,
protected  void doPublish(ChannelId to, Client from, java.lang.Object data, java.lang.String msgId, boolean lazy)
          Publish data to a channel.
protected  Message extendRcv(ClientImpl from, Message message)
           
protected  Message extendRcvMeta(ClientImpl from, Message message)
           
protected  Message extendSendBayeux(Client from, Message message)
           
 Message extendSendClient(Client from, ClientImpl to, Message message)
           
 Message extendSendMeta(ClientImpl from, Message message)
           
 JSON.Literal getAdvice()
           
 ChannelImpl getChannel(ChannelId id)
           
 ChannelImpl getChannel(java.lang.String id)
           
 Channel getChannel(java.lang.String id, boolean create)
          Get a Channel instance by ID.
 int getChannelCount()
           
 ChannelId getChannelId(java.lang.String id)
           
 java.util.Collection<Channel> getChannels()
          Get all known channels.
 Client getClient(java.lang.String client_id)
          Get Client by ID.
 int getClientCount()
           
 java.util.Set<java.lang.String> getClientIDs()
           
 java.util.Collection<Client> getClients()
          Get a collection of all Clients.
 javax.servlet.http.HttpServletRequest getCurrentRequest()
          Get the current Servlet Request.
 long getInterval()
           
 int getLogLevel()
           
 int getMaxClientQueue()
           
 long getMaxInterval()
           
 int getMaxLazyLatency()
           
 int getMultiFrameInterval()
           
 SecurityPolicy getSecurityPolicy()
          Get the SecurityPolicy instance.
 long getTimeout()
           
 java.lang.String handle(ClientImpl client, Transport transport, Message message)
          Handle a Bayeux message.
 boolean hasChannel(java.lang.String id)
          Check if channel exists.
 boolean hasClient(java.lang.String clientId)
           
protected  void initialize(javax.servlet.ServletContext context)
           
 boolean isDirectDeliver()
           
 boolean isInitialized()
           
 boolean isJSONCommented()
          Deprecated.  
 boolean isLogDebug()
           
 boolean isLogInfo()
           
 boolean isRequestAvailable()
           
 void logDebug(java.lang.String message)
           
 void logDebug(java.lang.String message, java.lang.Throwable th)
           
 void logInfo(java.lang.String message)
           
 void logWarn(java.lang.String message)
           
 void logWarn(java.lang.String message, java.lang.Throwable th)
           
 Client newClient(java.lang.String idPrefix)
          Create a new server side Client.
protected  java.lang.String newClientId(long variation, java.lang.String idPrefix)
           
abstract  ClientImpl newRemoteClient()
           
 Transport newTransport(ClientImpl client, java.util.Map<?,?> message)
          Create new transport object for a bayeux message
 boolean removeChannel(ChannelImpl channel)
           
 Channel removeChannel(java.lang.String channelId)
           
 Client removeClient(java.lang.String client_id)
           
 void removeExtension(Extension ext)
          Removes a bayeux extension.
 void removeListener(BayeuxListener listener)
          Removes a bayeux listener
 void setAdvice(JSON.Literal advice)
           
 void setDirectDeliver(boolean directDeliver)
          Deprecated.  
 void setInterval(long ms)
           
 void setJSONCommented(boolean commented)
           
 void setLogLevel(int logLevel)
           
 void setMaxClientQueue(int size)
           
 void setMaxInterval(long ms)
           
 void setMaxLazyLatency(int ms)
           
 void setMultiFrameInterval(int multiFrameInterval)
          The time a client should delay between reconnects when multiple connections from the same browser are detected.
 void setRequestAvailable(boolean requestAvailable)
           
 void setSecurityPolicy(SecurityPolicy securityPolicy)
          Set the security policy for the Bayeux instance.
 void setTimeout(long ms)
           
 
Methods inherited from class org.cometd.server.MessagePool
getBatchJSON, getJSON, getMsgJSON, newMessage, newMessage, parse, parse, parseTo, setBatchJSON, setJSON, setMsgJSON, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

META_ID

public static final ChannelId META_ID

META_CONNECT_ID

public static final ChannelId META_CONNECT_ID

META_CLIENT_ID

public static final ChannelId META_CLIENT_ID

META_DISCONNECT_ID

public static final ChannelId META_DISCONNECT_ID

META_HANDSHAKE_ID

public static final ChannelId META_HANDSHAKE_ID

META_PING_ID

public static final ChannelId META_PING_ID

META_STATUS_ID

public static final ChannelId META_STATUS_ID

META_SUBSCRIBE_ID

public static final ChannelId META_SUBSCRIBE_ID

META_UNSUBSCRIBE_ID

public static final ChannelId META_UNSUBSCRIBE_ID

_channelIdCache

protected final java.util.concurrent.ConcurrentHashMap<java.lang.String,ChannelId> _channelIdCache

_browser2client

protected final java.util.concurrent.ConcurrentHashMap<java.lang.String,java.util.List<java.lang.String>> _browser2client

_request

protected final java.lang.ThreadLocal<javax.servlet.http.HttpServletRequest> _request

_clientListeners

protected final java.util.List<ClientBayeuxListener> _clientListeners

_channelListeners

protected final java.util.List<ChannelBayeuxListener> _channelListeners

_publishHandler

protected final AbstractBayeux.Handler _publishHandler

_metaPublishHandler

protected final AbstractBayeux.Handler _metaPublishHandler

_securityPolicy

protected SecurityPolicy _securityPolicy

_advice

protected JSON.Literal _advice

_multiFrameAdvice

protected JSON.Literal _multiFrameAdvice

_adviceVersion

protected int _adviceVersion

_handshakeAdvice

protected java.lang.Object _handshakeAdvice

_logLevel

protected int _logLevel

_timeout

protected long _timeout

_interval

protected long _interval

_maxInterval

protected long _maxInterval

_initialized

protected boolean _initialized

_multiFrameInterval

protected int _multiFrameInterval

_requestAvailable

protected boolean _requestAvailable

_random

protected java.util.Random _random

_maxClientQueue

protected int _maxClientQueue

_extensions

protected Extension[] _extensions

_transports

protected JSON.Literal _transports

_replyExt

protected JSON.Literal _replyExt

_maxLazyLatency

protected int _maxLazyLatency
Constructor Detail

AbstractBayeux

protected AbstractBayeux()
Parameters:
context - The logLevel init parameter is used to set the logging to: 0=none, 1=info, 2=debug
Method Detail

addExtension

public void addExtension(Extension ext)
Description copied from interface: Bayeux
Adds a bayeux extension. A bayeux extension may modify a message or return a new message.

Specified by:
addExtension in interface Bayeux
Parameters:
ext - the extension to add
See Also:
Bayeux.removeExtension(Extension)

removeExtension

public void removeExtension(Extension ext)
Description copied from interface: Bayeux
Removes a bayeux extension.

Specified by:
removeExtension in interface Bayeux
Parameters:
ext - the extension to remove
See Also:
Bayeux.addExtension(Extension)

getChannel

public ChannelImpl getChannel(ChannelId id)
Parameters:
id -
Returns:

getChannel

public ChannelImpl getChannel(java.lang.String id)

getChannel

public Channel getChannel(java.lang.String id,
                          boolean create)
Description copied from interface: Bayeux
Get a Channel instance by ID.

Specified by:
getChannel in interface Bayeux
Parameters:
id - The Channel ID
create - If true, a channel will be created if it does not exist.
Returns:
A Channel instance or null if it does not exist and create is false.

getChannelId

public ChannelId getChannelId(java.lang.String id)

getClient

public Client getClient(java.lang.String client_id)
Description copied from interface: Bayeux
Get Client by ID.

Specified by:
getClient in interface Bayeux
Returns:
A Client instance or null if the ID is not known

getClientIDs

public java.util.Set<java.lang.String> getClientIDs()

getMaxInterval

public long getMaxInterval()
Returns:
The maximum time in ms to wait between polls before timing out a client

getLogLevel

public int getLogLevel()
Returns:
the logLevel. 0=none, 1=info, 2=debug

getSecurityPolicy

public SecurityPolicy getSecurityPolicy()
Description copied from interface: Bayeux
Get the SecurityPolicy instance.

Specified by:
getSecurityPolicy in interface Bayeux
Returns:
The current SecurityPolicy instance.

getTimeout

public long getTimeout()

getInterval

public long getInterval()

isDirectDeliver

public boolean isDirectDeliver()
Returns:
true if published messages are directly delivered to subscribers. False if a new message is to be created that holds only supported fields.

setDirectDeliver

public void setDirectDeliver(boolean directDeliver)
Deprecated. 

Parameters:
directDeliver - true if published messages are directly delivered to subscribers. False if a new message is to be created that holds only supported fields.

handle

public java.lang.String handle(ClientImpl client,
                               Transport transport,
                               Message message)
                        throws java.io.IOException
Handle a Bayeux message. This is normally only called by the bayeux servlet or a test harness.

Parameters:
client - The client if known
transport - The transport to use for the message
message - The bayeux message.
Throws:
java.io.IOException

hasChannel

public boolean hasChannel(java.lang.String id)
Description copied from interface: Bayeux
Check if channel exists.

Specified by:
hasChannel in interface Bayeux
Returns:
True if Bayeux has a channel with the channel name.

isInitialized

public boolean isInitialized()

isJSONCommented

public boolean isJSONCommented()
Deprecated. 

Returns:
the commented

isLogDebug

public boolean isLogDebug()

isLogInfo

public boolean isLogInfo()

logDebug

public void logDebug(java.lang.String message)

logDebug

public void logDebug(java.lang.String message,
                     java.lang.Throwable th)

logWarn

public void logWarn(java.lang.String message,
                    java.lang.Throwable th)

logWarn

public void logWarn(java.lang.String message)

logInfo

public void logInfo(java.lang.String message)

newClient

public Client newClient(java.lang.String idPrefix)
Description copied from interface: Bayeux
Create a new server side Client. Server side clients can be used to interact with Bayeux with publish and subscribe messaging.

Specified by:
newClient in interface Bayeux
Parameters:
idPrefix - An identifier to prefix to the client ID.
Returns:
A Client instance with Client.isLocal() returning true.

newRemoteClient

public abstract ClientImpl newRemoteClient()

newTransport

public Transport newTransport(ClientImpl client,
                              java.util.Map<?,?> message)
Create new transport object for a bayeux message

Parameters:
client - The client
message - the bayeux message
Returns:
the negotiated transport.

doPublish

protected void doPublish(ChannelId to,
                         Client from,
                         java.lang.Object data,
                         java.lang.String msgId,
                         boolean lazy)
Publish data to a channel. Creates a message and delivers it to the root channel.

Parameters:
to -
from -
data -
msgId -

removeChannel

public boolean removeChannel(ChannelImpl channel)

addChannel

protected void addChannel(ChannelImpl channel)

newClientId

protected java.lang.String newClientId(long variation,
                                       java.lang.String idPrefix)

addClient

protected void addClient(ClientImpl client,
                         java.lang.String idPrefix)

removeClient

public Client removeClient(java.lang.String client_id)
Specified by:
removeClient in interface Bayeux

setMaxInterval

public void setMaxInterval(long ms)
Parameters:
ms - The maximum time in ms to wait between polls before timing out a client

setJSONCommented

public void setJSONCommented(boolean commented)
Parameters:
commented - the commented to set

setLogLevel

public void setLogLevel(int logLevel)
Parameters:
logLevel - the logLevel: 0=none, 1=info, 2=debug

setSecurityPolicy

public void setSecurityPolicy(SecurityPolicy securityPolicy)
Description copied from interface: Bayeux
Set the security policy for the Bayeux instance.

The Security Policy will be called to check access for all handshakes, subscriptions and publishing.

Specified by:
setSecurityPolicy in interface Bayeux
Parameters:
securityPolicy - The security policy instance.

setTimeout

public void setTimeout(long ms)

setInterval

public void setInterval(long ms)

setMultiFrameInterval

public void setMultiFrameInterval(int multiFrameInterval)
The time a client should delay between reconnects when multiple connections from the same browser are detected. This effectively produces traditional polling.

Parameters:
multiFrameInterval - the multiFrameInterval to set

getMultiFrameInterval

public int getMultiFrameInterval()
Returns:
the multiFrameInterval in milliseconds

setAdvice

public void setAdvice(JSON.Literal advice)

getAdvice

public JSON.Literal getAdvice()

isRequestAvailable

public boolean isRequestAvailable()
Returns:
TRUE if getCurrentRequest() will return the current request

setRequestAvailable

public void setRequestAvailable(boolean requestAvailable)
Parameters:
requestAvailable - TRUE if getCurrentRequest() will return the current request

getCurrentRequest

public javax.servlet.http.HttpServletRequest getCurrentRequest()
Description copied from interface: Bayeux
Get the current Servlet Request. If the calling thread is in the context of a servlet call, then return the request object. This can be used to authenticate users and/or perform other validation of the caller.

Specified by:
getCurrentRequest in interface Bayeux
Returns:
the current request if isRequestAvailable() is true, else null

getChannels

public java.util.Collection<Channel> getChannels()
Description copied from interface: Bayeux
Get all known channels.

Specified by:
getChannels in interface Bayeux
Returns:
A collection of all known channel instances.

getChannelCount

public int getChannelCount()
Returns:

getClients

public java.util.Collection<Client> getClients()
Description copied from interface: Bayeux
Get a collection of all Clients. The collection is copy of the underlying collection.

Specified by:
getClients in interface Bayeux
Returns:
Collection of clients.

getClientCount

public int getClientCount()
Returns:

hasClient

public boolean hasClient(java.lang.String clientId)
Specified by:
hasClient in interface Bayeux

removeChannel

public Channel removeChannel(java.lang.String channelId)
Specified by:
removeChannel in interface Bayeux

initialize

protected void initialize(javax.servlet.ServletContext context)

addListener

public void addListener(BayeuxListener listener)
Description copied from interface: Bayeux
Adds a bayeux listener,

Specified by:
addListener in interface Bayeux
Parameters:
listener - the listener to add
See Also:
Bayeux.removeListener(BayeuxListener)

removeListener

public void removeListener(BayeuxListener listener)
Description copied from interface: Bayeux
Removes a bayeux listener

Specified by:
removeListener in interface Bayeux
Parameters:
listener - the listener to remove
See Also:
Bayeux.addListener(BayeuxListener)

getMaxClientQueue

public int getMaxClientQueue()
Specified by:
getMaxClientQueue in interface Bayeux
Returns:
the max client queue size
See Also:
Bayeux.setMaxClientQueue(int)

setMaxClientQueue

public void setMaxClientQueue(int size)
Specified by:
setMaxClientQueue in interface Bayeux
Parameters:
size - The size which if a client queue exceeds, forces a call to QueueListener#queueMaxed(Client, Message) to check if the message should be added. If set to -1, there is no queue limit. If set to zero, messages are not queued unless a QueueListener is applied that returns true.
See Also:
Bayeux.getMaxClientQueue()

extendRcv

protected Message extendRcv(ClientImpl from,
                            Message message)

extendRcvMeta

protected Message extendRcvMeta(ClientImpl from,
                                Message message)

extendSendBayeux

protected Message extendSendBayeux(Client from,
                                   Message message)

extendSendClient

public Message extendSendClient(Client from,
                                ClientImpl to,
                                Message message)

extendSendMeta

public Message extendSendMeta(ClientImpl from,
                              Message message)

getMaxLazyLatency

public int getMaxLazyLatency()
Returns:
the maximum ms that a lazy message will wait before resuming waiting client

setMaxLazyLatency

public void setMaxLazyLatency(int ms)
Parameters:
ms - the maximum ms that a lazy message will wait before resuming waiting client


Copyright © 2011 Dojo Foundation. All Rights Reserved.