## org.mortbay.cometd
Class AbstractBayeux

    java.lang.Object
      org.mortbay.cometd.MessagePool
          org.mortbay.cometd.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 Object` `_advice`
`protected int` `_adviceVersion`
`protected ConcurrentHashMap<String,List<String>>` `_browser2client`
`protected boolean` `_directDeliver`
`protected List<Extension>` `_extensions`
`protected boolean` `_initialized`
`protected long` `_interval`
`protected boolean` `_JSONCommented`
`protected int` `_logLevel`
`protected long` `_maxInterval`
`protected AbstractBayeux.Handler` `_metaPublishHandler`
`protected JSON.Literal` `_multiFrameAdvice`
`protected int` `_multiFrameInterval`
`protected AbstractBayeux.Handler` `_publishHandler`
`protected ThreadLocal<HttpServletRequest>` `_request`
`protected boolean` `_requestAvailable`
`protected SecurityPolicy` `_securityPolicy`
`protected long` `_timeout`
`protected Object` `_unknownAdvice`
`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`
`static JSON.Literal` `TRANSPORTS`

Fields inherited from interface dojox.cometd.Bayeux

`ADVICE_FIELD, CHANNEL_FIELD, CLIENT_FIELD, CONNECTION_TYPE_FIELD, DATA_FIELD, DOJOX_COMETD_BAYEUX, 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, SUPP_CONNECTION_TYPE_FIELD, TIMESTAMP_FIELD, TRANSPORT_CALLBACK_POLL, TRANSPORT_FIELD, TRANSPORT_FLASH, TRANSPORT_IFRAME, TRANSPORT_LONG_POLL, VERSION_FIELD`

Constructor Summary
`protected` `AbstractBayeux()`

Method Summary
`void` `addExtension(Extension ext)`
`void` `addFilter(String channels, DataFilter filter)` Deprecated. user `Channel#addFilter`
`void` `deliver(Client fromClient, Client toClient, String toChannel, Message message)` Deprecated. use `Client.deliver(Client, Message)`
`protected void` `doPublish(ChannelId to, Client from, Object data, String msgId)` Publish data to a channel.
`Object` `getAdvice()`
`ChannelImpl` `getChannel(ChannelId id)`
`ChannelImpl` `getChannel(String id)`
`Channel` `getChannel(String id, boolean create)` Get a Channel instance by ID.
`ChannelId` `getChannelId(String id)`
`Collection<Channel>` `getChannels()` Get all known channels.
`Client` `getClient(String client_id)`
`Set<String>` `getClientIDs()`
`Collection<Client>` `getClients()`
`HttpServletRequest` `getCurrentRequest()`
`List<Extension>` `getExtensions()`
`long` `getInterval()`
`int` `getLogLevel()`
`long` `getMaxInterval()`
`int` `getMultiFrameInterval()`
`SecurityPolicy` `getSecurityPolicy()`
`long` `getTimeout()`
`String` `handle(ClientImpl client, Transport transport, Message message)` Handle a Bayeux message.
`boolean` `hasChannel(String id)`
`boolean` `hasClient(String clientId)`
`protected void` `initialize(ServletContext context)`
`boolean` `isDirectDeliver()`
`boolean` `isInitialized()`
`boolean` `isJSONCommented()`
`boolean` `isLogDebug()`
`boolean` `isLogInfo()`
`boolean` `isRequestAvailable()`
`void` `logDebug(String message)`
`void` `logDebug(String message, Throwable th)`
`void` `logInfo(String message)`
`void` `logWarn(String message)`
`void` `logWarn(String message, Throwable th)`
`Client` `newClient(String idPrefix)`
`Client` `newClient(String idPrefix, Listener listener)` Deprecated. use `newClient(String)`
`abstract ClientImpl` `newRemoteClient()`
`Transport` `newTransport(ClientImpl client, Map<?,?> message)` Create new transport object for a bayeux message
`void` `publish(Client fromClient, String toChannelId, Object data, String msgId)` Deprecated. use `Channel.publish(Client, Object, String)`
`boolean` `removeChannel(ChannelId channelId)`
`Channel` `removeChannel(String channelId)`
`Client` `removeClient(String client_id)`
`void` `removeExtension(Extension ext)`
`void` `removeFilter(String channels, DataFilter filter)`
`void` `setAdvice(Object advice)`
`void` `setDirectDeliver(boolean directDeliver)`
`void` `setInterval(long ms)`
`void` `setJSONCommented(boolean commented)`
`void` `setLogLevel(int logLevel)`
`void` `setMaxInterval(long 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)`
`void` `subscribe(String toChannel, Client subscriber)` Subscribe to a channel.
`void` `unsubscribe(String toChannel, Client subscriber)` Unsubscribe to a channel

Methods inherited from class org.mortbay.cometd.MessagePool
`getBatchJSON, getJSON, getMsgJSON, newMessage, newMessage, parse, parse, parseTo, recycleMessage, setBatchJSON, setJSON, setMsgJSON`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, 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

### TRANSPORTS

    public static final JSON.Literal TRANSPORTS

### _securityPolicy

    protected SecurityPolicy _securityPolicy

### _advice

    protected Object _advice

### _adviceVersion

    protected int _adviceVersion

### _unknownAdvice

    protected Object _unknownAdvice

### _logLevel

    protected int _logLevel

### _timeout

    protected long _timeout

### _interval

    protected long _interval

### _maxInterval

    protected long _maxInterval

### _JSONCommented

    protected boolean _JSONCommented

### _initialized

    protected boolean _initialized

### _browser2client

    protected ConcurrentHashMap<String,List<String>> _browser2client

### _multiFrameInterval

    protected int _multiFrameInterval

### _multiFrameAdvice

    protected JSON.Literal _multiFrameAdvice

### _directDeliver

    protected boolean _directDeliver

### _requestAvailable

    protected boolean _requestAvailable

### _request

    protected ThreadLocal<HttpServletRequest> _request

### _publishHandler

    protected AbstractBayeux.Handler _publishHandler

### _metaPublishHandler

    protected AbstractBayeux.Handler _metaPublishHandler

### _extensions

    protected List<Extension> _extensions

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

### addFilter

    public void addFilter(String channels,
                          DataFilter filter)

  Deprecated. user `Channel#addFilter`

  Specified by:
    `addFilter` in interface `Bayeux`
  Parameters:
    `channels` - A `ChannelId`
    `filter` - The filter instance to apply to new channels matching the pattern

### removeFilter

    public void removeFilter(String channels,
                             DataFilter filter)

  Specified by:
    `removeFilter` in interface `Bayeux`

### addExtension

    public void addExtension(Extension ext)

### getExtensions

    public List<Extension> getExtensions()

### removeExtension

    public void removeExtension(Extension ext)

### getChannel

    public ChannelImpl getChannel(ChannelId id)

  Parameters:
    `id` -
  Returns:

### getChannel

    public ChannelImpl getChannel(String id)

### getChannel

    public Channel getChannel(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(String id)

### getClient

    public Client getClient(String client_id)

  Specified by:
    `getClient` in interface `Bayeux`

### getClientIDs

    public Set<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()

  Specified by:
    `getSecurityPolicy` in interface `Bayeux`

### 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)

  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 String handle(ClientImpl client,
                         Transport transport,
                         Message message)
                  throws 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:
    `IOException`

### hasChannel

    public boolean hasChannel(String id)

  Specified by:
    `hasChannel` in interface `Bayeux`

### isInitialized

    public boolean isInitialized()

### isJSONCommented

    public boolean isJSONCommented()

  Returns:
    the commented

### isLogDebug

    public boolean isLogDebug()

### isLogInfo

    public boolean isLogInfo()

### logDebug

    public void logDebug(String message)

### logDebug

    public void logDebug(String message,
                         Throwable th)

### logWarn

    public void logWarn(String message,
                        Throwable th)

### logWarn

    public void logWarn(String message)

### logInfo

    public void logInfo(String message)

### newClient

    public Client newClient(String idPrefix)

  Specified by:
    `newClient` in interface `Bayeux`

### newClient

    public Client newClient(String idPrefix,
                            Listener listener)

  Deprecated. use `newClient(String)`

  Specified by:
    `newClient` in interface `Bayeux`

### newRemoteClient

    public abstract ClientImpl newRemoteClient()

### newTransport

    public Transport newTransport(ClientImpl client,
                                  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,
                             Object data,
                             String msgId)

  Publish data to a channel. Creates a message and delivers it to the root channel.

  Parameters:
    `to` -
    `from` -
    `data` -
    `msgId` -

### publish

    public void publish(Client fromClient,
                        String toChannelId,
                        Object data,
                        String msgId)

  Deprecated. use `Channel.publish(Client, Object, String)`

  Description copied from interface: `Bayeux`
  Deliver data to a channel.

  Specified by:
    `publish` in interface `Bayeux`
  Parameters:
    `fromClient` - The client sending the data
    `toChannelId` - The Channel ID to which the data is targetted
    `data` - The data itself which must be an Object that can be encoded with `JSON`.
    `msgId` - optional message ID or null for automatic generation of a message ID.

### deliver

    public void deliver(Client fromClient,
                        Client toClient,
                        String toChannel,
                        Message message)

  Deprecated. use `Client.deliver(Client, Message)`

  (non-Javadoc)

  Specified by:
    `deliver` in interface `Bayeux`
  See Also:
    `Bayeux.deliver(dojox.cometd.Client, dojox.cometd.Client, java.lang.String, dojox.cometd.Message)`

### removeChannel

    public boolean removeChannel(ChannelId channelId)

### removeClient

    public Client removeClient(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)

### 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 HttpServletRequest getCurrentRequest()

  Returns:
    the current request if `isRequestAvailable()` is true, else null

### subscribe

    public void subscribe(String toChannel,
                          Client subscriber)

  Description copied from interface: `Bayeux`
  Subscribe to a channel. Equivalent to getChannel(toChannel).subscribe(subscriber).

  Specified by:
    `subscribe` in interface `Bayeux`

### unsubscribe

    public void unsubscribe(String toChannel,
                            Client subscriber)

  Description copied from interface: `Bayeux`
  Unsubscribe to a channel

  Specified by:
    `unsubscribe` in interface `Bayeux`

### getMultiFrameInterval

    public int getMultiFrameInterval()

  Returns:
    the multiFrameInterval in milliseconds

### 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

### getAdvice

    public Object getAdvice()

### setAdvice

    public void setAdvice(Object advice)

### getChannels

    public 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.

### getClients

    public Collection<Client> getClients()

  Specified by:
    `getClients` in interface `Bayeux`

### hasClient

    public boolean hasClient(String clientId)

  Specified by:
    `hasClient` in interface `Bayeux`

### removeChannel

    public Channel removeChannel(String channelId)

  Specified by:
    `removeChannel` in interface `Bayeux`

### initialize

    protected void initialize(ServletContext context)

Copyright © 2008 Mort Bay Consulting. All Rights Reserved.