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.String
BB_REMOTE_IP
static java.lang.String
BBCLIENT
static java.lang.String
DATA_BUFFER
static java.lang.String
ENCRYPTION_ENABLED
static java.lang.String
NO_IP
static java.lang.String
PACKET_READ_STATE
static java.lang.String
PROTOCOL
static java.lang.String
WS_CHANNEL
static java.lang.String
WS_REMOTE_IP
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addDroppedMessages(int amount)
void
addReadBytes(long amount)
void
addWrittenBytes(long amount)
void
close()
boolean
equals(java.lang.Object obj)
void
freeze()
java.lang.String
getAddress()
Get the session IP addressint
getClientPort()
Get the client side TCP port numberjava.nio.channels.SocketChannel
getConnection()
long
getCreationTime()
The timestamp at which the connection was done (milliseconds Unix Time)java.lang.Object
getCryptoKey()
java.nio.channels.DatagramChannel
getDatagramChannel()
int
getDroppedMessages()
The number of messages that were dropped since the connectionlong
getFreezeTime()
java.lang.String
getFullIpAddress()
Get the IPAddress and Port of the user as a String in the format "1.2.3.4:1234"java.lang.String
getFullServerIpAddress()
Get the full server address and port to which the user connected to, in the form "1.2.3.4:1234"java.lang.String
getHashId()
A unique string token used as an alternative session IDint
getId()
Get the unique session Idlong
getLastActivityTime()
The last time that the session has sent a packet (milliseconds Unix Time)long
getLastLoggedInActivityTime()
The last time that the session has sent a request (milliseconds Unix Time)long
getLastReadTime()
long
getLastWriteTime()
int
getMaxIdleTime()
Get the maximum time of socket inactivity after which the system will consider the User "idle" and disconnect it.int
getMaxLoggedInIdleTime()
Get the maximum time of User inactivity after which the system will consider the session "idle" and disconnect it.java.lang.String
getNodeId()
Return the node Id in a clustercom.smartfoxserver.bitswarm.sessions.IPacketQueue
getPacketQueue()
java.lang.Object
getProperty(java.lang.String key)
long
getReadBytes()
The amount of data in bytes that the client has sent so farint
getReconnectionSeconds()
Get the interval of time allowed for a Session to attempt a reconnection after and abrupt loss of connection.java.lang.String
getServerAddress()
Get the server address to which the user connected toint
getServerPort()
Get the server port to which the user connected tocom.smartfoxserver.bitswarm.sessions.ISessionManager
getSessionManager()
java.lang.Object
getSystemProperty(java.lang.String key)
SessionType
getType()
Get the Session typelong
getWrittenBytes()
The amount of data that was sent to the client so farboolean
isConnected()
Check if the session is connected.boolean
isEncrypted()
boolean
isFrozen()
boolean
isIdle()
boolean
isLocal()
See if the Session is local or hosted in another cluster node.boolean
isLoggedIn()
Check if the the Session is logged in.boolean
isMarkedForEviction()
boolean
isReconnectionTimeExpired()
boolean
isUdpEnabled()
void
removeProperty(java.lang.String key)
void
removeSystemProperty(java.lang.String key)
void
setConnected(boolean value)
void
setConnection(java.nio.channels.SocketChannel connection)
void
setCreationTime(long timestamp)
void
setCryptoKey(java.lang.Object key)
void
setDatagramChannel(java.nio.channels.DatagramChannel channel)
void
setHashId(java.lang.String hash)
void
setId(int id)
void
setLastActivityTime(long timestamp)
void
setLastLoggedInActivityTime(long timestamp)
void
setLastReadTime(long timestamp)
void
setLastWriteTime(long timestamp)
void
setLoggedIn(boolean value)
void
setMarkedForEviction()
void
setMaxIdleTime(int idleTime)
void
setMaxLoggedInIdleTime(int idleTime)
void
setNodeId(java.lang.String nodeId)
void
setPacketQueue(com.smartfoxserver.bitswarm.sessions.IPacketQueue queue)
void
setProperty(java.lang.String key, java.lang.Object property)
void
setReconnectionSeconds(int value)
void
setSessionManager(com.smartfoxserver.bitswarm.sessions.ISessionManager sessionManager)
void
setSystemProperty(java.lang.String key, java.lang.Object property)
void
setType(SessionType type)
java.lang.String
toString()
void
unfreeze()
-
-
-
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:
addReadBytes
in interfaceISession
-
addWrittenBytes
public void addWrittenBytes(long amount)
- Specified by:
addWrittenBytes
in interfaceISession
-
getConnection
public java.nio.channels.SocketChannel getConnection()
- Specified by:
getConnection
in interfaceISession
-
getDatagramChannel
public java.nio.channels.DatagramChannel getDatagramChannel()
- Specified by:
getDatagramChannel
in interfaceISession
-
setDatagramChannel
public void setDatagramChannel(java.nio.channels.DatagramChannel channel)
- Specified by:
setDatagramChannel
in interfaceISession
-
getCreationTime
public long getCreationTime()
Description copied from interface:ISession
The timestamp at which the connection was done (milliseconds Unix Time)- Specified by:
getCreationTime
in interfaceISession
- Returns:
- the timestamp at which the connection was done (milliseconds Unix Time)
-
getHashId
public java.lang.String getHashId()
Description copied from interface:ISession
A unique string token used as an alternative session ID
-
getId
public int getId()
Description copied from interface:ISession
Get the unique session Id
-
getFullIpAddress
public java.lang.String getFullIpAddress()
Description copied from interface:ISession
Get the IPAddress and Port of the user as a String in the format "1.2.3.4:1234"- Specified by:
getFullIpAddress
in interfaceISession
- Returns:
- the ip address and port of the client
-
getAddress
public java.lang.String getAddress()
Description copied from interface:ISession
Get the session IP address- Specified by:
getAddress
in interfaceISession
- Returns:
- the session IP address
-
getClientPort
public int getClientPort()
Description copied from interface:ISession
Get the client side TCP port number- Specified by:
getClientPort
in interfaceISession
- Returns:
- get the client side TCP port number
-
getServerPort
public int getServerPort()
Description copied from interface:ISession
Get the server port to which the user connected to- Specified by:
getServerPort
in interfaceISession
- Returns:
- get the server port to which the user connected to
-
getFullServerIpAddress
public java.lang.String getFullServerIpAddress()
Description copied from interface:ISession
Get the full server address and port to which the user connected to, in the form "1.2.3.4:1234"- Specified by:
getFullServerIpAddress
in interfaceISession
- Returns:
- get the server address and port to which the user connected to
-
getServerAddress
public java.lang.String getServerAddress()
Description copied from interface:ISession
Get the server address to which the user connected to- Specified by:
getServerAddress
in interfaceISession
- Returns:
- get the server address to which the user connected to
-
getLastActivityTime
public long getLastActivityTime()
Description copied from interface:ISession
The last time that the session has sent a packet (milliseconds Unix Time)- Specified by:
getLastActivityTime
in interfaceISession
- Returns:
- the last time that the session has sent a packet (milliseconds Unix Time)
-
getLastReadTime
public long getLastReadTime()
- Specified by:
getLastReadTime
in interfaceISession
-
getLastWriteTime
public long getLastWriteTime()
- Specified by:
getLastWriteTime
in interfaceISession
-
getMaxIdleTime
public int getMaxIdleTime()
Description copied from interface:ISession
Get 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:
getMaxIdleTime
in 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:
getPacketQueue
in interfaceISession
-
getNodeId
public java.lang.String getNodeId()
Description copied from interface:ISession
Return the node Id in a cluster
-
getProperty
public java.lang.Object getProperty(java.lang.String key)
- Specified by:
getProperty
in interfaceISession
-
removeProperty
public void removeProperty(java.lang.String key)
- Specified by:
removeProperty
in interfaceISession
-
getReadBytes
public long getReadBytes()
Description copied from interface:ISession
The amount of data in bytes that the client has sent so far- Specified by:
getReadBytes
in 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:
getSystemProperty
in interfaceISession
-
removeSystemProperty
public void removeSystemProperty(java.lang.String key)
- Specified by:
removeSystemProperty
in interfaceISession
-
getType
public SessionType getType()
Description copied from interface:ISession
Get the Session type- Specified by:
getType
in interfaceISession
- Returns:
- the Session type
- See Also:
SessionType
-
getWrittenBytes
public long getWrittenBytes()
Description copied from interface:ISession
The amount of data that was sent to the client so far- Specified by:
getWrittenBytes
in interfaceISession
- Returns:
- the amount of data that was sent to the client so far
-
isConnected
public boolean isConnected()
Description copied from interface:ISession
Check if the session is connected.- Specified by:
isConnected
in interfaceISession
- Returns:
- true if the session is connected.
-
setConnected
public void setConnected(boolean value)
- Specified by:
setConnected
in interfaceISession
-
isLoggedIn
public boolean isLoggedIn()
Description copied from interface:ISession
Check if the the Session is logged in.- Specified by:
isLoggedIn
in interfaceISession
- Returns:
- true if the session has performed the login process
-
setLoggedIn
public void setLoggedIn(boolean value)
- Specified by:
setLoggedIn
in interfaceISession
-
getMaxLoggedInIdleTime
public int getMaxLoggedInIdleTime()
Description copied from interface:ISession
Get 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:
getMaxLoggedInIdleTime
in 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:
setMaxLoggedInIdleTime
in interfaceISession
-
getLastLoggedInActivityTime
public long getLastLoggedInActivityTime()
Description copied from interface:ISession
The last time that the session has sent a request (milliseconds Unix Time)- Specified by:
getLastLoggedInActivityTime
in interfaceISession
- Returns:
- the last time that the session has sent a request (milliseconds Unix Time)
-
setLastLoggedInActivityTime
public void setLastLoggedInActivityTime(long timestamp)
- Specified by:
setLastLoggedInActivityTime
in interfaceISession
-
isLocal
public boolean isLocal()
Description copied from interface:ISession
See if the Session is local or hosted in another cluster node.
-
isMarkedForEviction
public boolean isMarkedForEviction()
- Specified by:
isMarkedForEviction
in interfaceISession
-
isUdpEnabled
public boolean isUdpEnabled()
- Specified by:
isUdpEnabled
in interfaceISession
-
setConnection
public void setConnection(java.nio.channels.SocketChannel connection)
- Specified by:
setConnection
in interfaceISession
-
setPacketQueue
public void setPacketQueue(com.smartfoxserver.bitswarm.sessions.IPacketQueue queue)
- Specified by:
setPacketQueue
in interfaceISession
-
setCreationTime
public void setCreationTime(long timestamp)
- Specified by:
setCreationTime
in interfaceISession
-
setHashId
public void setHashId(java.lang.String hash)
-
setLastActivityTime
public void setLastActivityTime(long timestamp)
- Specified by:
setLastActivityTime
in interfaceISession
-
setLastReadTime
public void setLastReadTime(long timestamp)
- Specified by:
setLastReadTime
in interfaceISession
-
setLastWriteTime
public void setLastWriteTime(long timestamp)
- Specified by:
setLastWriteTime
in interfaceISession
-
setMarkedForEviction
public void setMarkedForEviction()
- Specified by:
setMarkedForEviction
in interfaceISession
-
setMaxIdleTime
public void setMaxIdleTime(int idleTime)
- Specified by:
setMaxIdleTime
in interfaceISession
-
setNodeId
public void setNodeId(java.lang.String nodeId)
-
setProperty
public void setProperty(java.lang.String key, java.lang.Object property)
- Specified by:
setProperty
in interfaceISession
-
setSystemProperty
public void setSystemProperty(java.lang.String key, java.lang.Object property)
- Specified by:
setSystemProperty
in interfaceISession
-
setType
public void setType(SessionType type)
-
getDroppedMessages
public int getDroppedMessages()
Description copied from interface:ISession
The number of messages that were dropped since the connection- Specified by:
getDroppedMessages
in interfaceISession
- Returns:
- the number of messages that were dropped since the connection
-
addDroppedMessages
public void addDroppedMessages(int amount)
- Specified by:
addDroppedMessages
in interfaceISession
-
getSessionManager
public com.smartfoxserver.bitswarm.sessions.ISessionManager getSessionManager()
- Specified by:
getSessionManager
in interfaceISession
-
setSessionManager
public void setSessionManager(com.smartfoxserver.bitswarm.sessions.ISessionManager sessionManager)
- Specified by:
setSessionManager
in interfaceISession
-
getFreezeTime
public long getFreezeTime()
- Specified by:
getFreezeTime
in interfaceISession
-
isReconnectionTimeExpired
public boolean isReconnectionTimeExpired()
- Specified by:
isReconnectionTimeExpired
in interfaceISession
-
close
public void close() throws java.io.IOException
-
getReconnectionSeconds
public int getReconnectionSeconds()
Description copied from interface:ISession
Get 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:
getReconnectionSeconds
in interfaceISession
- Returns:
- the amount of seconds allowed for a reconnection.
-
setReconnectionSeconds
public void setReconnectionSeconds(int value)
- Specified by:
setReconnectionSeconds
in interfaceISession
-
isEncrypted
public boolean isEncrypted()
- Specified by:
isEncrypted
in interfaceISession
-
getCryptoKey
public java.lang.Object getCryptoKey()
- Specified by:
getCryptoKey
in interfaceISession
-
setCryptoKey
public void setCryptoKey(java.lang.Object key)
- Specified by:
setCryptoKey
in interfaceISession
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
-