Interface ClientSession
-
- All Superinterfaces:
Session
- All Known Subinterfaces:
LocalSession
- All Known Implementing Classes:
AbstractClientSession
,BayeuxClient
,LocalSessionImpl
,OortComet
public interface ClientSession extends Session
This interface represents the client side Bayeux session.
In addition to the
common Bayeux session
, this interface provides method to configure extension, access channels and to initiate the communication with a Bayeux server(s).
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
ClientSession.Extension
Extension API for client session.static interface
ClientSession.MessageListener
A listener for remote call messages.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description void
addExtension(ClientSession.Extension extension)
Adds an extension to this session.default void
disconnect()
Disconnects this session, ending the link between the client and the server peers.void
disconnect(ClientSession.MessageListener callback)
Disconnects this session, ending the link between the client and the server peers.default void
disconnect(ClientSessionChannel.MessageListener callback)
Deprecated.usedisconnect(MessageListener)
insteadClientSessionChannel
getChannel(String channelName)
Returns a client side channel scoped by this session.List<ClientSession.Extension>
getExtensions()
default void
handshake()
Equivalent tohandshake(null)
.default void
handshake(Map<String,Object> template)
Equivalent tohandshake(template, null)
.void
handshake(Map<String,Object> template, ClientSession.MessageListener callback)
Initiates the bayeux protocol handshake with the server(s).default void
handshake(Map<String,Object> template, ClientSessionChannel.MessageListener callback)
Deprecated.usehandshake(Map, MessageListener)
insteadvoid
remoteCall(String target, Object data, ClientSession.MessageListener callback)
Performs a remote call to the server, to the specifiedtarget
, and with the givendata
as payload.void
removeExtension(ClientSession.Extension extension)
Removes an extension from this session.-
Methods inherited from interface org.cometd.bayeux.Session
batch, endBatch, getAttribute, getAttributeNames, getId, isConnected, isHandshook, removeAttribute, setAttribute, startBatch
-
-
-
-
Method Detail
-
addExtension
void addExtension(ClientSession.Extension extension)
Adds an extension to this session.- Parameters:
extension
- the extension to add- See Also:
removeExtension(Extension)
-
removeExtension
void removeExtension(ClientSession.Extension extension)
Removes an extension from this session.- Parameters:
extension
- the extension to remove- See Also:
addExtension(Extension)
-
getExtensions
List<ClientSession.Extension> getExtensions()
- Returns:
- an immutable list of extensions present in this ClientSession instance
- See Also:
addExtension(Extension)
-
handshake
default void handshake()
Equivalent to
handshake(null)
.
-
handshake
default void handshake(Map<String,Object> template)
Equivalent to
handshake(template, null)
.- Parameters:
template
- additional fields to add to the handshake message.
-
handshake
@Deprecated default void handshake(Map<String,Object> template, ClientSessionChannel.MessageListener callback)
Deprecated.usehandshake(Map, MessageListener)
instead- Parameters:
template
- additional fields to add to the handshake message.callback
- the message listener to notify of the handshake result
-
handshake
void handshake(Map<String,Object> template, ClientSession.MessageListener callback)
Initiates the bayeux protocol handshake with the server(s).
The handshake initiated by this method is asynchronous and does not wait for the handshake response.
- Parameters:
template
- additional fields to add to the handshake message.callback
- the message listener to notify of the handshake result
-
disconnect
default void disconnect()
Description copied from interface:Session
Disconnects this session, ending the link between the client and the server peers.- Specified by:
disconnect
in interfaceSession
- See Also:
Session.isConnected()
-
disconnect
@Deprecated default void disconnect(ClientSessionChannel.MessageListener callback)
Deprecated.usedisconnect(MessageListener)
instead- Parameters:
callback
- the message listener to notify of the disconnect result
-
disconnect
void disconnect(ClientSession.MessageListener callback)
Disconnects this session, ending the link between the client and the server peers.
- Parameters:
callback
- the message listener to notify of the disconnect result
-
getChannel
ClientSessionChannel getChannel(String channelName)
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);
- Parameters:
channelName
- specific or wild channel name.- Returns:
- a channel scoped by this session.
-
remoteCall
void remoteCall(String target, Object data, ClientSession.MessageListener callback)
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. } } });
- Parameters:
target
- the remote call targetdata
- the remote call parameterscallback
- the listener that receives the remote call response
-
-