Class ServerSessionImpl
- All Implemented Interfaces:
ServerSession
,Session
,org.eclipse.jetty.util.component.Dumpable
public class ServerSessionImpl extends Object implements ServerSession, org.eclipse.jetty.util.component.Dumpable
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.cometd.bayeux.server.ServerSession
ServerSession.DeQueueListener, ServerSession.Extension, ServerSession.MaxQueueListener, ServerSession.MessageListener, ServerSession.QueueListener, ServerSession.RemoveListener, ServerSession.ServerSessionListener
-
Constructor Summary
Constructors Constructor Description ServerSessionImpl(BayeuxServerImpl bayeux)
ServerSessionImpl(BayeuxServerImpl bayeux, LocalSessionImpl localSession, String idHint)
-
Method Summary
Modifier and Type Method 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)
void
cancelSchedule()
protected void
connected()
void
deliver(Session sender, String channelId, Object data)
Delivers the given information to this session.void
deliver(Session sender, ServerMessage.Mutable message)
Delivers the given message to this session.void
disconnect()
Disconnects this session, ending the link between the client and the server peers.protected void
doDeliver(ServerSession sender, ServerMessage.Mutable mutable)
String
dump()
void
dump(Appendable out, String indent)
boolean
endBatch()
Ends a batch started withSession.startBatch()
.protected boolean
extendRecv(ServerMessage.Mutable message)
protected ServerMessage.Mutable
extendSend(ServerMessage.Mutable mutable)
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()
protected long
getMaxInterval()
Queue<ServerMessage>
getQueue()
Set<ServerChannel>
getSubscriptions()
long
getTimeout()
String
getUserAgent()
protected void
handshake()
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 completedboolean
isLocalSession()
boolean
isMetaConnectDeliveryOnly()
void
reAdvise()
Object
removeAttribute(String name)
Removes a named session attribute.protected boolean
removed(boolean timedOut)
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)
void
setAllowMessageDeliveryDuringHandshake(boolean allow)
void
setAttribute(String name, Object value)
Sets a named session attribute value.void
setBroadcastToPublisher(boolean value)
void
setBrowserId(String browserId)
Sets a remote client identifier, typically a browser.void
setInterval(long intervalMS)
void
setMetaConnectDeliveryOnly(boolean meta)
void
setScheduler(AbstractServerTransport.Scheduler newScheduler)
void
setTimeout(long timeoutMS)
void
setUserAgent(String userAgent)
boolean
shouldSchedule()
void
startBatch()
Starts a batch, to be ended withSession.endBatch()
.protected void
subscribedTo(ServerChannelImpl channel)
protected void
sweep(long now)
Map<String,Object>
takeAdvice(ServerTransport transport)
List<ServerMessage>
takeQueue()
String
toString()
protected void
unsubscribedFrom(ServerChannelImpl channel)
void
updateTransientInterval(long interval)
Updates the transient interval with the given value.void
updateTransientTimeout(long timeout)
Updates the transient timeout with the given value.
-
Constructor Details
-
Method Details
-
getBayeuxServer
-
getUserAgent
- Specified by:
getUserAgent
in interfaceServerSession
- Returns:
- the remote user agent
-
setUserAgent
- Parameters:
userAgent
- the remote user agent
-
getBrowserId
- Returns:
- the remote client identifier
-
setBrowserId
Sets a remote client identifier, typically a browser.
- Parameters:
browserId
- the remote client identifier
-
sweep
protected void sweep(long now) -
getSubscriptions
- Specified by:
getSubscriptions
in interfaceServerSession
- Returns:
- the set of channels to which this session is subscribed to
-
addExtension
Description copied from interface:ServerSession
Adds the given extension to this session.
- Specified by:
addExtension
in interfaceServerSession
- Parameters:
extension
- the extension to add- See Also:
ServerSession.removeExtension(Extension)
-
removeExtension
Description copied from interface:ServerSession
Removes the given extension from this session.
- Specified by:
removeExtension
in interfaceServerSession
- Parameters:
extension
- the extension to remove- See Also:
ServerSession.addExtension(Extension)
-
getExtensions
- Specified by:
getExtensions
in interfaceServerSession
- Returns:
- an immutable list of extensions present in this ServerSession instance
- See Also:
ServerSession.addExtension(Extension)
-
batch
Description copied from interface: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.
-
deliver
Description copied from interface:ServerSession
Delivers the given message to this session.
This is different from
ServerChannel.publish(Session, ServerMessage.Mutable)
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:
deliver
in interfaceServerSession
- Parameters:
sender
- the session delivering the messagemessage
- the message to deliver- See Also:
ServerSession.deliver(Session, String, Object)
-
deliver
Description copied from interface:ServerSession
Delivers the given information to this session.
- Specified by:
deliver
in interfaceServerSession
- Parameters:
sender
- the session delivering the messagechannelId
- the channel of the messagedata
- the data of the message- See Also:
ServerSession.deliver(Session, ServerMessage.Mutable)
-
doDeliver
-
extendSend
-
handshake
protected void handshake() -
connected
protected void connected() -
disconnect
public 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()
-
startBatch
public void startBatch()Description copied from interface: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.- Specified by:
startBatch
in interfaceSession
- See Also:
Session.endBatch()
,Session.batch(Runnable)
-
endBatch
public boolean endBatch()Description copied from interface:Session
Ends a batch started with
Session.startBatch()
.- Specified by:
endBatch
in interfaceSession
- Returns:
- true if the batch ended and there were messages to send.
- See Also:
Session.startBatch()
-
getLocalSession
- Specified by:
getLocalSession
in interfaceServerSession
- Returns:
- the
LocalSession
associated with this session, or null if this is a session representing a remote client.
-
isLocalSession
public boolean isLocalSession()- Specified by:
isLocalSession
in interfaceServerSession
- Returns:
- whether this is a session for a local client on server-side
-
addListener
Description copied from interface:ServerSession
Adds the given listener to this session.
- Specified by:
addListener
in interfaceServerSession
- Parameters:
listener
- the listener to add- See Also:
ServerSession.removeListener(ServerSessionListener)
-
getId
Description copied from interface: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.
-
getLock
-
getQueue
-
hasNonLazyMessages
public boolean hasNonLazyMessages() -
addMessage
-
takeQueue
-
removeListener
Description copied from interface:ServerSession
Removes the given listener from this session.
- Specified by:
removeListener
in interfaceServerSession
- Parameters:
listener
- the listener to remove- See Also:
ServerSession.addListener(ServerSessionListener)
-
getListeners
-
setScheduler
-
shouldSchedule
public boolean shouldSchedule() -
flush
public void flush() -
cancelSchedule
public void cancelSchedule() -
cancelExpiration
public void cancelExpiration(boolean metaConnect) -
scheduleExpiration
public void scheduleExpiration(long defaultInterval) -
getMaxInterval
protected long getMaxInterval() -
getAttribute
Description copied from interface:Session
Retrieves the value of named session attribute.
- Specified by:
getAttribute
in interfaceSession
- Parameters:
name
- the name of the attribute- Returns:
- the attribute value or null if the attribute is not present
-
getAttributeNames
- Specified by:
getAttributeNames
in interfaceSession
- Returns:
- the list of session attribute names.
-
removeAttribute
Description copied from interface:Session
Removes a named session attribute.
- Specified by:
removeAttribute
in interfaceSession
- Parameters:
name
- the name of the attribute- Returns:
- the value of the attribute
-
setAttribute
Description copied from interface:Session
Sets a named session attribute value.
Session attributes are convenience data that allows arbitrary application data to be associated with a session.
- Specified by:
setAttribute
in interfaceSession
- Parameters:
name
- the attribute namevalue
- the attribute value
-
isHandshook
public boolean isHandshook()Description copied from interface:Session
A handshook session is a session where the handshake has successfully completed
- Specified by:
isHandshook
in interfaceSession
- Returns:
- whether the session is handshook
-
isConnected
public boolean isConnected()Description copied from interface:Session
A connected session is a session where the link between the client and the server has been established.
- Specified by:
isConnected
in interfaceSession
- Returns:
- whether the session is connected
- See Also:
Session.disconnect()
-
isDisconnected
public boolean isDisconnected() -
extendRecv
-
reAdvise
public void reAdvise() -
takeAdvice
-
getTimeout
public long getTimeout()- Specified by:
getTimeout
in 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:
getInterval
in 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:
setTimeout
in 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:
setInterval
in 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() -
setBroadcastToPublisher
public void setBroadcastToPublisher(boolean value) -
removed
protected boolean removed(boolean timedOut)- Parameters:
timedOut
- whether the session has been timed out- Returns:
- True if the session was connected.
-
setMetaConnectDeliveryOnly
public void setMetaConnectDeliveryOnly(boolean meta) -
isMetaConnectDeliveryOnly
public boolean isMetaConnectDeliveryOnly() -
isAllowMessageDeliveryDuringHandshake
public boolean isAllowMessageDeliveryDuringHandshake() -
setAllowMessageDeliveryDuringHandshake
public void setAllowMessageDeliveryDuringHandshake(boolean allow) -
subscribedTo
-
unsubscribedFrom
-
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
- Specified by:
dump
in interfaceorg.eclipse.jetty.util.component.Dumpable
-
dump
- Specified by:
dump
in interfaceorg.eclipse.jetty.util.component.Dumpable
- Throws:
IOException
-
toString
-