Class Session
- java.lang.Object
-
- com.smartfoxserver.bitswarm.sessions.Session
-
- All Implemented Interfaces:
ISession
public final class Session extends java.lang.Object implements 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 tunnelling and lots more. Each connected User in the system is backed by its own Session.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringBB_REMOTE_IPstatic java.lang.StringBBCLIENTstatic java.lang.StringDATA_BUFFERstatic java.lang.StringENCRYPTION_ENABLEDstatic java.lang.StringNO_IPstatic java.lang.StringPACKET_READ_STATEstatic java.lang.StringPROTOCOLstatic java.lang.StringWS_CHANNELstatic java.lang.StringWS_REMOTE_IP
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddDroppedMessages(int amount)voidaddReadBytes(long amount)voidaddWrittenBytes(long amount)voidclose()booleanequals(java.lang.Object obj)voidfreeze()java.lang.StringgetAddress()Get the session IP addressintgetClientPort()Get the client side TCP port numberjava.nio.channels.SocketChannelgetConnection()longgetCreationTime()The timestamp at which the connection was done (milliseconds Unix Time)java.lang.ObjectgetCryptoKey()java.nio.channels.DatagramChannelgetDatagramChannel()intgetDroppedMessages()The number of messages that were dropped since the connectionlonggetFreezeTime()java.lang.StringgetFullIpAddress()Get the IPAddress and Port of the user as a String in the format "1.2.3.4:1234"java.lang.StringgetFullServerIpAddress()Get the full server address and port to which the user connected to, in the form "1.2.3.4:1234"java.lang.StringgetHashId()A unique string token used as an alternative session IDintgetId()Get the unique session IdlonggetLastActivityTime()The last time that the session has sent a packet (milliseconds Unix Time)longgetLastLoggedInActivityTime()The last time that the session has sent a request (milliseconds Unix Time)longgetLastReadTime()longgetLastWriteTime()intgetMaxIdleTime()Get the maximum time of socket inactivity after which the system will consider the User "idle" and disconnect it.intgetMaxLoggedInIdleTime()Get the maximum time of User inactivity after which the system will consider the session "idle" and disconnect it.java.lang.StringgetNodeId()Return the node Id in a clustercom.smartfoxserver.bitswarm.sessions.IPacketQueuegetPacketQueue()java.lang.ObjectgetProperty(java.lang.String key)longgetReadBytes()The amount of data in bytes that the client has sent so farintgetReconnectionSeconds()Get the interval of time allowed for a Session to attempt a reconnection after and abrupt loss of connection.java.lang.StringgetServerAddress()Get the server address to which the user connected tointgetServerPort()Get the server port to which the user connected tocom.smartfoxserver.bitswarm.sessions.ISessionManagergetSessionManager()java.lang.ObjectgetSystemProperty(java.lang.String key)SessionTypegetType()Get the Session typelonggetWrittenBytes()The amount of data that was sent to the client so farbooleanisConnected()Check if the session is connected.booleanisEncrypted()booleanisFrozen()booleanisIdle()booleanisLocal()See if the Session is local or hosted in another cluster node.booleanisLoggedIn()Check if the the Session is logged in.booleanisMarkedForEviction()booleanisReconnectionTimeExpired()booleanisUdpEnabled()voidremoveProperty(java.lang.String key)voidremoveSystemProperty(java.lang.String key)voidsetConnected(boolean value)voidsetConnection(java.nio.channels.SocketChannel connection)voidsetCreationTime(long timestamp)voidsetCryptoKey(java.lang.Object key)voidsetDatagramChannel(java.nio.channels.DatagramChannel channel)voidsetHashId(java.lang.String hash)voidsetId(int id)voidsetLastActivityTime(long timestamp)voidsetLastLoggedInActivityTime(long timestamp)voidsetLastReadTime(long timestamp)voidsetLastWriteTime(long timestamp)voidsetLoggedIn(boolean value)voidsetMarkedForEviction()voidsetMaxIdleTime(int idleTime)voidsetMaxLoggedInIdleTime(int idleTime)voidsetNodeId(java.lang.String nodeId)voidsetPacketQueue(com.smartfoxserver.bitswarm.sessions.IPacketQueue queue)voidsetProperty(java.lang.String key, java.lang.Object property)voidsetReconnectionSeconds(int value)voidsetSessionManager(com.smartfoxserver.bitswarm.sessions.ISessionManager sessionManager)voidsetSystemProperty(java.lang.String key, java.lang.Object property)voidsetType(SessionType type)java.lang.StringtoString()voidunfreeze()
-
-
-
Field Detail
-
ENCRYPTION_ENABLED
public static final java.lang.String ENCRYPTION_ENABLED
- See Also:
- Constant Field Values
-
DATA_BUFFER
public static final java.lang.String DATA_BUFFER
- See Also:
- Constant Field Values
-
PROTOCOL
public static final java.lang.String PROTOCOL
- See Also:
- Constant Field Values
-
NO_IP
public static final java.lang.String NO_IP
- See Also:
- Constant Field Values
-
BBCLIENT
public static final java.lang.String BBCLIENT
- See Also:
- Constant Field Values
-
WS_CHANNEL
public static final java.lang.String WS_CHANNEL
- See Also:
- Constant Field Values
-
WS_REMOTE_IP
public static final java.lang.String WS_REMOTE_IP
- See Also:
- Constant Field Values
-
BB_REMOTE_IP
public static final java.lang.String BB_REMOTE_IP
- See Also:
- Constant Field Values
-
PACKET_READ_STATE
public static final java.lang.String PACKET_READ_STATE
- See Also:
- Constant Field Values
-
-
Method Detail
-
addReadBytes
public void addReadBytes(long amount)
- Specified by:
addReadBytesin interfaceISession
-
addWrittenBytes
public void addWrittenBytes(long amount)
- Specified by:
addWrittenBytesin interfaceISession
-
getConnection
public java.nio.channels.SocketChannel getConnection()
- Specified by:
getConnectionin interfaceISession
-
getDatagramChannel
public java.nio.channels.DatagramChannel getDatagramChannel()
- Specified by:
getDatagramChannelin interfaceISession
-
setDatagramChannel
public void setDatagramChannel(java.nio.channels.DatagramChannel channel)
- Specified by:
setDatagramChannelin interfaceISession
-
getCreationTime
public long getCreationTime()
Description copied from interface:ISessionThe timestamp at which the connection was done (milliseconds Unix Time)- Specified by:
getCreationTimein interfaceISession- Returns:
- the timestamp at which the connection was done (milliseconds Unix Time)
-
getHashId
public java.lang.String getHashId()
Description copied from interface:ISessionA unique string token used as an alternative session ID
-
getId
public int getId()
Description copied from interface:ISessionGet the unique session Id
-
getFullIpAddress
public java.lang.String 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
public java.lang.String 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
-
getFullServerIpAddress
public java.lang.String 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
-
getServerAddress
public java.lang.String 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
-
getLastActivityTime
public long getLastActivityTime()
Description copied from interface:ISessionThe last time that the 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)
-
getLastReadTime
public long getLastReadTime()
- Specified by:
getLastReadTimein interfaceISession
-
getLastWriteTime
public long getLastWriteTime()
- Specified by:
getLastWriteTimein interfaceISession
-
getMaxIdleTime
public int getMaxIdleTime()
Description copied from interface:ISessionGet the maximum time of socket inactivity after which the system will consider the User "idle" and disconnect it.NOTE: 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 User "idle" and disconnect it
-
getPacketQueue
public com.smartfoxserver.bitswarm.sessions.IPacketQueue getPacketQueue()
- Specified by:
getPacketQueuein interfaceISession
-
getNodeId
public java.lang.String getNodeId()
Description copied from interface:ISessionReturn the node Id in a cluster
-
getProperty
public java.lang.Object getProperty(java.lang.String key)
- Specified by:
getPropertyin interfaceISession
-
removeProperty
public void removeProperty(java.lang.String key)
- Specified by:
removePropertyin interfaceISession
-
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
-
getSystemProperty
public java.lang.Object getSystemProperty(java.lang.String key)
- Specified by:
getSystemPropertyin interfaceISession
-
removeSystemProperty
public void removeSystemProperty(java.lang.String key)
- Specified by:
removeSystemPropertyin interfaceISession
-
getType
public SessionType getType()
Description copied from interface:ISessionGet the Session type- Specified by:
getTypein interfaceISession- Returns:
- the Session type
- See Also:
SessionType
-
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
-
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.
-
setConnected
public void setConnected(boolean value)
- Specified by:
setConnectedin interfaceISession
-
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
-
setLoggedIn
public void setLoggedIn(boolean value)
- Specified by:
setLoggedInin interfaceISession
-
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 it.NOTE: 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.
-
setMaxLoggedInIdleTime
public void setMaxLoggedInIdleTime(int idleTime)
- Specified by:
setMaxLoggedInIdleTimein interfaceISession
-
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)
-
setLastLoggedInActivityTime
public void setLastLoggedInActivityTime(long timestamp)
- Specified by:
setLastLoggedInActivityTimein interfaceISession
-
isLocal
public boolean isLocal()
Description copied from interface:ISessionSee if the Session is local or hosted in another cluster node.
-
isMarkedForEviction
public boolean isMarkedForEviction()
- Specified by:
isMarkedForEvictionin interfaceISession
-
isUdpEnabled
public boolean isUdpEnabled()
- Specified by:
isUdpEnabledin interfaceISession
-
setConnection
public void setConnection(java.nio.channels.SocketChannel connection)
- Specified by:
setConnectionin interfaceISession
-
setPacketQueue
public void setPacketQueue(com.smartfoxserver.bitswarm.sessions.IPacketQueue queue)
- Specified by:
setPacketQueuein interfaceISession
-
setCreationTime
public void setCreationTime(long timestamp)
- Specified by:
setCreationTimein interfaceISession
-
setHashId
public void setHashId(java.lang.String hash)
-
setLastActivityTime
public void setLastActivityTime(long timestamp)
- Specified by:
setLastActivityTimein interfaceISession
-
setLastReadTime
public void setLastReadTime(long timestamp)
- Specified by:
setLastReadTimein interfaceISession
-
setLastWriteTime
public void setLastWriteTime(long timestamp)
- Specified by:
setLastWriteTimein interfaceISession
-
setMarkedForEviction
public void setMarkedForEviction()
- Specified by:
setMarkedForEvictionin interfaceISession
-
setMaxIdleTime
public void setMaxIdleTime(int idleTime)
- Specified by:
setMaxIdleTimein interfaceISession
-
setNodeId
public void setNodeId(java.lang.String nodeId)
-
setProperty
public void setProperty(java.lang.String key, java.lang.Object property)- Specified by:
setPropertyin interfaceISession
-
setSystemProperty
public void setSystemProperty(java.lang.String key, java.lang.Object property)- Specified by:
setSystemPropertyin interfaceISession
-
setType
public void setType(SessionType type)
-
getDroppedMessages
public int getDroppedMessages()
Description copied from interface:ISessionThe number of messages that were dropped since the connection- Specified by:
getDroppedMessagesin interfaceISession- Returns:
- the number of messages that were dropped since the connection
-
addDroppedMessages
public void addDroppedMessages(int amount)
- Specified by:
addDroppedMessagesin interfaceISession
-
getSessionManager
public com.smartfoxserver.bitswarm.sessions.ISessionManager getSessionManager()
- Specified by:
getSessionManagerin interfaceISession
-
setSessionManager
public void setSessionManager(com.smartfoxserver.bitswarm.sessions.ISessionManager sessionManager)
- Specified by:
setSessionManagerin interfaceISession
-
getFreezeTime
public long getFreezeTime()
- Specified by:
getFreezeTimein interfaceISession
-
isReconnectionTimeExpired
public boolean isReconnectionTimeExpired()
- Specified by:
isReconnectionTimeExpiredin interfaceISession
-
close
public void close() throws java.io.IOException
-
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.
-
setReconnectionSeconds
public void setReconnectionSeconds(int value)
- Specified by:
setReconnectionSecondsin interfaceISession
-
isEncrypted
public boolean isEncrypted()
- Specified by:
isEncryptedin interfaceISession
-
getCryptoKey
public java.lang.Object getCryptoKey()
- Specified by:
getCryptoKeyin interfaceISession
-
setCryptoKey
public void setCryptoKey(java.lang.Object key)
- Specified by:
setCryptoKeyin interfaceISession
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
-