org.cometd.server
Class AbstractService

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

public abstract class AbstractService
extends Object

Abstract Bayeux Service

This class provides convenience methods to assist with the creation of a Bayeux Services typically used to provide the behaviour associated with a service channel (see Channel.isService()). Specifically it provides:

See Also:
BayeuxServer#getSession(String)} as an alternative to AbstractService.

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

Constructor Detail

AbstractService

public AbstractService(BayeuxServer bayeux,
                       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).

AbstractService

public AbstractService(BayeuxServer bayeux,
                       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()

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)

addService

protected void addService(String channelId,
                          String methodName)
Add a service.

Listen to a 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,
                    String onChannel,
                    Object data,
                    String 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(String method,
                         ServerSession fromClient,
                         LocalSession toClient,
                         ServerMessage msg,
                         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 -

doInvoke

protected void doInvoke(Method method,
                        ServerSession fromClient,
                        ServerMessage msg)


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