|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.mortbay.cometd.BayeuxService
public abstract class BayeuxService
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).
MessageListener
Constructor Summary | |
---|---|
BayeuxService(org.cometd.Bayeux bayeux,
String name)
Instantiate the service. |
|
BayeuxService(org.cometd.Bayeux bayeux,
String name,
int maxThreads)
Instantiate the service. |
|
BayeuxService(org.cometd.Bayeux bayeux,
String name,
int maxThreads,
boolean synchronous)
Instantiate the service. |
Method Summary | |
---|---|
protected void |
exception(org.cometd.Client fromClient,
org.cometd.Client toClient,
Map<String,Object> msg,
Throwable th)
Handle Exception. |
org.cometd.Bayeux |
getBayeux()
|
org.cometd.Client |
getClient()
|
ThreadPool |
getThreadPool()
|
boolean |
isSeeOwnPublishes()
|
protected void |
send(org.cometd.Client toClient,
String onChannel,
Object data,
String id)
Send data to a individual client. |
void |
setSeeOwnPublishes(boolean own)
|
void |
setThreadPool(ThreadPool pool)
Set the threadpool. |
protected void |
subscribe(String channelId,
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 |
---|
public BayeuxService(org.cometd.Bayeux bayeux, String name)
bayeux
- The bayeux instance.name
- The name of the service (used as client ID prefix).public BayeuxService(org.cometd.Bayeux bayeux, String name, int maxThreads)
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.public BayeuxService(org.cometd.Bayeux bayeux, String name, int maxThreads, boolean synchronous)
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.synchronous
- True if message delivery will be synchronized on the client.Method Detail |
---|
public org.cometd.Bayeux getBayeux()
public org.cometd.Client getClient()
public ThreadPool getThreadPool()
public void setThreadPool(ThreadPool pool)
ThreadPool
is a LifeCycle
,
then it is started by this method.
pool
- public boolean isSeeOwnPublishes()
public void setSeeOwnPublishes(boolean own)
protected void subscribe(String channelId, String methodName)
myMethod(Client fromClient,Object data)
myMethod(Client fromClient,Object data,String id)
myMethod(Client fromClient,String channel,Object data,String id)
Message
then the message object itself is
passed rather than just the data.
Typically a service will subscribe to a channel in the "/service/**" space which is not a broadcast channel. Messages published to these channels are only delivered to server side clients like this service.
Any object returned by a mapped subscription method is delivered to the
calling client and not broadcast. If the method returns void or null,
then no response is sent. A mapped subscription method may also call
send(Client, String, Object, String)
to deliver a response
message(s) to different clients and/or channels. It may also publish
methods via the normal Bayeux
API.
channelId
- The channel to subscribe tomethodName
- The name of the method on this object to call when messages
are recieved.protected void send(org.cometd.Client toClient, String onChannel, Object data, String id)
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.
toClient
- The target clientonChannel
- The channel the message is fordata
- The data of the messageid
- The id of the message (or null for a random id).protected void exception(org.cometd.Client fromClient, org.cometd.Client toClient, Map<String,Object> msg, Throwable th)
fromClient
- toClient
- msg
- th
-
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |