org.mortbay.cometd.client
Class BayeuxClient

java.lang.Object
  extended by org.mortbay.component.AbstractLifeCycle
      extended by org.mortbay.cometd.client.BayeuxClient
All Implemented Interfaces:
org.cometd.Client, LifeCycle
Direct Known Subclasses:
OortComet

public class BayeuxClient
extends AbstractLifeCycle
implements org.cometd.Client

Bayeux protocol Client.

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

The HttpClient attributes are used to share a Timer and MessagePool instance between all Bayeux clients sharing the same HttpClient.

Author:
gregw
See Also:
http://cometd.org

Nested Class Summary
protected  class BayeuxClient.Connect
          The Bayeux Connect exchange.
protected  class BayeuxClient.Exchange
          The base class for all bayeux exchanges.
protected  class BayeuxClient.Handshake
          The Bayeux handshake exchange.
protected  class BayeuxClient.Publish
          Publish message exchange.
 
Nested classes/interfaces inherited from interface org.mortbay.component.LifeCycle
LifeCycle.Listener
 
Field Summary
protected  Address _cometdAddress
           
protected  org.cometd.Extension[] _extensions
           
protected  HttpClient _httpClient
           
protected  JSON _jsonOut
           
protected  MessagePool _msgPool
           
 
Fields inherited from class org.mortbay.component.AbstractLifeCycle
_listeners
 
Constructor Summary
BayeuxClient(HttpClient client, Address address, String uri)
           
BayeuxClient(HttpClient client, Address address, String path, Timer timer)
           
BayeuxClient(HttpClient client, String url)
           
BayeuxClient(HttpClient client, String url, Timer timer)
           
 
Method Summary
 void addExtension(org.cometd.Extension ext)
           
 void addListener(org.cometd.ClientListener listener)
           
protected  void customize(HttpExchange exchange)
          Customize an Exchange.
 void deliver(org.cometd.Client from, org.cometd.Message message)
          (non-Javadoc)
 void deliver(org.cometd.Client from, String toChannel, Object data, String id)
           
 void disconnect()
          Disconnect this client.
protected  void doStart()
           
protected  void doStop()
           
 void endBatch()
           
protected  void extendIn(org.cometd.Message message)
          Called to extend inbound messages
protected  void extendOut(org.cometd.Message message)
          Called to extend outbound messages
protected  String extendOut(String msg)
          Called to extend outbound string messages.
 int getBackoffIncrement()
           
 int getBackoffInterval()
           
 int getBackoffMaxInterval()
           
 int getBackoffMaxRetries()
          Deprecated.  
 Cookie getCookie(String name)
           
 String getId()
           
 org.cometd.Listener getListener()
          Deprecated.  
 int getMaxQueue()
           
 Queue<org.cometd.Message> getQueue()
           
 boolean hasMessages()
           
protected  boolean isInitialized()
           
 boolean isLocal()
           
 boolean isPolling()
           
protected  void metaConnect(boolean success, org.cometd.Message message)
          Called with the results of a /meta/connect message
protected  void metaHandshake(boolean success, boolean reestablish, org.cometd.Message message)
          Called with the results of a /meta/handshake message
protected  void metaPublishFail(Throwable e, org.cometd.Message[] messages)
          Called with the results of a failed publish
 void publish(String toChannel, Object data, String msgId)
           
 void remove()
          Deprecated. use disconnect()
 void removeListener(org.cometd.ClientListener listener)
           
protected  boolean send(BayeuxClient.Exchange exchange, boolean backoff)
          Send the exchange, possibly using a backoff.
protected  void send(HttpExchange exchange)
          Send the exchange.
 void setBackoffIncrement(int interval)
          .
 void setBackOffInterval(int interval)
          If unable to connect/handshake etc, even if following the interval in the advice, wait for this interval initially, and try again.
 void setBackoffMaxInterval(int interval)
           
 void setBackoffMaxRetries(int retries)
          Deprecated. We retry an infinite number of times. use getBackoffIncrement() to set limits
 void setCookie(Cookie cookie)
           
protected  void setInitialized(boolean b)
          False when we have received a success=false message in response to a Connect, or we have had an exception when sending or receiving a Connect.
 void setListener(org.cometd.Listener listener)
          Deprecated.  
 void setMaxQueue(int max)
           
 void startBatch()
           
 void subscribe(String toChannel)
           
 List<org.cometd.Message> takeMessages()
           
 void unsubscribe(String toChannel)
           
 
Methods inherited from class org.mortbay.component.AbstractLifeCycle
addLifeCycleListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_httpClient

protected HttpClient _httpClient

_msgPool

protected MessagePool _msgPool

_cometdAddress

protected Address _cometdAddress

_extensions

protected org.cometd.Extension[] _extensions

_jsonOut

protected JSON _jsonOut
Constructor Detail

BayeuxClient

public BayeuxClient(HttpClient client,
                    String url)

BayeuxClient

public BayeuxClient(HttpClient client,
                    String url,
                    Timer timer)

BayeuxClient

public BayeuxClient(HttpClient client,
                    Address address,
                    String path,
                    Timer timer)

BayeuxClient

public BayeuxClient(HttpClient client,
                    Address address,
                    String uri)
Method Detail

addExtension

public void addExtension(org.cometd.Extension ext)
Specified by:
addExtension in interface org.cometd.Client

setBackOffInterval

public void setBackOffInterval(int interval)
If unable to connect/handshake etc, even if following the interval in the advice, wait for this interval initially, and try again.

Parameters:
interval -

getBackoffInterval

public int getBackoffInterval()
Returns:
the backoff interval to wait before retrying an unsuccessful or failed message

setBackoffMaxRetries

public void setBackoffMaxRetries(int retries)
Deprecated. We retry an infinite number of times. use getBackoffIncrement() to set limits


getBackoffMaxRetries

public int getBackoffMaxRetries()
Deprecated. 


setBackoffIncrement

public void setBackoffIncrement(int interval)
. Each retry will increment by this intervel, until we reach _backoffMaxInterval


getBackoffIncrement

public int getBackoffIncrement()
Returns:
the backoff interval used to increase the backoff time when retrying an unsuccessful or failed message.

setBackoffMaxInterval

public void setBackoffMaxInterval(int interval)

getBackoffMaxInterval

public int getBackoffMaxInterval()

getId

public String getId()
Specified by:
getId in interface org.cometd.Client

doStart

protected void doStart()
                throws Exception
Overrides:
doStart in class AbstractLifeCycle
Throws:
Exception

doStop

protected void doStop()
               throws Exception
Overrides:
doStop in class AbstractLifeCycle
Throws:
Exception

isPolling

public boolean isPolling()

deliver

public void deliver(org.cometd.Client from,
                    org.cometd.Message message)
(non-Javadoc)


deliver

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

getListener

public org.cometd.Listener getListener()
Deprecated. 


hasMessages

public boolean hasMessages()
Specified by:
hasMessages in interface org.cometd.Client

isLocal

public boolean isLocal()
Specified by:
isLocal in interface org.cometd.Client

publish

public void publish(String toChannel,
                    Object data,
                    String msgId)

subscribe

public void subscribe(String toChannel)

unsubscribe

public void unsubscribe(String toChannel)

remove

public void remove()
Deprecated. use disconnect()

Disconnect this client.


disconnect

public void disconnect()
Disconnect this client.

Specified by:
disconnect in interface org.cometd.Client

setListener

public void setListener(org.cometd.Listener listener)
Deprecated. 


takeMessages

public List<org.cometd.Message> takeMessages()
Specified by:
takeMessages in interface org.cometd.Client

endBatch

public void endBatch()
Specified by:
endBatch in interface org.cometd.Client

startBatch

public void startBatch()
Specified by:
startBatch in interface org.cometd.Client

customize

protected void customize(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(Cookie cookie)

getCookie

public Cookie getCookie(String name)

addListener

public void addListener(org.cometd.ClientListener listener)
Specified by:
addListener in interface org.cometd.Client

removeListener

public void removeListener(org.cometd.ClientListener listener)
Specified by:
removeListener in interface org.cometd.Client

getMaxQueue

public int getMaxQueue()
Specified by:
getMaxQueue in interface org.cometd.Client

getQueue

public Queue<org.cometd.Message> getQueue()
Specified by:
getQueue in interface org.cometd.Client

setMaxQueue

public void setMaxQueue(int max)
Specified by:
setMaxQueue in interface org.cometd.Client

send

protected boolean send(BayeuxClient.Exchange exchange,
                       boolean backoff)
Send the exchange, possibly using a backoff.

Parameters:
exchange -
backoff - if true, use backoff algorithm to send
Returns:

send

protected void send(HttpExchange exchange)
             throws IOException
Send the exchange.

Parameters:
exchange -
Throws:
IOException

setInitialized

protected void setInitialized(boolean b)
False when we have received a success=false message in response to a Connect, or we have had an exception when sending or receiving a Connect. True when handshake and then connect has happened.

Parameters:
b -

isInitialized

protected boolean isInitialized()

metaConnect

protected void metaConnect(boolean success,
                           org.cometd.Message message)
Called with the results of a /meta/connect message

Parameters:
success - connect was returned with this status

metaHandshake

protected void metaHandshake(boolean success,
                             boolean reestablish,
                             org.cometd.Message message)
Called with the results of a /meta/handshake message

Parameters:
success - connect was returned with this status
reestablish - the client was previously connected.

metaPublishFail

protected void metaPublishFail(Throwable e,
                               org.cometd.Message[] messages)
Called with the results of a failed publish


extendOut

protected String extendOut(String msg)
Called to extend outbound string messages. Some messages are sent as preformatted JSON strings (eg handshake and connect messages). This extendOut method is a variation of the extendOut(Message) method to efficiently cater for these preformatted strings.

This method calls the Extensions added by addExtension(Extension)

Parameters:
msg -
Returns:
the extended message

extendOut

protected void extendOut(org.cometd.Message message)
Called to extend outbound messages

This method calls the Extensions added by addExtension(Extension)


extendIn

protected void extendIn(org.cometd.Message message)
Called to extend inbound messages

This method calls the Extensions added by addExtension(Extension)



Copyright © 1995-2009 Mort Bay Consulting. All Rights Reserved.