Class AbstractClientSession
- All Implemented Interfaces:
ClientSession
,Session
,org.eclipse.jetty.util.component.Dumpable
- Direct Known Subclasses:
BayeuxClient
,LocalSessionImpl
public abstract class AbstractClientSession extends Object implements ClientSession, org.eclipse.jetty.util.component.Dumpable
Partial implementation of ClientSession
.
It handles extensions and batching, and provides utility methods to be used by subclasses.
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
AbstractClientSession.AbstractSessionChannel
A channel scoped to aClientSession
.Nested classes/interfaces inherited from interface org.cometd.bayeux.client.ClientSession
ClientSession.Extension, ClientSession.MessageListener
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractClientSession()
-
Method Summary
Modifier and Type Method Description void
addExtension(ClientSession.Extension extension)
Adds an extension to this session.void
batch(Runnable batch)
Executes the given command in a batch so that any Bayeux message sent by the command (via the Bayeux API) is queued up until the end of the command and then all messages are sent at once.String
dump()
void
dump(Appendable out, String indent)
boolean
endBatch()
Ends a batch started withSession.startBatch()
.protected boolean
extendRcv(Message.Mutable message)
protected boolean
extendSend(Message.Mutable message)
Object
getAttribute(String name)
Retrieves the value of named session attribute.Set<String>
getAttributeNames()
ClientSessionChannel
getChannel(String channelName)
Returns a client side channel scoped by this session.ClientSessionChannel
getChannel(ChannelId channelId)
protected ConcurrentMap<String,AbstractClientSession.AbstractSessionChannel>
getChannels()
List<ClientSession.Extension>
getExtensions()
protected boolean
isBatching()
protected abstract AbstractClientSession.AbstractSessionChannel
newChannel(ChannelId channelId)
protected abstract ChannelId
newChannelId(String channelId)
protected Message.Mutable
newMessage()
protected String
newMessageId()
protected void
notifyListener(ClientSessionChannel.MessageListener listener, Message.Mutable message)
protected void
notifyListeners(Message.Mutable message)
void
receive(Message.Mutable message)
Receives a message (from the server) and process it.protected void
registerCallback(String messageId, ClientSessionChannel.MessageListener callback)
protected void
registerSubscriber(String messageId, ClientSessionChannel.MessageListener subscriber)
void
remoteCall(String target, Object data, ClientSession.MessageListener callback)
Performs a remote call to the server, to the specifiedtarget
, and with the givendata
as payload.Object
removeAttribute(String name)
Removes a named session attribute.void
removeExtension(ClientSession.Extension extension)
Removes an extension from this session.protected void
resetSubscriptions()
protected abstract void
send(Message.Mutable message)
protected abstract void
sendBatch()
void
setAttribute(String name, Object value)
Sets a named session attribute value.void
startBatch()
Starts a batch, to be ended withSession.endBatch()
.protected ClientSessionChannel.MessageListener
unregisterCallback(String messageId)
protected ClientSessionChannel.MessageListener
unregisterSubscriber(String messageId)
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.cometd.bayeux.client.ClientSession
disconnect, handshake, handshake, handshake
Methods inherited from interface org.cometd.bayeux.Session
disconnect, getId, isConnected, isHandshook
-
Constructor Details
-
AbstractClientSession
protected AbstractClientSession()
-
-
Method Details
-
newMessageId
-
addExtension
Description copied from interface:ClientSession
Adds an extension to this session.- Specified by:
addExtension
in interfaceClientSession
- Parameters:
extension
- the extension to add- See Also:
ClientSession.removeExtension(Extension)
-
removeExtension
Description copied from interface:ClientSession
Removes an extension from this session.- Specified by:
removeExtension
in interfaceClientSession
- Parameters:
extension
- the extension to remove- See Also:
ClientSession.addExtension(Extension)
-
getExtensions
- Specified by:
getExtensions
in interfaceClientSession
- Returns:
- an immutable list of extensions present in this ClientSession instance
- See Also:
ClientSession.addExtension(Extension)
-
extendSend
-
extendRcv
-
newChannelId
-
newChannel
-
getChannel
Description copied from interface:ClientSession
Returns a client side channel scoped by this session.
The channel name may be for a specific channel (e.g. "/foo/bar") or for a wild channel (e.g. "/meta/**" or "/foo/*").
This method will always return a channel, even if the the channel has not been created on the server side. The server side channel is only involved once a publish or subscribe method is called on the channel returned by this method.
Typical usage examples are:
clientSession.getChannel("/foo/bar").subscribe(mySubscriptionListener); clientSession.getChannel("/foo/bar").publish("Hello"); clientSession.getChannel("/meta/*").addListener(myMetaChannelListener);
- Specified by:
getChannel
in interfaceClientSession
- Parameters:
channelName
- specific or wild channel name.- Returns:
- a channel scoped by this session.
-
getChannel
-
getChannels
-
startBatch
public void startBatch()Description copied from interface:Session
Starts a batch, to be ended with
Session.endBatch()
.The
Session.batch(Runnable)
method should be preferred since it automatically starts and ends a batch without relying on a try/finally block.This method is to be used in the cases where the use of
Session.batch(Runnable)
is not possible or would make the code more complex.- Specified by:
startBatch
in interfaceSession
- See Also:
Session.endBatch()
,Session.batch(Runnable)
-
sendBatch
protected abstract void sendBatch() -
endBatch
public boolean endBatch()Description copied from interface:Session
Ends a batch started with
Session.startBatch()
.- Specified by:
endBatch
in interfaceSession
- Returns:
- true if the batch ended and there were messages to send.
- See Also:
Session.startBatch()
-
batch
Description copied from interface:Session
Executes the given command in a batch so that any Bayeux message sent by the command (via the Bayeux API) is queued up until the end of the command and then all messages are sent at once.
-
isBatching
protected boolean isBatching() -
getAttribute
Description copied from interface:Session
Retrieves the value of named session attribute.
- Specified by:
getAttribute
in interfaceSession
- Parameters:
name
- the name of the attribute- Returns:
- the attribute value or null if the attribute is not present
-
getAttributeNames
- Specified by:
getAttributeNames
in interfaceSession
- Returns:
- the list of session attribute names.
-
removeAttribute
Description copied from interface:Session
Removes a named session attribute.
- Specified by:
removeAttribute
in interfaceSession
- Parameters:
name
- the name of the attribute- Returns:
- the value of the attribute
-
setAttribute
Description copied from interface:Session
Sets a named session attribute value.
Session attributes are convenience data that allows arbitrary application data to be associated with a session.
- Specified by:
setAttribute
in interfaceSession
- Parameters:
name
- the attribute namevalue
- the attribute value
-
remoteCall
Description copied from interface:ClientSession
Performs a remote call to the server, to the specified
target
, and with the givendata
as payload.The remote call response will be delivered via the
callback
parameter.Typical usage:
clientSession.remoteCall("getOnlineStatus", userId, new MessageListener() { @Override public void onMessage(Message message) { if (message.isSuccessful()) { String status = (String)message.getData(); // Update UI with online status. } else { // Remote call failed. } } });
- Specified by:
remoteCall
in interfaceClientSession
- Parameters:
target
- the remote call targetdata
- the remote call parameterscallback
- the listener that receives the remote call response
-
send
-
newMessage
-
resetSubscriptions
protected void resetSubscriptions() -
receive
Receives a message (from the server) and process it.
Processing the message involves calling the receive
extensions
and the channellisteners
.- Parameters:
message
- the message received.
-
notifyListeners
-
notifyListener
protected void notifyListener(ClientSessionChannel.MessageListener listener, Message.Mutable message) -
registerCallback
-
unregisterCallback
-
registerSubscriber
protected void registerSubscriber(String messageId, ClientSessionChannel.MessageListener subscriber) -
unregisterSubscriber
-
dump
- Specified by:
dump
in interfaceorg.eclipse.jetty.util.component.Dumpable
-
dump
- Specified by:
dump
in interfaceorg.eclipse.jetty.util.component.Dumpable
- Throws:
IOException
-