public class ServerSessionImpl extends Object implements ServerSession, org.eclipse.jetty.util.component.Dumpable
ServerSession.AddedListener, ServerSession.AddListener, ServerSession.DeQueueListener, ServerSession.Extension, ServerSession.HeartBeatListener, ServerSession.MaxQueueListener, ServerSession.MessageListener, ServerSession.QueueListener, ServerSession.QueueMaxedListener, ServerSession.RemovedListener, ServerSession.RemoveListener, ServerSession.ServerSessionListener
Constructor and Description |
---|
ServerSessionImpl(BayeuxServerImpl bayeux) |
ServerSessionImpl(BayeuxServerImpl bayeux,
LocalSessionImpl localSession,
String idHint) |
Modifier and Type | Method and Description |
---|---|
void |
addExtension(ServerSession.Extension extension)
Adds the given extension to this session.
|
void |
addListener(ServerSession.ServerSessionListener listener)
Adds the given listener to this session.
|
protected void |
addMessage(ServerMessage message) |
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.
|
long |
calculateInterval(long defaultInterval) |
long |
calculateTimeout(long defaultTimeout) |
void |
cancelExpiration(boolean metaConnect) |
protected boolean |
connected() |
void |
deliver(Session sender,
ServerMessage.Mutable message,
Promise<Boolean> promise)
Delivers the given message to this session.
|
void |
deliver(Session sender,
String channelId,
Object data,
Promise<Boolean> promise)
Delivers the given information to this session.
|
protected void |
deliver1(ServerSession sender,
ServerMessage.Mutable mutable,
Promise<Boolean> promise) |
void |
destroyScheduler() |
void |
disconnect()
Disconnects this session, ending the link between the client and the server peers.
|
void |
dump(Appendable out,
String indent) |
boolean |
endBatch()
Ends a batch started with
Session.startBatch() . |
protected void |
extendIncoming(ServerMessage.Mutable message,
Promise<Boolean> promise) |
protected void |
extendOutgoing(ServerSession sender,
ServerMessage.Mutable message,
Promise<ServerMessage.Mutable> promise) |
void |
flush() |
Object |
getAttribute(String name)
Retrieves the value of named session attribute.
|
Set<String> |
getAttributeNames() |
BayeuxServerImpl |
getBayeuxServer() |
String |
getBrowserId() |
List<ServerSession.Extension> |
getExtensions() |
String |
getId()
The clientId of the session.
|
long |
getInterval() |
List<ServerSession.ServerSessionListener> |
getListeners() |
LocalSession |
getLocalSession() |
Object |
getLock() |
long |
getMaxInterval() |
Queue<ServerMessage> |
getQueue() |
ServerTransport |
getServerTransport() |
Set<ServerChannel> |
getSubscriptions() |
long |
getTimeout() |
String |
getUserAgent() |
protected boolean |
handshake(ServerMessage.Mutable message) |
boolean |
hasNonLazyMessages() |
boolean |
isAllowMessageDeliveryDuringHandshake() |
boolean |
isBroadcastToPublisher() |
boolean |
isConnected()
A connected session is a session where the link between the client and the server
has been established.
|
boolean |
isDisconnected() |
boolean |
isHandshook()
A handshook session is a session where the handshake has successfully completed
|
boolean |
isLocalSession() |
boolean |
isMetaConnectDeliveryOnly() |
boolean |
isTerminated() |
void |
notifyResumed(ServerMessage message,
boolean timeout) |
void |
notifySuspended(ServerMessage message,
long timeout) |
void |
reAdvise() |
Object |
removeAttribute(String name)
Removes a named session attribute.
|
protected boolean |
removed(ServerMessage message,
boolean timeout) |
void |
removeExtension(ServerSession.Extension extension)
Removes the given extension from this session.
|
void |
removeListener(ServerSession.ServerSessionListener listener)
Removes the given listener from this session.
|
void |
scheduleExpiration(long defaultInterval,
long defaultMaxInterval,
long metaConnectCycle) |
void |
setAllowMessageDeliveryDuringHandshake(boolean allow) |
void |
setAttribute(String name,
Object value)
Sets a named session attribute value.
|
void |
setBroadcastToPublisher(boolean value)
Sets whether this session sends messages back to itself.
|
void |
setBrowserId(String browserId)
Sets a remote client identifier, typically a browser.
|
void |
setInterval(long intervalMS) |
void |
setMaxInterval(long maxInterval) |
void |
setMetaConnectDeliveryOnly(boolean meta)
Sets whether delivery of messages only happen via the
/meta/connect channel. |
void |
setScheduler(AbstractServerTransport.Scheduler newScheduler) |
void |
setServerTransport(ServerTransport transport) |
void |
setTimeout(long timeoutMS) |
void |
setUserAgent(String userAgent) |
boolean |
shouldSchedule() |
void |
startBatch()
Starts a batch, to be ended with
Session.endBatch() . |
protected boolean |
subscribe(ServerChannelImpl channel) |
protected boolean |
sweep(long now) |
Map<String,Object> |
takeAdvice(ServerTransport transport) |
List<ServerMessage> |
takeQueue(List<ServerMessage.Mutable> replies) |
String |
toString() |
protected void |
unsubscribedFrom(ServerChannelImpl channel) |
boolean |
updateServerEndPoint(Object newEndPoint) |
void |
updateTransientInterval(long interval)
Updates the transient interval with the given value.
|
void |
updateTransientTimeout(long timeout)
Updates the transient timeout with the given value.
|
public ServerSessionImpl(BayeuxServerImpl bayeux)
public ServerSessionImpl(BayeuxServerImpl bayeux, LocalSessionImpl localSession, String idHint)
public BayeuxServerImpl getBayeuxServer()
public String getUserAgent()
getUserAgent
in interface ServerSession
public void setUserAgent(String userAgent)
userAgent
- the remote user agentpublic String getBrowserId()
public void setBrowserId(String browserId)
Sets a remote client identifier, typically a browser.
browserId
- the remote client identifierprotected boolean sweep(long now)
public Set<ServerChannel> getSubscriptions()
getSubscriptions
in interface ServerSession
public void addExtension(ServerSession.Extension extension)
ServerSession
Adds the given extension to this session.
addExtension
in interface ServerSession
extension
- the extension to addServerSession.removeExtension(Extension)
public void removeExtension(ServerSession.Extension extension)
ServerSession
Removes the given extension from this session.
removeExtension
in interface ServerSession
extension
- the extension to removeServerSession.addExtension(Extension)
public List<ServerSession.Extension> getExtensions()
getExtensions
in interface ServerSession
ServerSession.addExtension(Extension)
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.
public void deliver(Session sender, ServerMessage.Mutable message, Promise<Boolean> promise)
ServerSession
Delivers the given message to this session.
This is different from ServerChannel.publish(Session, ServerMessage.Mutable, Promise)
as the message is delivered only to this session and
not to all subscribers of the channel.
The message should still have a channel id specified, so that the ClientSession may identify the listeners the message should be delivered to.
deliver
in interface ServerSession
sender
- the session delivering the messagemessage
- the message to deliverpromise
- the promise to notify with the result of the deliverServerSession.deliver(Session, String, Object, Promise)
public void deliver(Session sender, String channelId, Object data, Promise<Boolean> promise)
ServerSession
Delivers the given information to this session.
deliver
in interface ServerSession
sender
- the session delivering the messagechannelId
- the channel of the messagedata
- the data of the messagepromise
- the promise to notify with the result of the deliverServerSession.deliver(Session, ServerMessage.Mutable, Promise)
protected void deliver1(ServerSession sender, ServerMessage.Mutable mutable, Promise<Boolean> promise)
protected void extendOutgoing(ServerSession sender, ServerMessage.Mutable message, Promise<ServerMessage.Mutable> promise)
protected boolean handshake(ServerMessage.Mutable message)
protected boolean connected()
public void disconnect()
Session
disconnect
in interface Session
Session.isConnected()
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)
public boolean endBatch()
Session
Ends a batch started with Session.startBatch()
.
endBatch
in interface Session
Session.startBatch()
public LocalSession getLocalSession()
getLocalSession
in interface ServerSession
LocalSession
associated with this session,
or null if this is a session representing a remote client.public boolean isLocalSession()
isLocalSession
in interface ServerSession
public void addListener(ServerSession.ServerSessionListener listener)
ServerSession
Adds the given listener to this session.
addListener
in interface ServerSession
listener
- the listener to addServerSession.removeListener(ServerSessionListener)
public String getId()
Session
The clientId of the session.
This would more correctly be called a "sessionId", but for backwards compatibility with the Bayeux protocol, it is a field called "clientId" that identifies a session.
public Object getLock()
public Queue<ServerMessage> getQueue()
public boolean hasNonLazyMessages()
protected void addMessage(ServerMessage message)
public List<ServerMessage> takeQueue(List<ServerMessage.Mutable> replies)
public void notifySuspended(ServerMessage message, long timeout)
public void notifyResumed(ServerMessage message, boolean timeout)
public void removeListener(ServerSession.ServerSessionListener listener)
ServerSession
Removes the given listener from this session.
removeListener
in interface ServerSession
listener
- the listener to removeServerSession.addListener(ServerSessionListener)
public List<ServerSession.ServerSessionListener> getListeners()
public void setScheduler(AbstractServerTransport.Scheduler newScheduler)
public boolean shouldSchedule()
public void flush()
public void destroyScheduler()
public void cancelExpiration(boolean metaConnect)
public void scheduleExpiration(long defaultInterval, long defaultMaxInterval, long metaConnectCycle)
public long getMaxInterval()
getMaxInterval
in interface ServerSession
public void setMaxInterval(long maxInterval)
setMaxInterval
in interface ServerSession
maxInterval
- the max period of time, in milliseconds, that the server waits
before expiring the sessionpublic 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 boolean isHandshook()
Session
A handshook session is a session where the handshake has successfully completed
isHandshook
in interface Session
public boolean isConnected()
Session
A connected session is a session where the link between the client and the server has been established.
isConnected
in interface Session
Session.disconnect()
public boolean isDisconnected()
public boolean isTerminated()
protected void extendIncoming(ServerMessage.Mutable message, Promise<Boolean> promise)
public void reAdvise()
public Map<String,Object> takeAdvice(ServerTransport transport)
public ServerTransport getServerTransport()
getServerTransport
in interface ServerSession
public void setServerTransport(ServerTransport transport)
public boolean updateServerEndPoint(Object newEndPoint)
public long getTimeout()
getTimeout
in interface ServerSession
ServerTransport.getTimeout()
public long getInterval()
getInterval
in interface ServerSession
ServerTransport.getInterval()
,
ServerSession.setInterval(long)
public void setTimeout(long timeoutMS)
setTimeout
in interface ServerSession
timeoutMS
- the period of time, in milliseconds, that the server will hold connect
messages for this sessionpublic void setInterval(long intervalMS)
setInterval
in interface ServerSession
intervalMS
- the period of time, in milliseconds, that the client
associated with this session will wait before issuing a connect messagepublic boolean isBroadcastToPublisher()
isBroadcastToPublisher
in interface ServerSession
public void setBroadcastToPublisher(boolean value)
ServerSession
setBroadcastToPublisher
in interface ServerSession
value
- whether this session sends messages back to itselfprotected boolean removed(ServerMessage message, boolean timeout)
message
- the message that caused the removal, or nulltimeout
- whether the session has been removed due a timeoutpublic void setMetaConnectDeliveryOnly(boolean meta)
ServerSession
Sets whether delivery of messages only happen via the /meta/connect
channel.
Transports that use more than one connection to the server (e.g. HTTP transports) may deliver some messages in one connection and some in another connection, causing messages to arrive out-of-order.
Forcing messages to be delivered only via the /meta/connect
channel guarantees
server-to-client message ordering.
setMetaConnectDeliveryOnly
in interface ServerSession
meta
- whether delivery of messages only happens via the
/meta/connect
channelpublic boolean isMetaConnectDeliveryOnly()
isMetaConnectDeliveryOnly
in interface ServerSession
/meta/connect
channelpublic boolean isAllowMessageDeliveryDuringHandshake()
public void setAllowMessageDeliveryDuringHandshake(boolean allow)
protected boolean subscribe(ServerChannelImpl channel)
protected void unsubscribedFrom(ServerChannelImpl channel)
public long calculateTimeout(long defaultTimeout)
public long calculateInterval(long defaultInterval)
public void updateTransientTimeout(long timeout)
timeout
- the value to update the timeout toupdateTransientInterval(long)
public void updateTransientInterval(long interval)
interval
- the value to update the interval toupdateTransientTimeout(long)
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.