Class ServerSessionImpl
- java.lang.Object
-
- org.cometd.server.ServerSessionImpl
-
- All Implemented Interfaces:
ServerSession,Session,org.eclipse.jetty.util.component.Dumpable
public class ServerSessionImpl extends java.lang.Object implements ServerSession, org.eclipse.jetty.util.component.Dumpable
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Dumpable
org.eclipse.jetty.util.component.Dumpable.DumpableContainer
-
Nested classes/interfaces inherited from interface org.cometd.bayeux.server.ServerSession
ServerSession.AddedListener, ServerSession.DeQueueListener, ServerSession.Extension, ServerSession.HeartBeatListener, ServerSession.MessageListener, ServerSession.QueueListener, ServerSession.QueueMaxedListener, ServerSession.RemovedListener, ServerSession.ServerSessionListener
-
-
Constructor Summary
Constructors Constructor Description ServerSessionImpl(BayeuxServerImpl bayeux)ServerSessionImpl(BayeuxServerImpl bayeux, LocalSessionImpl localSession, java.lang.String idHint)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddExtension(ServerSession.Extension extension)Adds the given extension to this session.voidaddListener(ServerSession.ServerSessionListener listener)Adds the given listener to this session.protected voidaddMessage(ServerMessage message)voidbatch(java.lang.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.longcalculateInterval(long defaultInterval)longcalculateTimeout(long defaultTimeout)voidcancelExpiration(boolean metaConnect)protected booleanconnected()voiddeliver(Session sender, java.lang.String channelId, java.lang.Object data, Promise<java.lang.Boolean> promise)Delivers the given information to this session.voiddeliver(Session sender, ServerMessage.Mutable message, Promise<java.lang.Boolean> promise)Delivers the given message to this session.protected voiddeliver1(ServerSession sender, ServerMessage.Mutable mutable, Promise<java.lang.Boolean> promise)voiddestroyScheduler()voiddisconnect()Disconnects this session, ending the link between the client and the server peers.voiddump(java.lang.Appendable out, java.lang.String indent)booleanendBatch()Ends a batch started withSession.startBatch().protected voidextendIncoming(ServerMessage.Mutable message, Promise<java.lang.Boolean> promise)protected voidextendOutgoing(ServerSession sender, ServerMessage.Mutable message, Promise<ServerMessage.Mutable> promise)voidflush()java.lang.ObjectgetAttribute(java.lang.String name)Retrieves the value of named session attribute.java.util.Set<java.lang.String>getAttributeNames()BayeuxServerImplgetBayeuxServer()java.lang.StringgetBrowserId()java.util.List<ServerSession.Extension>getExtensions()java.lang.StringgetId()The clientId of the session.longgetInterval()java.util.List<ServerSession.ServerSessionListener>getListeners()LocalSessiongetLocalSession()java.util.concurrent.locks.LockgetLock()longgetMaxInterval()java.util.Queue<ServerMessage>getQueue()ServerTransportgetServerTransport()java.util.Set<ServerChannel>getSubscriptions()longgetTimeout()java.lang.StringgetUserAgent()protected booleanhandshake(ServerMessage.Mutable message)booleanhasNonLazyMessages()booleanisAllowMessageDeliveryDuringHandshake()booleanisBroadcastToPublisher()booleanisConnected()A connected session is a session where the link between the client and the server has been established.booleanisDisconnected()booleanisHandshook()A handshook session is a session where the handshake has successfully completedbooleanisLocalSession()booleanisMetaConnectDeliveryOnly()booleanisTerminated()voidnotifyResumed(ServerMessage message, boolean timeout)voidnotifySuspended(ServerMessage message, long timeout)voidreAdvise()java.lang.ObjectremoveAttribute(java.lang.String name)Removes a named session attribute.protected booleanremoved(ServerMessage message, boolean timeout)voidremoveExtension(ServerSession.Extension extension)Removes the given extension from this session.voidremoveListener(ServerSession.ServerSessionListener listener)Removes the given listener from this session.voidscheduleExpiration(long defaultInterval, long defaultMaxInterval, long metaConnectCycle)voidsetAllowMessageDeliveryDuringHandshake(boolean allow)voidsetAttribute(java.lang.String name, java.lang.Object value)Sets a named session attribute value.voidsetBroadcastToPublisher(boolean value)Sets whether this session sends messages back to itself.voidsetBrowserId(java.lang.String browserId)Sets a remote client identifier, typically a browser.voidsetInterval(long intervalMS)voidsetMaxInterval(long maxInterval)voidsetMetaConnectDeliveryOnly(boolean meta)Sets whether delivery of messages only happen via the/meta/connectchannel.voidsetScheduler(AbstractServerTransport.Scheduler newScheduler)voidsetServerTransport(ServerTransport transport)voidsetTimeout(long timeoutMS)voidsetUserAgent(java.lang.String userAgent)booleanshouldSchedule()voidstartBatch()Starts a batch, to be ended withSession.endBatch().protected booleansubscribe(ServerChannelImpl channel)protected booleansweep(long now)java.util.Map<java.lang.String,java.lang.Object>takeAdvice(ServerTransport transport)java.util.List<ServerMessage>takeQueue(java.util.List<ServerMessage.Mutable> replies)java.lang.StringtoString()protected voidunsubscribedFrom(ServerChannelImpl channel)booleanupdateServerEndPoint(java.lang.Object newEndPoint)voidupdateTransientInterval(long interval)Updates the transient interval with the given value.voidupdateTransientTimeout(long timeout)Updates the transient timeout with the given value.
-
-
-
Constructor Detail
-
ServerSessionImpl
public ServerSessionImpl(BayeuxServerImpl bayeux)
-
ServerSessionImpl
public ServerSessionImpl(BayeuxServerImpl bayeux, LocalSessionImpl localSession, java.lang.String idHint)
-
-
Method Detail
-
getBayeuxServer
public BayeuxServerImpl getBayeuxServer()
-
getUserAgent
public java.lang.String getUserAgent()
- Specified by:
getUserAgentin interfaceServerSession- Returns:
- the remote user agent
-
setUserAgent
public void setUserAgent(java.lang.String userAgent)
- Parameters:
userAgent- the remote user agent
-
getBrowserId
public java.lang.String getBrowserId()
- Returns:
- the remote client identifier
-
setBrowserId
public void setBrowserId(java.lang.String browserId)
Sets a remote client identifier, typically a browser.
- Parameters:
browserId- the remote client identifier
-
sweep
protected boolean sweep(long now)
-
getSubscriptions
public java.util.Set<ServerChannel> getSubscriptions()
- Specified by:
getSubscriptionsin interfaceServerSession- Returns:
- the set of channels to which this session is subscribed to
-
addExtension
public void addExtension(ServerSession.Extension extension)
Description copied from interface:ServerSessionAdds the given extension to this session.
- Specified by:
addExtensionin interfaceServerSession- Parameters:
extension- the extension to add- See Also:
ServerSession.removeExtension(Extension)
-
removeExtension
public void removeExtension(ServerSession.Extension extension)
Description copied from interface:ServerSessionRemoves the given extension from this session.
- Specified by:
removeExtensionin interfaceServerSession- Parameters:
extension- the extension to remove- See Also:
ServerSession.addExtension(Extension)
-
getExtensions
public java.util.List<ServerSession.Extension> getExtensions()
- Specified by:
getExtensionsin interfaceServerSession- Returns:
- an immutable list of extensions present in this ServerSession instance
- See Also:
ServerSession.addExtension(Extension)
-
batch
public void batch(java.lang.Runnable batch)
Description copied from interface:SessionExecutes 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.
-
deliver
public void deliver(Session sender, ServerMessage.Mutable message, Promise<java.lang.Boolean> promise)
Description copied from interface:ServerSessionDelivers 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.
- Specified by:
deliverin interfaceServerSession- Parameters:
sender- the session delivering the messagemessage- the message to deliverpromise- the promise to notify with the result of the deliver- See Also:
ServerSession.deliver(Session, String, Object, Promise)
-
deliver
public void deliver(Session sender, java.lang.String channelId, java.lang.Object data, Promise<java.lang.Boolean> promise)
Description copied from interface:ServerSessionDelivers the given information to this session.
- Specified by:
deliverin interfaceServerSession- Parameters:
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 deliver- See Also:
ServerSession.deliver(Session, ServerMessage.Mutable, Promise)
-
deliver1
protected void deliver1(ServerSession sender, ServerMessage.Mutable mutable, Promise<java.lang.Boolean> promise)
-
extendOutgoing
protected void extendOutgoing(ServerSession sender, ServerMessage.Mutable message, Promise<ServerMessage.Mutable> promise)
-
handshake
protected boolean handshake(ServerMessage.Mutable message)
-
connected
protected boolean connected()
-
disconnect
public void disconnect()
Description copied from interface:SessionDisconnects this session, ending the link between the client and the server peers.- Specified by:
disconnectin interfaceSession- See Also:
Session.isConnected()
-
startBatch
public void startBatch()
Description copied from interface:SessionStarts 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.- Specified by:
startBatchin interfaceSession- See Also:
Session.endBatch(),Session.batch(Runnable)
-
endBatch
public boolean endBatch()
Description copied from interface:SessionEnds a batch started with
Session.startBatch().- Specified by:
endBatchin interfaceSession- Returns:
- true if the batch ended and there were messages to send.
- See Also:
Session.startBatch()
-
getLocalSession
public LocalSession getLocalSession()
- Specified by:
getLocalSessionin interfaceServerSession- Returns:
- the
LocalSessionassociated with this session, or null if this is a session representing a remote client.
-
isLocalSession
public boolean isLocalSession()
- Specified by:
isLocalSessionin interfaceServerSession- Returns:
- whether this is a session for a local client on server-side
-
addListener
public void addListener(ServerSession.ServerSessionListener listener)
Description copied from interface:ServerSessionAdds the given listener to this session.
- Specified by:
addListenerin interfaceServerSession- Parameters:
listener- the listener to add- See Also:
ServerSession.removeListener(ServerSessionListener)
-
getId
public java.lang.String getId()
Description copied from interface:SessionThe 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.
-
getLock
public java.util.concurrent.locks.Lock getLock()
-
getQueue
public java.util.Queue<ServerMessage> getQueue()
-
hasNonLazyMessages
public boolean hasNonLazyMessages()
-
addMessage
protected void addMessage(ServerMessage message)
-
takeQueue
public java.util.List<ServerMessage> takeQueue(java.util.List<ServerMessage.Mutable> replies)
-
notifySuspended
public void notifySuspended(ServerMessage message, long timeout)
-
notifyResumed
public void notifyResumed(ServerMessage message, boolean timeout)
-
removeListener
public void removeListener(ServerSession.ServerSessionListener listener)
Description copied from interface:ServerSessionRemoves the given listener from this session.
- Specified by:
removeListenerin interfaceServerSession- Parameters:
listener- the listener to remove- See Also:
ServerSession.addListener(ServerSessionListener)
-
getListeners
public java.util.List<ServerSession.ServerSessionListener> getListeners()
-
setScheduler
public void setScheduler(AbstractServerTransport.Scheduler newScheduler)
-
shouldSchedule
public boolean shouldSchedule()
-
flush
public void flush()
-
destroyScheduler
public void destroyScheduler()
-
cancelExpiration
public void cancelExpiration(boolean metaConnect)
-
scheduleExpiration
public void scheduleExpiration(long defaultInterval, long defaultMaxInterval, long metaConnectCycle)
-
getMaxInterval
public long getMaxInterval()
- Specified by:
getMaxIntervalin interfaceServerSession- Returns:
- the max period of time, in milliseconds, that the server waits before expiring the session when the client does not send messages to the server, or -1 if the default value is used
-
setMaxInterval
public void setMaxInterval(long maxInterval)
- Specified by:
setMaxIntervalin interfaceServerSession- Parameters:
maxInterval- the max period of time, in milliseconds, that the server waits before expiring the session
-
getAttribute
public java.lang.Object getAttribute(java.lang.String name)
Description copied from interface:SessionRetrieves the value of named session attribute.
- Specified by:
getAttributein interfaceSession- Parameters:
name- the name of the attribute- Returns:
- the attribute value or null if the attribute is not present
-
getAttributeNames
public java.util.Set<java.lang.String> getAttributeNames()
- Specified by:
getAttributeNamesin interfaceSession- Returns:
- the list of session attribute names.
-
removeAttribute
public java.lang.Object removeAttribute(java.lang.String name)
Description copied from interface:SessionRemoves a named session attribute.
- Specified by:
removeAttributein interfaceSession- Parameters:
name- the name of the attribute- Returns:
- the value of the attribute
-
setAttribute
public void setAttribute(java.lang.String name, java.lang.Object value)Description copied from interface:SessionSets a named session attribute value.
Session attributes are convenience data that allows arbitrary application data to be associated with a session.
- Specified by:
setAttributein interfaceSession- Parameters:
name- the attribute namevalue- the attribute value
-
isHandshook
public boolean isHandshook()
Description copied from interface:SessionA handshook session is a session where the handshake has successfully completed
- Specified by:
isHandshookin interfaceSession- Returns:
- whether the session is handshook
-
isConnected
public boolean isConnected()
Description copied from interface:SessionA connected session is a session where the link between the client and the server has been established.
- Specified by:
isConnectedin interfaceSession- Returns:
- whether the session is connected
- See Also:
Session.disconnect()
-
isDisconnected
public boolean isDisconnected()
-
isTerminated
public boolean isTerminated()
-
extendIncoming
protected void extendIncoming(ServerMessage.Mutable message, Promise<java.lang.Boolean> promise)
-
reAdvise
public void reAdvise()
-
takeAdvice
public java.util.Map<java.lang.String,java.lang.Object> takeAdvice(ServerTransport transport)
-
getServerTransport
public ServerTransport getServerTransport()
- Specified by:
getServerTransportin interfaceServerSession- Returns:
- the ServerTransport associated with this session
-
setServerTransport
public void setServerTransport(ServerTransport transport)
-
updateServerEndPoint
public boolean updateServerEndPoint(java.lang.Object newEndPoint)
-
getTimeout
public long getTimeout()
- Specified by:
getTimeoutin interfaceServerSession- Returns:
- the period of time, in milliseconds, that the server will hold connect messages for this session or -1 if the default value is used
- See Also:
ServerTransport.getTimeout()
-
getInterval
public long getInterval()
- Specified by:
getIntervalin interfaceServerSession- Returns:
- the period of time, in milliseconds, that the client associated with this session will wait before issuing a connect message, or -1 if the default value is used
- See Also:
ServerTransport.getInterval(),ServerSession.setInterval(long)
-
setTimeout
public void setTimeout(long timeoutMS)
- Specified by:
setTimeoutin interfaceServerSession- Parameters:
timeoutMS- the period of time, in milliseconds, that the server will hold connect messages for this session
-
setInterval
public void setInterval(long intervalMS)
- Specified by:
setIntervalin interfaceServerSession- Parameters:
intervalMS- the period of time, in milliseconds, that the client associated with this session will wait before issuing a connect message
-
isBroadcastToPublisher
public boolean isBroadcastToPublisher()
- Specified by:
isBroadcastToPublisherin interfaceServerSession- Returns:
- whether this session sends messages back to itself
-
setBroadcastToPublisher
public void setBroadcastToPublisher(boolean value)
Description copied from interface:ServerSessionSets whether this session sends messages back to itself.- Specified by:
setBroadcastToPublisherin interfaceServerSession- Parameters:
value- whether this session sends messages back to itself
-
removed
protected boolean removed(ServerMessage message, boolean timeout)
- Parameters:
message- the message that caused the removal, or nulltimeout- whether the session has been removed due a timeout- Returns:
- True if the session was connected.
-
setMetaConnectDeliveryOnly
public void setMetaConnectDeliveryOnly(boolean meta)
Description copied from interface:ServerSessionSets whether delivery of messages only happen via the
/meta/connectchannel.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/connectchannel guarantees server-to-client message ordering.- Specified by:
setMetaConnectDeliveryOnlyin interfaceServerSession- Parameters:
meta- whether delivery of messages only happens via the/meta/connectchannel
-
isMetaConnectDeliveryOnly
public boolean isMetaConnectDeliveryOnly()
- Specified by:
isMetaConnectDeliveryOnlyin interfaceServerSession- Returns:
- whether delivery of messages only happens via the
/meta/connectchannel
-
isAllowMessageDeliveryDuringHandshake
public boolean isAllowMessageDeliveryDuringHandshake()
-
setAllowMessageDeliveryDuringHandshake
public void setAllowMessageDeliveryDuringHandshake(boolean allow)
-
subscribe
protected boolean subscribe(ServerChannelImpl channel)
-
unsubscribedFrom
protected void unsubscribedFrom(ServerChannelImpl channel)
-
calculateTimeout
public long calculateTimeout(long defaultTimeout)
-
calculateInterval
public long calculateInterval(long defaultInterval)
-
updateTransientTimeout
public void updateTransientTimeout(long timeout)
Updates the transient timeout with the given value. The transient timeout is the one sent by the client, that should temporarily override the session/transport timeout, for example when the client sends {timeout:0}- Parameters:
timeout- the value to update the timeout to- See Also:
updateTransientInterval(long)
-
updateTransientInterval
public void updateTransientInterval(long interval)
Updates the transient interval with the given value. The transient interval is the one sent by the client, that should temporarily override the session/transport interval, for example when the client sends {timeout:0,interval:60000}- Parameters:
interval- the value to update the interval to- See Also:
updateTransientTimeout(long)
-
dump
public void dump(java.lang.Appendable out, java.lang.String indent) throws java.io.IOException- Specified by:
dumpin interfaceorg.eclipse.jetty.util.component.Dumpable- Throws:
java.io.IOException
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-