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
ServerToClientMessages in order to resend them in case of failure.-
Method Summary
Modifier and TypeMethodDescriptionlonggetId()Return the id of the associated client.com.levigo.jadice.web.transport.server.session.internal.TransportSessionGet the transport connection over which communication with the client is currently established.voidServer-side transport implementations notify this method about the reception of some kind of signs of life from the client.voidonMessageReceived(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.ServerToClientMessageReturn 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.voidReceive notification that the client closed the session.voidsetTransportSession(com.levigo.jadice.web.transport.server.session.internal.TransportSession tc) Set the transport connection over which communication with the client is currently established.voidsynchronizeEventId(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. Returnnullif there are currently no queued messages.- Returns:
- The oldest queued Message or
nullif 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. Returnnullif there is currently no transport connection with the client.- Returns:
- a TransportConnection or
nullif 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()
-