org.cometd.server
Class BayeuxService

java.lang.Object
  extended by org.cometd.server.BayeuxService

public abstract class BayeuxService
extends java.lang.Object

Abstract Bayeux Service class. This is a base class to assist with the creation of server side @ link Bayeux} clients that provide services to remote Bayeux clients. The class provides a Bayeux Client and Listener together with convenience methods to map subscriptions to methods on the derived class and to send responses to those methods.

If a #set_threadPool(ThreadPool) is set, then messages are handled in their own threads. This is desirable if the handling of a message can take considerable time and it is desired not to hold up the delivering thread (typically a HTTP request handling thread).

If the BayeuxService is constructed asynchronously (the default), then messages are delivered unsynchronized and multiple simultaneous calls to handling methods may occur.

If the BayeuxService is constructed as a synchronous service, then message delivery is synchronized on the internal Client instances used and only a single call will be made to the handler method (unless a thread pool is used).

Author:
gregw
See Also:
ServerSession.MessageListener

Constructor Summary
BayeuxService(BayeuxServer bayeux, java.lang.String name)
          Instantiate the service.
BayeuxService(BayeuxServer bayeux, java.lang.String name, int maxThreads)
          Instantiate the service.
 
Method Summary
protected  void exception(java.lang.String method, ServerSession fromClient, LocalSession toClient, ServerMessage msg, java.lang.Throwable th)
          Handle Exception.
 BayeuxServer getBayeux()
           
 LocalSession getClient()
          Deprecated. use getLocalSession() or getServerSession()
 LocalSession getLocalSession()
           
 ServerSession getServerSession()
           
 org.eclipse.jetty.util.thread.ThreadPool getThreadPool()
           
 boolean isSeeOwnPublishes()
           
protected  void send(ServerSession toClient, java.lang.String onChannel, java.lang.Object data, java.lang.Object id)
          Send data to a individual client.
 void setSeeOwnPublishes(boolean own)
           
 void setThreadPool(org.eclipse.jetty.util.thread.ThreadPool pool)
          Set the threadpool.
protected  void subscribe(java.lang.String channelId, java.lang.String methodName)
          Subscribe to a channel.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BayeuxService

public BayeuxService(BayeuxServer bayeux,
                     java.lang.String name)
Instantiate the service. Typically the derived constructor will call @ #subscribe(String, String)} to map subscriptions to methods.

Parameters:
bayeux - The bayeux instance.
name - The name of the service (used as client ID prefix).

BayeuxService

public BayeuxService(BayeuxServer bayeux,
                     java.lang.String name,
                     int maxThreads)
Instantiate the service. Typically the derived constructor will call @ #subscribe(String, String)} to map subscriptions to methods.

Parameters:
bayeux - The bayeux instance.
name - The name of the service (used as client ID prefix).
maxThreads - The size of a ThreadPool to create to handle messages.
Method Detail

getBayeux

public BayeuxServer getBayeux()

getClient

public LocalSession getClient()
Deprecated. use getLocalSession() or getServerSession()


getLocalSession

public LocalSession getLocalSession()

getServerSession

public ServerSession getServerSession()

getThreadPool

public org.eclipse.jetty.util.thread.ThreadPool getThreadPool()

setThreadPool

public void setThreadPool(org.eclipse.jetty.util.thread.ThreadPool pool)
Set the threadpool. If the ThreadPool is a LifeCycle, then it is started by this method.

Parameters:
pool -

isSeeOwnPublishes

public boolean isSeeOwnPublishes()

setSeeOwnPublishes

public void setSeeOwnPublishes(boolean own)

subscribe

protected void subscribe(java.lang.String channelId,
                         java.lang.String methodName)
Subscribe to a channel. Subscribe to channel and map a method to handle received messages. The method must have a unique name and one of the following signatures:

send

protected void send(ServerSession toClient,
                    java.lang.String onChannel,
                    java.lang.Object data,
                    java.lang.Object id)
Send data to a individual client. The data passed is sent to the client as the "data" member of a message with the given channel and id. The message is not published on the channel and is thus not broadcast to all channel subscribers. However to the target client, the message appears as if it was broadcast.

Typcially this method is only required if a service method sends response(s) to channels other than the subscribed channel. If the response is to be sent to the subscribed channel, then the data can simply be returned from the subscription method.

Parameters:
toClient - The target client
onChannel - The channel the message is for
data - The data of the message
id - The id of the message (or null for a random id).

exception

protected void exception(java.lang.String method,
                         ServerSession fromClient,
                         LocalSession toClient,
                         ServerMessage msg,
                         java.lang.Throwable th)
Handle Exception. This method is called when a mapped subscription method throws and exception while handling a message.

Parameters:
fromClient -
toClient -
msg -
th -


Copyright © 2010 Dojo Foundation. All Rights Reserved.