org.mortbay.cometd
Class BayeuxService

java.lang.Object
  extended by org.mortbay.cometd.BayeuxService
Direct Known Subclasses:
BayeuxStartupListener.ChatService, BayeuxStartupListener.EchoRPC, BayeuxStartupListener.Monitor

public abstract class BayeuxService
extends Object

Abstract Bayeux Service class. This is a base class to assist with the creation of server side 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.

Author:
gregw

Constructor Summary
BayeuxService(Bayeux bayeux, String name)
          Instantiate the service.
 
Method Summary
protected  void exception(Client fromClient, Client toClient, Map<String,Object> msg, Throwable th)
          Handle Exception.
 Bayeux getBayeux()
           
 Client getClient()
           
protected  void send(Client toClient, String onChannel, Object data, String id)
          Send data to a individual client.
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

BayeuxService

public BayeuxService(Bayeux bayeux,
                     String name)
Instantiate the service. Typically the derived constructor will call to map subscriptions to methods.

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

getBayeux

public Bayeux getBayeux()

getClient

public Client getClient()

subscribe

protected void subscribe(String channelId,
                         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(Client 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(Client fromClient,
                         Client toClient,
                         Map<String,Object> 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 -


Copyright © 2008 Mort Bay Consulting. All Rights Reserved.