Interface ClientSession
public interface ClientSession
A ClientSession represents a session from a particular client which is identified by a unique
session ID. The actual connection to the client is via some transport implementation like
long-poll, server-sent-events or WebSocket. A ClientSession is able to buffer
ServerToClientMessage
s in order to resend them in case of failure.-
Method Summary
Modifier and TypeMethodDescriptionlong
getId()
Return the id of the associated client.com.levigo.jadice.web.transport.server.session.internal.TransportSession
Get the transport connection over which communication with the client is currently established.void
Server-side transport implementations notify this method about the reception of some kind of signs of life from the client.void
onMessageReceived
(String message, MessageContext messageContext) Server-side transport implementations notify this method about the arrival of messages from a client.com.levigo.jadice.web.transport.server.session.internal.ServerToClientMessage
Return the oldest queued message for the client.List
<com.levigo.jadice.web.transport.server.session.internal.ServerToClientMessage> queryMessageHistory
(long largerThan) Return all historical messages with an ID larger than the given id.void
Receive notification that the client closed the session.void
setTransportSession
(com.levigo.jadice.web.transport.server.session.internal.TransportSession tc) Set the transport connection over which communication with the client is currently established.void
synchronizeEventId
(long eventId) Synchronize the event id generation with the current value from a client.
-
Method Details
-
onMessageReceived
Server-side transport implementations notify this method about the arrival of messages from a client.- Parameters:
message
- The message received.messageContext
- The context of the received message.
-
heartbeatReceived
void heartbeatReceived()Server-side transport implementations notify this method about the reception of some kind of signs of life from the client. -
queryMessageHistory
List<com.levigo.jadice.web.transport.server.session.internal.ServerToClientMessage> queryMessageHistory(long largerThan) Return all historical messages with an ID larger than the given id. Return an empty list if there are currently no queued messages.- Parameters:
largerThan
- The starting id (exclusive) of the messages in the list.- Returns:
- A filtered list of historical messages.
-
pollMessage
com.levigo.jadice.web.transport.server.session.internal.ServerToClientMessage pollMessage()Return the oldest queued message for the client. Returnnull
if there are currently no queued messages.- Returns:
- The oldest queued Message or
null
if none is present.
-
setTransportSession
void setTransportSession(com.levigo.jadice.web.transport.server.session.internal.TransportSession tc) Set the transport connection over which communication with the client is currently established. The TransportConnection used to communicate with a client may change over time.- Parameters:
tc
- the TransportConnection
-
getTransportSession
com.levigo.jadice.web.transport.server.session.internal.TransportSession getTransportSession()Get the transport connection over which communication with the client is currently established. Returnnull
if there is currently no transport connection with the client.- Returns:
- a TransportConnection or
null
if there is currently no transport connection for this session.
-
getId
String getId()Return the id of the associated client.- Returns:
- The clients' id.
-
sessionClosed
void sessionClosed()Receive notification that the client closed the session. -
synchronizeEventId
void synchronizeEventId(long eventId) Synchronize the event id generation with the current value from a client. In general, when a session determines that its own sequence number lags behind the one the client has, it knows that the server side lost state in some form, e.g. through a restart or fail over.It may react by fast-forwarding to the client's number + 1 or by signaling an error condition to the server.
Other tasks during event id synchronization may include pruning the event history.
- Parameters:
eventId
- the client's last known event id
-
currentEventId
long currentEventId()
-