org.cometd
Interface Client


public interface Client

A Bayeux Client.

A Client instance represents a consumer/producer of messages in bayeux. A Client may subscribe to channels and publish messages to channels.

Client instances should not be directly created by uses, but should be obtained via the Bayeux.getClient(String) or Bayeux.newClient(String) methods.

Two types of client may be represented by this interface:

Version:
$Revision: 1453 $ $Date: 2009-02-25 12:57:20 +0100 (Wed, 25 Feb 2009) $

Method Summary
 void addExtension(Extension ext)
          Adds a bayeux client extension.
 void addListener(ClientListener listener)
          Adds a listener.
 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 disconnect()
          Disconnects this Client from the server.
 void endBatch()
          Ends a batch of messages.
 java.lang.String getId()
           
 int getMaxQueue()
           
 java.util.Queue<Message> getQueue()
           
 boolean hasMessages()
           
 boolean isLocal()
           
 void removeExtension(Extension ext)
          Removes a bayeux client extension.
 void removeListener(ClientListener listener)
          Removes a listener
 void setMaxQueue(int max)
           
 void startBatch()
          Starts a batch of messages.
 java.util.List<Message> takeMessages()
          Deprecated. use addListener(ClientListener) to be notified of messages
 

Method Detail

getId

java.lang.String getId()
Returns:
the unique ID representing this client

hasMessages

boolean hasMessages()
Returns:
whether or not this client has messages to send

takeMessages

java.util.List<Message> takeMessages()
Deprecated. use addListener(ClientListener) to be notified of messages

Takes any messages queued for a client.


deliver

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.

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

addExtension

void addExtension(Extension ext)
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.

Parameters:
ext - the extension to add
See Also:
removeExtension(Extension)

removeExtension

void removeExtension(Extension ext)
Removes a bayeux client extension.

Parameters:
ext - the extension to removeù
See Also:
addExtension(Extension)

addListener

void addListener(ClientListener listener)
Adds a listener.

Parameters:
listener - the listener to add
See Also:
removeListener(ClientListener)

removeListener

void removeListener(ClientListener listener)
Removes a listener

Parameters:
listener - the listener to remove
See Also:
addListener(ClientListener)

isLocal

boolean isLocal()
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.

startBatch

void startBatch()
Starts 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.

See Also:
endBatch()

endBatch

void endBatch()
Ends 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.

See Also:
startBatch()

disconnect

void disconnect()
Disconnects this Client from the server.


getQueue

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

setMaxQueue

void setMaxQueue(int max)
Parameters:
max - 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:
getMaxQueue()

getMaxQueue

int getMaxQueue()
Returns:
the max queue size
See Also:
setMaxQueue(int)


Copyright © 2010 Dojo Foundation. All Rights Reserved.