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.
Modifier and Type | Class and Description |
---|---|
protected class |
AbstractClientSession.AbstractSessionChannel
A channel scoped to a
ClientSession . |
ClientSession.Extension, ClientSession.MessageListener
Modifier | Constructor and Description |
---|---|
protected |
AbstractClientSession() |
Modifier and Type | Method and 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.
|
void |
dump(Appendable out,
String indent) |
boolean |
endBatch()
Ends a batch started with
Session.startBatch() . |
protected void |
extendIncoming(Message.Mutable message,
Promise<Boolean> promise) |
protected void |
extendOutgoing(Message.Mutable message,
Promise<Boolean> promise) |
Object |
getAttribute(String name)
Retrieves the value of named session attribute.
|
Set<String> |
getAttributeNames() |
ClientSessionChannel |
getChannel(ChannelId channelId) |
ClientSessionChannel |
getChannel(String channelName)
Returns a client side channel scoped by this session.
|
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 |
notifyCallback(ClientSession.MessageListener callback,
Message.Mutable message) |
protected void |
notifyListeners(Message.Mutable message) |
void |
receive(Message.Mutable message,
Promise<Void> promise)
Receives a message (from the server) and process it.
|
protected void |
registerCallback(String messageId,
ClientSession.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 specified
target ,
and with the given data 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 with
Session.endBatch() . |
protected ClientSession.MessageListener |
unregisterCallback(String messageId) |
protected ClientSessionChannel.MessageListener |
unregisterSubscriber(String messageId) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
disconnect, disconnect, handshake, handshake, handshake
getId, isConnected, isHandshook
protected String newMessageId()
public void addExtension(ClientSession.Extension extension)
ClientSession
addExtension
in interface ClientSession
extension
- the extension to addClientSession.removeExtension(Extension)
public void removeExtension(ClientSession.Extension extension)
ClientSession
removeExtension
in interface ClientSession
extension
- the extension to removeClientSession.addExtension(Extension)
public List<ClientSession.Extension> getExtensions()
getExtensions
in interface ClientSession
ClientSession.addExtension(Extension)
protected void extendOutgoing(Message.Mutable message, Promise<Boolean> promise)
protected void extendIncoming(Message.Mutable message, Promise<Boolean> promise)
protected abstract AbstractClientSession.AbstractSessionChannel newChannel(ChannelId channelId)
public ClientSessionChannel getChannel(String channelName)
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);
getChannel
in interface ClientSession
channelName
- specific or wild channel name.public ClientSessionChannel getChannel(ChannelId channelId)
protected ConcurrentMap<String,AbstractClientSession.AbstractSessionChannel> getChannels()
public void startBatch()
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.
startBatch
in interface Session
Session.endBatch()
,
Session.batch(Runnable)
protected abstract void sendBatch()
public boolean endBatch()
Session
Ends a batch started with Session.startBatch()
.
endBatch
in interface Session
Session.startBatch()
public void batch(Runnable batch)
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.
protected boolean isBatching()
public Object getAttribute(String name)
Session
Retrieves the value of named session attribute.
getAttribute
in interface Session
name
- the name of the attributepublic Set<String> getAttributeNames()
getAttributeNames
in interface Session
public Object removeAttribute(String name)
Session
Removes a named session attribute.
removeAttribute
in interface Session
name
- the name of the attributepublic void setAttribute(String name, Object value)
Session
Sets a named session attribute value.
Session attributes are convenience data that allows arbitrary application data to be associated with a session.
setAttribute
in interface Session
name
- the attribute namevalue
- the attribute valuepublic void remoteCall(String target, Object data, ClientSession.MessageListener callback)
ClientSession
Performs a remote call to the server, to the specified target
,
and with the given data
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. } } });
remoteCall
in interface ClientSession
target
- the remote call targetdata
- the remote call parameterscallback
- the listener that receives the remote call responseprotected abstract void send(Message.Mutable message)
protected Message.Mutable newMessage()
protected void resetSubscriptions()
public void receive(Message.Mutable message, Promise<Void> promise)
Receives a message (from the server) and process it.
Processing the message involves calling the receive extensions
and the channel listeners
.
message
- the message received.promise
- the promise notified of the receive processingprotected void notifyListeners(Message.Mutable message)
protected void notifyCallback(ClientSession.MessageListener callback, Message.Mutable message)
protected void registerCallback(String messageId, ClientSession.MessageListener callback)
protected ClientSession.MessageListener unregisterCallback(String messageId)
protected void registerSubscriber(String messageId, ClientSessionChannel.MessageListener subscriber)
protected ClientSessionChannel.MessageListener unregisterSubscriber(String messageId)
public void dump(Appendable out, String indent) throws IOException
dump
in interface org.eclipse.jetty.util.component.Dumpable
IOException
Copyright © 2008–2024 The CometD Project. All rights reserved.