org.cometd.server
Class ClientImpl

java.lang.Object
  extended by org.cometd.server.ClientImpl
All Implemented Interfaces:
Client
Direct Known Subclasses:
ContinuationClient

public class ClientImpl
extends java.lang.Object
implements Client

Author:
gregw

Field Summary
protected  AbstractBayeux _bayeux
           
 
Constructor Summary
protected ClientImpl(AbstractBayeux bayeux)
           
protected ClientImpl(AbstractBayeux bayeux, java.lang.String idPrefix)
           
 
Method Summary
 void addExtension(Extension ext)
          Adds a bayeux client extension.
 void addListener(ClientListener listener)
          Adds a listener.
protected  void addSubscription(ChannelImpl channel)
           
 void deliver(Client from, java.lang.String toChannel, java.lang.Object data, java.lang.String id)
          Delivers a message to the remote client represented by this object.
 void deliverLazy(Client from, java.lang.String toChannel, java.lang.Object data, java.lang.String id)
           
 void disconnect()
          Disconnects this Client from the server.
 void doDeliverListeners()
           
protected  void doDelivery(Client from, Message msg)
           
 void endBatch()
          Ends a batch of messages.
 boolean equals(java.lang.Object o)
           
 JSON.Literal getAdvice()
          Get the advice specific for this Client
 java.lang.String getBrowserId()
           
 java.lang.String getConnectionType()
           
 java.lang.String getId()
           
 long getInterval()
           
 int getLag()
           
 int getMaxQueue()
           
 int getMessages()
           
 java.util.Queue<Message> getQueue()
           
 Channel[] getSubscriptions()
          Get the subscribed to channels
 long getTimeout()
           
 boolean hasMessages()
           
 boolean hasNonLazyMessages()
           
 boolean isExpired()
           
 boolean isLocal()
           
 boolean isMetaConnectDeliveryOnly()
           
 void lazyResume()
          Called by deliver to resume anything waiting on this client lazily
 void remove(boolean timeout)
           
 void removeExtension(Extension ext)
          Removes a bayeux client extension.
 void removeListener(ClientListener listener)
          Removes a listener
protected  void removeSubscription(ChannelImpl channel)
           
 int responded()
           
 int responsePending()
           
 void resume()
          Called by deliver to resume anything waiting on this client.
 void returnMessages(java.util.List<Message> messages)
           
 void setAdvice(JSON.Literal advice)
           
 void setBrowserId(java.lang.String id)
           
protected  void setConnectionType(java.lang.String type)
           
protected  void setId(java.lang.String id)
           
 void setInterval(long intervalMS)
          Set per client interval
 void setLag(int lag)
           
 void setMaxQueue(int maxQueue)
           
 void setMetaConnectDeliveryOnly(boolean deliverViaMetaConnectOnly)
           
 void setTimeout(long timeoutMS)
          Set per client timeout
 void startBatch()
          Starts a batch of messages.
 java.util.List<Message> takeMessages()
          Takes any messages queued for a client.
 java.lang.String toString()
           
 void unsubscribeAll()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_bayeux

protected AbstractBayeux _bayeux
Constructor Detail

ClientImpl

protected ClientImpl(AbstractBayeux bayeux)

ClientImpl

protected ClientImpl(AbstractBayeux bayeux,
                     java.lang.String idPrefix)
Method Detail

addExtension

public void addExtension(Extension ext)
Description copied from interface: Client
Adds a bayeux client extension. A bayeux client extension may examine a message or return a new message. A bayeux client extension should not modify a message as it may be sent to multile clients, instead it should clone the passed message.

Specified by:
addExtension in interface Client
Parameters:
ext - the extension to add
See Also:
Client.removeExtension(Extension)

removeExtension

public void removeExtension(Extension ext)
Description copied from interface: Client
Removes a bayeux client extension.

Specified by:
removeExtension in interface Client
Parameters:
ext - the extension to remove��
See Also:
Client.addExtension(Extension)

deliver

public void deliver(Client from,
                    java.lang.String toChannel,
                    java.lang.Object data,
                    java.lang.String id)
Description copied from interface: Client
Delivers a message to the remote client represented by this object.

Specified by:
deliver in interface Client
Parameters:
from - the Client that sends the message
toChannel - the channel onto which the message is sent
data - the data of the message
id - the message ID

deliverLazy

public void deliverLazy(Client from,
                        java.lang.String toChannel,
                        java.lang.Object data,
                        java.lang.String id)

doDelivery

protected void doDelivery(Client from,
                          Message msg)

doDeliverListeners

public void doDeliverListeners()

setMetaConnectDeliveryOnly

public void setMetaConnectDeliveryOnly(boolean deliverViaMetaConnectOnly)

isMetaConnectDeliveryOnly

public boolean isMetaConnectDeliveryOnly()

startBatch

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

Specified by:
startBatch in interface Client
See Also:
Client.endBatch()

endBatch

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

Specified by:
endBatch in interface Client
See Also:
Client.startBatch()

getConnectionType

public java.lang.String getConnectionType()

getId

public java.lang.String getId()
Specified by:
getId in interface Client
Returns:
the unique ID representing this client

hasMessages

public boolean hasMessages()
Specified by:
hasMessages in interface Client
Returns:
whether or not this client has messages to send

hasNonLazyMessages

public boolean hasNonLazyMessages()

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.

disconnect

public void disconnect()
Description copied from interface: Client
Disconnects this Client from the server.

Specified by:
disconnect in interface Client

remove

public void remove(boolean timeout)

isExpired

public boolean isExpired()

responded

public int responded()

responsePending

public int responsePending()

lazyResume

public void lazyResume()
Called by deliver to resume anything waiting on this client lazily


resume

public void resume()
Called by deliver to resume anything waiting on this client.


getMessages

public int getMessages()

takeMessages

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

Specified by:
takeMessages in interface Client

returnMessages

public void returnMessages(java.util.List<Message> messages)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

addSubscription

protected void addSubscription(ChannelImpl channel)

removeSubscription

protected void removeSubscription(ChannelImpl channel)

setConnectionType

protected void setConnectionType(java.lang.String type)

setId

protected void setId(java.lang.String id)

unsubscribeAll

public void unsubscribeAll()

setBrowserId

public void setBrowserId(java.lang.String id)

getBrowserId

public java.lang.String getBrowserId()

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

getAdvice

public JSON.Literal getAdvice()
Get the advice specific for this Client

Returns:
advice specific for this client or null

setAdvice

public void setAdvice(JSON.Literal advice)
Parameters:
advice - specific for this client

addListener

public void addListener(ClientListener listener)
Description copied from interface: Client
Adds a listener.

Specified by:
addListener in interface Client
Parameters:
listener - the listener to add
See Also:
Client.removeListener(ClientListener)

removeListener

public void removeListener(ClientListener listener)
Description copied from interface: Client
Removes a listener

Specified by:
removeListener in interface Client
Parameters:
listener - the listener to remove
See Also:
Client.addListener(ClientListener)

getInterval

public long getInterval()

setInterval

public void setInterval(long intervalMS)
Set per client interval

Parameters:
intervalMS - timeout in MS for longpoll duration or 0 to use default from AbstractBayeux.getMaxInterval().

getTimeout

public long getTimeout()

setTimeout

public void setTimeout(long timeoutMS)
Set per client timeout

Parameters:
timeoutMS - timeout in MS for longpoll duration or 0 to use default from AbstractBayeux.getTimeout().

setMaxQueue

public void setMaxQueue(int maxQueue)
Specified by:
setMaxQueue in interface Client
Parameters:
maxQueue - The size which if a client queue exceeds, forces a call to QueueListener.queueMaxed(Client, Client, Message) to check if the message should be added. If set to -1, there is no queue limit. If set to zero, messages are not queued.
See Also:
Client.getMaxQueue()

getMaxQueue

public int getMaxQueue()
Specified by:
getMaxQueue in interface Client
Returns:
the max queue size
See Also:
Client.setMaxQueue(int)

getQueue

public java.util.Queue<Message> getQueue()
Specified by:
getQueue in interface Client
Returns:
the message queue (its usage must synchronize on this Client instance).

getLag

public int getLag()
Returns:
The lag in ms as measured by an extension like the TimesyncExtension
See Also:
TimesyncExtension

setLag

public void setLag(int lag)
Parameters:
lag - in ms
See Also:
TimesyncExtension

getSubscriptions

public Channel[] getSubscriptions()
Get the subscribed to channels

Returns:
A copied array of the channels to which this client is subscribed


Copyright © 2011 Dojo Foundation. All Rights Reserved.