org.apache.tomcat.bayeux
Class TomcatBayeux

java.lang.Object
  extended by org.apache.tomcat.bayeux.TomcatBayeux
All Implemented Interfaces:
Bayeux

public class TomcatBayeux
extends java.lang.Object
implements Bayeux

Version:
1.0
Author:
Filip Hanik

Field Summary
protected  java.util.LinkedHashMap<java.lang.String,Channel> channels
          a list of all active channels
protected  java.util.HashMap<java.lang.String,Client> clients
          a list of all active clients
protected static ClientImpl errorClient
          default client to use when we need to send an error message but don't have a client valid reference
protected  int reconnectInterval
           
protected  SecurityPolicy securityPolicy
          security policy to be used.
 
Fields inherited from interface org.apache.cometd.bayeux.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_RECONNECT, 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 TomcatBayeux()
           
 
Method Summary
 java.lang.String createUUID(java.lang.String idprefix)
           
 void destroy()
          should be invoked when the servlet is destroyed or when the context shuts down
 Channel getChannel(java.lang.String channelId, boolean create)
          Returns the channel for a given channel id.
 java.util.List<Channel> getChannels()
          Returns a list of currently active channels in this Bayeux session.
 Client getClient(java.lang.String clientId)
          retrieve a client based on an ID.
protected  ClientImpl getClientImpl(org.jboss.servlet.http.HttpEvent event)
           
 java.util.List<Client> getClients()
          Returns a non modifiable list of all the clients that are currently active in this Bayeux session
static ClientImpl getErrorClient()
          returns the default error client
 int getReconnectInterval()
           
 SecurityPolicy getSecurityPolicy()
          Returns the security policy associated with this Bayeux session
 boolean hasChannel(java.lang.String channel)
          returns true if a channel with the given channelId exists.
 boolean hasClient(java.lang.String clientId)
          Returns true if a client with the given id exists.
 Client newClient(java.lang.String idprefix, Listener listener)
          Creates a new server side client.
 Client newClient(java.lang.String idprefix, Listener listener, boolean local, org.jboss.servlet.http.HttpEvent event)
           
protected  Message newMessage()
           
 Message newMessage(Client from)
          Creates a new message to be sent by a server side client.
 Channel remove(Channel channel)
          Removes a channel from the Bayeux object.
 Client remove(Client client)
          Removes the client all together.
protected  void remove(org.jboss.servlet.http.HttpEvent event)
           
 void setReconnectInterval(int reconnectTimeout)
           
 void setSecurityPolicy(SecurityPolicy securityPolicy)
          Sets the security policy to be used in this Bayeux session
protected static java.lang.String toString(byte[] data)
           
protected static java.lang.String toString(byte[] data, int offset, int length)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

reconnectInterval

protected int reconnectInterval

clients

protected java.util.HashMap<java.lang.String,Client> clients
a list of all active clients


channels

protected java.util.LinkedHashMap<java.lang.String,Channel> channels
a list of all active channels


securityPolicy

protected SecurityPolicy securityPolicy
security policy to be used.


errorClient

protected static ClientImpl errorClient
default client to use when we need to send an error message but don't have a client valid reference

Constructor Detail

TomcatBayeux

protected TomcatBayeux()
Method Detail

getErrorClient

public static ClientImpl getErrorClient()
returns the default error client

Returns:
ClientImpl

destroy

public void destroy()
should be invoked when the servlet is destroyed or when the context shuts down


getChannel

public Channel getChannel(java.lang.String channelId,
                          boolean create)
Description copied from interface: Bayeux
Returns the channel for a given channel id. If the channel doesn't exist, and the create parameter is set to true, the channel will be created and added to the list of active channels.
if create is set to false, and the channel doesn't exist, null will be returned.

Specified by:
getChannel in interface Bayeux
Parameters:
channelId - String - the id of the channel to be retrieved or created
create - boolean - true if the Bayeux impl should create the channel
Returns:
Channel - null if create is set to false and the channel doesn't exist, otherwise it returns a channel object.

remove

public Channel remove(Channel channel)
Description copied from interface: Bayeux
Removes a channel from the Bayeux object. This will also unsubscribe all the clients currently subscribed to the the channel.

Specified by:
remove in interface Bayeux
Parameters:
channel - Channel - the channel to be removed
Returns:
Channel - returns the channel that was removed, or null if no channel was removed.

remove

public Client remove(Client client)
Description copied from interface: Bayeux
Removes the client all together. This will unsubscribe the client to any channels it may be subscribed to and remove it from the list.

Specified by:
remove in interface Bayeux
Parameters:
client - Client
Returns:
Client - returns the client that was removed, or null if no client was removed.

getClient

public Client getClient(java.lang.String clientId)
Description copied from interface: Bayeux
retrieve a client based on an ID. Will return null if the client doesn't exist.

Specified by:
getClient in interface Bayeux
Parameters:
clientId - String
Returns:
Client-null if the client doesn't exist.returns the client if it does.

hasClient

public boolean hasClient(java.lang.String clientId)
Description copied from interface: Bayeux
Returns true if a client with the given id exists.
Same as executing getClient(id)!=null.

Specified by:
hasClient in interface Bayeux
Parameters:
clientId - String
Returns:
boolean - true if the client exists

getClients

public java.util.List<Client> getClients()
Description copied from interface: Bayeux
Returns a non modifiable list of all the clients that are currently active in this Bayeux session

Specified by:
getClients in interface Bayeux
Returns:
List - a list containing all clients. The List can not be modified.

getSecurityPolicy

public SecurityPolicy getSecurityPolicy()
Description copied from interface: Bayeux
Returns the security policy associated with this Bayeux session

Specified by:
getSecurityPolicy in interface Bayeux
Returns:
SecurityPolicy

getReconnectInterval

public int getReconnectInterval()

hasChannel

public boolean hasChannel(java.lang.String channel)
Description copied from interface: Bayeux
returns true if a channel with the given channelId exists.
Same as executing Bayeux.getChannel(channelId,false)!=null

Specified by:
hasChannel in interface Bayeux
Parameters:
channel - String
Returns:
boolean - true if the channel exists.

newClient

public Client newClient(java.lang.String idprefix,
                        Listener listener,
                        boolean local,
                        org.jboss.servlet.http.HttpEvent event)

newClient

public Client newClient(java.lang.String idprefix,
                        Listener listener)
Description copied from interface: Bayeux
Creates a new server side client. This method is to be invoked by server side objects only. You cannot create a remote client by using this method. A client represents an entity that can subscribe to channels and publish and receive messages through these channels

Specified by:
newClient in interface Bayeux
Parameters:
idprefix - String - the prefix string for the id generated, can be null
listener - Listener - a callback object to be called when messages are to be delivered to the new client
Returns:
Client - returns an implementation of the client interface.

getClientImpl

protected ClientImpl getClientImpl(org.jboss.servlet.http.HttpEvent event)

remove

protected void remove(org.jboss.servlet.http.HttpEvent event)

createUUID

public java.lang.String createUUID(java.lang.String idprefix)

toString

protected static java.lang.String toString(byte[] data)

toString

protected static java.lang.String toString(byte[] data,
                                           int offset,
                                           int length)

getChannels

public java.util.List<Channel> getChannels()
Description copied from interface: Bayeux
Returns a list of currently active channels in this Bayeux session.

Specified by:
getChannels in interface Bayeux
Returns:
List

newMessage

protected Message newMessage()

newMessage

public Message newMessage(Client from)
Description copied from interface: Bayeux
Creates a new message to be sent by a server side client.

Specified by:
newMessage in interface Bayeux
Returns:
Message - returns a new Message object, that has a unique id.

setSecurityPolicy

public void setSecurityPolicy(SecurityPolicy securityPolicy)
Description copied from interface: Bayeux
Sets the security policy to be used in this Bayeux session

Specified by:
setSecurityPolicy in interface Bayeux
Parameters:
securityPolicy - SecurityPolicy

setReconnectInterval

public void setReconnectInterval(int reconnectTimeout)


Copyright © 2000-2009 Apache Software Foundation. All Rights Reserved.