Class Session
java.lang.Object
com.smartfoxserver.bitswarm.sessions.Session
- All Implemented Interfaces:
ISession
Overview
The Session object represents a connected client in the system. Normally a Session is not able to interact with the server until a Login operation is successfully executed. Once this is done the Session is promoted as User and the interaction is allowed.Sessions are a fundamental element in the Server. They hide the complexity of different types of socket and non-socket based connections, they handle basic traffic statistics, dropped messages, disconnections, transparent re-connections, TCP/UDP transmissions, socket tunneling and more. Each connected User in the system is backed by its own Session.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddReadBytes(long amount) voidaddTcpDroppedPackets(int amount) voidaddUdpDroppedPackets(int amount) voidaddWrittenBytes(long amount) voidclose()booleancontainsProperty(String name) booleancontainsSystemProperty(String name) voiddestroy()booleanvoidfreeze()Get the session IP addressintGet the client side TCP port numberlongThe Session's creation time as Unix Time in milliseconds.com.smartfoxserver.bitswarm.sessions.IPacketQueuelongGet the IPAddress and Port of the user as a String in the format "1.2.3.4:1234"Get the full server address and port to which the user connected to, in the form "1.2.3.4:1234"A unique string token that identifies the SessionintgetId()Get the unique session Idcom.smartfoxserver.bitswarm.sessions.ISeqProcessorlongThe last time that the client Session has sent a packet (milliseconds Unix Time)longThe last time that the Session has sent a Request (milliseconds Unix Time)longlongintGet the maximum time of socket inactivity after which the system will consider the Session "idle" and disconnect itintGet the maximum time of User inactivity after which the system will consider the session "idle" and disconnect itintGet the maximum idle time for User's UDP connection before it is considered disconnectedcom.smartfoxserver.bitswarm.sessions.IPacketQueuegetProperty(String key) Get a custom property from the SessionlongThe amount of data in bytes that the client has sent so farintGet the interval of time allowed for a Session to attempt a reconnection after and abrupt loss of connection.Get the server address to which the user connected tointGet the server port to which the user connected tocom.smartfoxserver.bitswarm.sessions.ISessionManagergetSystemProperty(String key) longgetType()Get the Session typecom.smartfoxserver.bitswarm.data.UDPConnectionlonglongThe amount of data that was sent to the client so farvoidbooleanvoidhandshakeComplete(boolean value) booleanCheck if the session is connected.booleanbooleanisFrozen()booleanisIdle()booleanCheck if the the Session is logged in.booleanbooleanbooleanbooleanvoidremoveProperty(String key) Remove an asoociated propertyvoidvoidsetConnected(boolean value) voidsetConnection(SocketChannel connection) voidsetCreationTime(long timestamp) voidsetCryptoKey(Object key) voidsetDatagramOutQueue(com.smartfoxserver.bitswarm.sessions.IPacketQueue queue) voidvoidsetId(int id) voidsetInSeqProcessor(com.smartfoxserver.bitswarm.sessions.ISeqProcessor processor) voidsetLastActivityTime(long timestamp) voidsetLastLoggedInActivityTime(long timestamp) voidsetLastReadTime(long timestamp) voidsetLastWriteTime(long timestamp) voidsetLoggedIn(boolean value) voidvoidsetMaxIdleTime(int idleTime) voidsetMaxLoggedInIdleTime(int idleTime) voidsetMaxUdpIdleTime(int seconds) voidsetPacketOutQueue(com.smartfoxserver.bitswarm.sessions.IPacketQueue queue) voidsetProperty(String key, Object property) Can be used to attach custom properties to a Session at runtime.voidsetReconnectionSeconds(int value) voidsetSessionManager(com.smartfoxserver.bitswarm.sessions.ISessionManager sessionManager) voidsetSystemProperty(String key, Object property) voidsetType(SessionType type) voidsetUdpConnection(com.smartfoxserver.bitswarm.data.UDPConnection conn) voidsetUdpKeepAlive(boolean value) toString()voidunfreeze()
-
Field Details
-
ENCRYPTION_ENABLED
- See Also:
-
DATA_BUFFER
- See Also:
-
PROTOCOL
- See Also:
-
NO_IP
- See Also:
-
BBCLIENT
- See Also:
-
WS_CHANNEL
- See Also:
-
WS_REMOTE_IP
- See Also:
-
BB_REMOTE_IP
- See Also:
-
PACKET_READ_STATE
- See Also:
-
-
Constructor Details
-
Session
public Session() -
Session
-
-
Method Details
-
destroy
public void destroy() -
addReadBytes
public void addReadBytes(long amount) - Specified by:
addReadBytesin interfaceISession- Internal
-
addWrittenBytes
public void addWrittenBytes(long amount) - Specified by:
addWrittenBytesin interfaceISession- Internal
-
getConnection
- Specified by:
getConnectionin interfaceISession- Internal
-
getCreationTime
public long getCreationTime()Description copied from interface:ISessionThe Session's creation time as Unix Time in milliseconds.- Specified by:
getCreationTimein interfaceISession- Returns:
- the creation time
- Internal
-
getHashId
Description copied from interface:ISessionA unique string token that identifies the Session -
getId
public int getId()Description copied from interface:ISessionGet the unique session Id -
getFullIpAddress
Description copied from interface:ISessionGet the IPAddress and Port of the user as a String in the format "1.2.3.4:1234"- Specified by:
getFullIpAddressin interfaceISession- Returns:
- the ip address and port of the client
-
getAddress
Description copied from interface:ISessionGet the session IP address- Specified by:
getAddressin interfaceISession- Returns:
- the session IP address
-
getClientPort
public int getClientPort()Description copied from interface:ISessionGet the client side TCP port number- Specified by:
getClientPortin interfaceISession- Returns:
- get the client side TCP port number
-
getServerPort
public int getServerPort()Description copied from interface:ISessionGet the server port to which the user connected to- Specified by:
getServerPortin interfaceISession- Returns:
- get the server port to which the user connected to
- Internal
-
getFullServerIpAddress
Description copied from interface:ISessionGet the full server address and port to which the user connected to, in the form "1.2.3.4:1234"- Specified by:
getFullServerIpAddressin interfaceISession- Returns:
- get the server address and port to which the user connected to
- Internal
-
getServerAddress
Description copied from interface:ISessionGet the server address to which the user connected to- Specified by:
getServerAddressin interfaceISession- Returns:
- get the server address to which the user connected to
- Internal
-
getLastActivityTime
public long getLastActivityTime()Description copied from interface:ISessionThe last time that the client Session has sent a packet (milliseconds Unix Time)- Specified by:
getLastActivityTimein interfaceISession- Returns:
- the last time that the Session has sent a packet (milliseconds Unix Time)
- Internal
-
getLastReadTime
public long getLastReadTime()- Specified by:
getLastReadTimein interfaceISession- Internal
-
getLastWriteTime
public long getLastWriteTime()- Specified by:
getLastWriteTimein interfaceISession- Internal
-
getMaxIdleTime
public int getMaxIdleTime()Description copied from interface:ISessionGet the maximum time of socket inactivity after which the system will consider the Session "idle" and disconnect itNOTE: This is valid until the client is not logged in, then the maxLoggedInIdleTime will be used
- Specified by:
getMaxIdleTimein interfaceISession- Returns:
- get the maximum time of inactivity after which the system will consider the Session "idle" and disconnect it
- Internal
-
getPacketOutQueue
public com.smartfoxserver.bitswarm.sessions.IPacketQueue getPacketOutQueue()- Specified by:
getPacketOutQueuein interfaceISession- Internal
-
getDatagramOutQueue
public com.smartfoxserver.bitswarm.sessions.IPacketQueue getDatagramOutQueue()- Specified by:
getDatagramOutQueuein interfaceISession- Internal
-
containsProperty
- Specified by:
containsPropertyin interfaceISession
-
getProperty
Description copied from interface:ISessionGet a custom property from the Session- Specified by:
getPropertyin interfaceISession- Parameters:
key- the property name- Returns:
- the associated value, null if no property exists
-
removeProperty
Description copied from interface:ISessionRemove an asoociated property- Specified by:
removePropertyin interfaceISession- Parameters:
key- name of the property
-
getReadBytes
public long getReadBytes()Description copied from interface:ISessionThe amount of data in bytes that the client has sent so far- Specified by:
getReadBytesin interfaceISession- Returns:
- the amount of data in bytes that the user has sent so far
- Internal
-
containsSystemProperty
- Specified by:
containsSystemPropertyin interfaceISession- Internal
-
getSystemProperty
- Specified by:
getSystemPropertyin interfaceISession- Internal
-
removeSystemProperty
- Specified by:
removeSystemPropertyin interfaceISession- Internal
-
getType
Description copied from interface:ISessionGet the Session type -
getWrittenBytes
public long getWrittenBytes()Description copied from interface:ISessionThe amount of data that was sent to the client so far- Specified by:
getWrittenBytesin interfaceISession- Returns:
- the amount of data that was sent to the client so far
- Internal
-
isConnected
public boolean isConnected()Description copied from interface:ISessionCheck if the session is connected.- Specified by:
isConnectedin interfaceISession- Returns:
- true if the session is connected.
- Internal
-
setConnected
public void setConnected(boolean value) - Specified by:
setConnectedin interfaceISession- Internal
-
handshakeComplete
public boolean handshakeComplete()- Specified by:
handshakeCompletein interfaceISession- Internal
-
handshakeComplete
public void handshakeComplete(boolean value) - Specified by:
handshakeCompletein interfaceISession- Internal
-
isLoggedIn
public boolean isLoggedIn()Description copied from interface:ISessionCheck if the the Session is logged in.- Specified by:
isLoggedInin interfaceISession- Returns:
- true if the session has performed the login process
- Internal
-
setLoggedIn
public void setLoggedIn(boolean value) - Specified by:
setLoggedInin interfaceISession- Internal
-
getMaxLoggedInIdleTime
public int getMaxLoggedInIdleTime()Description copied from interface:ISessionGet the maximum time of User inactivity after which the system will consider the session "idle" and disconnect itNOTE: This applies only if the client is logged in
- Specified by:
getMaxLoggedInIdleTimein interfaceISession- Returns:
- Get the maximum time of User inactivity after which the system will consider the session "idle" and disconnect it
- Internal
-
setMaxLoggedInIdleTime
public void setMaxLoggedInIdleTime(int idleTime) - Specified by:
setMaxLoggedInIdleTimein interfaceISession- Internal
-
getMaxUdpIdleTime
public int getMaxUdpIdleTime()Description copied from interface:ISessionGet the maximum idle time for User's UDP connection before it is considered disconnectedNOTE: This applies only if the client has an active UDP connection
- Specified by:
getMaxUdpIdleTimein interfaceISession- Returns:
- the max number of idle seconds
- Internal
-
setMaxUdpIdleTime
public void setMaxUdpIdleTime(int seconds) - Specified by:
setMaxUdpIdleTimein interfaceISession- Internal
-
isUdpKeepAlive
public boolean isUdpKeepAlive()- Specified by:
isUdpKeepAlivein interfaceISession- Internal
-
setUdpKeepAlive
public void setUdpKeepAlive(boolean value) - Specified by:
setUdpKeepAlivein interfaceISession- Internal
-
getLastLoggedInActivityTime
public long getLastLoggedInActivityTime()Description copied from interface:ISessionThe last time that the Session has sent a Request (milliseconds Unix Time)- Specified by:
getLastLoggedInActivityTimein interfaceISession- Returns:
- the last time that the Session has sent a request (milliseconds Unix Time)
- Internal
-
setLastLoggedInActivityTime
public void setLastLoggedInActivityTime(long timestamp) - Specified by:
setLastLoggedInActivityTimein interfaceISession- Internal
-
getUdpConnection
public com.smartfoxserver.bitswarm.data.UDPConnection getUdpConnection()- Specified by:
getUdpConnectionin interfaceISession- Internal
-
setUdpConnection
public void setUdpConnection(com.smartfoxserver.bitswarm.data.UDPConnection conn) - Specified by:
setUdpConnectionin interfaceISession- Internal
-
isIdle
public boolean isIdle() -
isMarkedForEviction
public boolean isMarkedForEviction()- Specified by:
isMarkedForEvictionin interfaceISession- Internal
-
isUdpConnected
public boolean isUdpConnected()- Specified by:
isUdpConnectedin interfaceISession- Internal
-
setConnection
- Specified by:
setConnectionin interfaceISession- Internal
-
setPacketOutQueue
public void setPacketOutQueue(com.smartfoxserver.bitswarm.sessions.IPacketQueue queue) - Specified by:
setPacketOutQueuein interfaceISession- Internal
-
setDatagramOutQueue
public void setDatagramOutQueue(com.smartfoxserver.bitswarm.sessions.IPacketQueue queue) - Specified by:
setDatagramOutQueuein interfaceISession- Internal
-
setCreationTime
public void setCreationTime(long timestamp) - Specified by:
setCreationTimein interfaceISession- Internal
-
setHashId
-
setId
public void setId(int id) -
setLastActivityTime
public void setLastActivityTime(long timestamp) - Specified by:
setLastActivityTimein interfaceISession- Internal
-
setLastReadTime
public void setLastReadTime(long timestamp) - Specified by:
setLastReadTimein interfaceISession- Internal
-
setLastWriteTime
public void setLastWriteTime(long timestamp) - Specified by:
setLastWriteTimein interfaceISession- Internal
-
setMarkedForEviction
public void setMarkedForEviction()- Specified by:
setMarkedForEvictionin interfaceISession- Internal
-
setMaxIdleTime
public void setMaxIdleTime(int idleTime) - Specified by:
setMaxIdleTimein interfaceISession- Internal
-
setProperty
Description copied from interface:ISessionCan be used to attach custom properties to a Session at runtime. A common use case is to associate a number of properties before the User is logged in, when the User object isn't available yet.- Specified by:
setPropertyin interfaceISession- Parameters:
key- name of the propertyproperty- any Object
-
setSystemProperty
- Specified by:
setSystemPropertyin interfaceISession- Internal
-
setType
-
getTcpDroppedPackets
public long getTcpDroppedPackets()- Specified by:
getTcpDroppedPacketsin interfaceISession- Internal
-
addTcpDroppedPackets
public void addTcpDroppedPackets(int amount) - Specified by:
addTcpDroppedPacketsin interfaceISession- Internal
-
getUdpDroppedPackets
public long getUdpDroppedPackets()- Specified by:
getUdpDroppedPacketsin interfaceISession- Internal
-
addUdpDroppedPackets
public void addUdpDroppedPackets(int amount) - Specified by:
addUdpDroppedPacketsin interfaceISession- Internal
-
getSessionManager
public com.smartfoxserver.bitswarm.sessions.ISessionManager getSessionManager()- Specified by:
getSessionManagerin interfaceISession- Internal
-
setSessionManager
public void setSessionManager(com.smartfoxserver.bitswarm.sessions.ISessionManager sessionManager) - Specified by:
setSessionManagerin interfaceISession- Internal
-
isFrozen
public boolean isFrozen() -
freeze
public void freeze() -
unfreeze
public void unfreeze() -
getFreezeTime
public long getFreezeTime()- Specified by:
getFreezeTimein interfaceISession- Internal
-
isReconnectionTimeExpired
public boolean isReconnectionTimeExpired()- Specified by:
isReconnectionTimeExpiredin interfaceISession- Internal
-
close
- Specified by:
closein interfaceISession- Throws:
IOException- Internal
-
getReconnectionSeconds
public int getReconnectionSeconds()Description copied from interface:ISessionGet the interval of time allowed for a Session to attempt a reconnection after and abrupt loss of connection. Once the time has expired and reconnection was done the User will finally be disconnected from the system.- Specified by:
getReconnectionSecondsin interfaceISession- Returns:
- the amount of seconds allowed for a reconnection.
- Internal
-
setReconnectionSeconds
public void setReconnectionSeconds(int value) - Specified by:
setReconnectionSecondsin interfaceISession- Internal
-
isEncrypted
public boolean isEncrypted()- Specified by:
isEncryptedin interfaceISession- Internal
-
getCryptoKey
- Specified by:
getCryptoKeyin interfaceISession- Internal
-
setCryptoKey
- Specified by:
setCryptoKeyin interfaceISession- Internal
-
toString
-
equals
-
handleRDPDisconnection
public void handleRDPDisconnection()- Specified by:
handleRDPDisconnectionin interfaceISession- Internal
-
getInSeqProcessor
public com.smartfoxserver.bitswarm.sessions.ISeqProcessor getInSeqProcessor()- Specified by:
getInSeqProcessorin interfaceISession
-
setInSeqProcessor
public void setInSeqProcessor(com.smartfoxserver.bitswarm.sessions.ISeqProcessor processor) - Specified by:
setInSeqProcessorin interfaceISession
-