org.mortbay.cometd.client
Class BayeuxClient

java.lang.Object
  extended by org.mortbay.cometd.MessagePool
      extended by org.mortbay.cometd.client.BayeuxClient
All Implemented Interfaces:
Client

public class BayeuxClient
extends org.mortbay.cometd.MessagePool
implements Client

Bayeux protocol Client.

Implements a Bayeux Ajax Push client as part of the cometd project.

Author:
gregw Modified by Bjarki Bjorgulfsson to work with Grizzly
See Also:
http://cometd.com

Constructor Summary
BayeuxClient(org.mortbay.jetty.client.HttpClient client, InetSocketAddress address, String uri)
           
 
Method Summary
 void addListener(EventListener listener)
           
protected  void customize(org.mortbay.jetty.client.HttpExchange exchange)
          Customize an Exchange.
 void deliver(Client from, Message message)
          Deprecated. use deliver(Client, String, Object, String)
 void deliver(Client from, String toChannel, Object data, String id)
           
 void endBatch()
          End a batch of messages.
 String getId()
           
 Listener getListener()
          Deprecated.  
 int getNextMsgId()
           
 boolean hasMessages()
           
 boolean isLocal()
           
 boolean isPolling()
           
 Message[] parse(String s)
           
 void publish(String toChannel, Object data, String msgId)
          Publish data from this client.
 void remove(boolean timeout)
           
 void removeListener(EventListener listener)
           
 void setCookie(javax.servlet.http.Cookie cookie)
           
 void setListener(Listener listener)
          Deprecated.  
 void start()
           
 void startBatch()
          Start a batch of messages.
 void stop()
           
 void subscribe(String toChannel)
          Subscribe this client to a channel.
 List<Message> takeMessages()
          Take any messages queued for a client.
 void unsubscribe(String toChannel)
          Unsubscribe this client from a channel.
 
Methods inherited from class org.mortbay.cometd.MessagePool
getBatchJSON, getJSON, getMsgJSON, newMessage, newMessage, parse, parseTo, recycleMessage, setBatchJSON, setJSON, setMsgJSON
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BayeuxClient

public BayeuxClient(org.mortbay.jetty.client.HttpClient client,
                    InetSocketAddress address,
                    String uri)
             throws IOException
Throws:
IOException
Method Detail

getId

public String getId()
Specified by:
getId in interface Client

start

public void start()

stop

public void stop()

isPolling

public boolean isPolling()

deliver

public void deliver(Client from,
                    Message message)
Deprecated. use deliver(Client, String, Object, String)

(non-Javadoc)

Specified by:
deliver in interface Client
Parameters:
from - The Client that published the message, or null if not known/available
See Also:
dojox.cometd.Client#deliver(dojox.cometd.Client, java.util.Map)

deliver

public void deliver(Client from,
                    String toChannel,
                    Object data,
                    String id)
Specified by:
deliver in interface Client

getListener

public Listener getListener()
Deprecated. 

Specified by:
getListener in interface Client

hasMessages

public boolean hasMessages()
Specified by:
hasMessages in interface Client

isLocal

public boolean isLocal()
Specified by:
isLocal in interface Client
Returns:
True if the client is local. False if this client is either a remote HTTP client or a java client to a remote server.

publish

public void publish(String toChannel,
                    Object data,
                    String msgId)
Description copied from interface: Client
Publish data from this client. This is equivalent to Bayeux.publish(Client, String, Object, String) with this client passed as the fromClient.

Specified by:
publish in interface Client
Parameters:
toChannel - The Channel ID to which the data is targetted
data - The data itself which must be an Object that can be encoded with JSON.
msgId - optional message ID or null for automatic generation of a message ID.

subscribe

public void subscribe(String toChannel)
Description copied from interface: Client
Subscribe this client to a channel. This is equivalent to Bayeux.subscribe(String, Client) with this client passed. Equivalent to getChannel(toChannel).subscribe(subscriber).

Specified by:
subscribe in interface Client

unsubscribe

public void unsubscribe(String toChannel)
Description copied from interface: Client
Unsubscribe this client from a channel. This is equivalent to Bayeux.unsubscribe(String, Client) with this client passed.

Specified by:
unsubscribe in interface Client

remove

public void remove(boolean timeout)

setListener

public void setListener(Listener listener)
Deprecated. 

Specified by:
setListener in interface Client

takeMessages

public List<Message> takeMessages()
Description copied from interface: Client
Take any messages queued for a client.

Specified by:
takeMessages in interface Client

endBatch

public void endBatch()
Description copied from interface: Client
End a batch of messages. Messages will not be delivered that have been queued since the previous startBatch is called. Batches may be nested and messages are only sent once all batches are ended.

Specified by:
endBatch in interface Client

startBatch

public void startBatch()
Description copied from interface: Client
Start a batch of messages. Messages will not be delivered remotely until the corresponding endBatch is called. Batches may be nested and messages are only sent once all batches are ended.

Specified by:
startBatch in interface Client

customize

protected void customize(org.mortbay.jetty.client.HttpExchange exchange)
Customize an Exchange. Called when an exchange is about to be sent to allow Cookies and Credentials to be customized. Default implementation sets any cookies


setCookie

public void setCookie(javax.servlet.http.Cookie cookie)

parse

public Message[] parse(String s)
                throws IOException
Overrides:
parse in class org.mortbay.cometd.MessagePool
Throws:
IOException

addListener

public void addListener(EventListener listener)
Specified by:
addListener in interface Client

removeListener

public void removeListener(EventListener listener)
Specified by:
removeListener in interface Client

getNextMsgId

public int getNextMsgId()
Returns:
the _initialized


Copyright © 2013 Oracle Corporation. All Rights Reserved.