public final class Session extends java.lang.Object implements ISession
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.
Modifier and Type | Field and 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 |
Constructor and Description |
---|
Session() |
Session(java.net.SocketAddress address) |
Modifier and Type | Method and 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 address
|
int |
getClientPort()
Get the client side TCP port number
|
java.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 connection
|
long |
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 ID
|
int |
getId()
Get the unique session Id
|
long |
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 cluster
|
com.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 far
|
int |
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 to
|
int |
getServerPort()
Get the server port to which the user connected to
|
com.smartfoxserver.bitswarm.sessions.ISessionManager |
getSessionManager() |
java.lang.Object |
getSystemProperty(java.lang.String key) |
SessionType |
getType()
Get the Session type
|
long |
getWrittenBytes()
The amount of data that was sent to the client so far
|
boolean |
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() |
public static final java.lang.String ENCRYPTION_ENABLED
public static final java.lang.String DATA_BUFFER
public static final java.lang.String PROTOCOL
public static final java.lang.String NO_IP
public static final java.lang.String BBCLIENT
public static final java.lang.String WS_CHANNEL
public static final java.lang.String WS_REMOTE_IP
public static final java.lang.String BB_REMOTE_IP
public static final java.lang.String PACKET_READ_STATE
public void addReadBytes(long amount)
addReadBytes
in interface ISession
public void addWrittenBytes(long amount)
addWrittenBytes
in interface ISession
public java.nio.channels.SocketChannel getConnection()
getConnection
in interface ISession
public java.nio.channels.DatagramChannel getDatagramChannel()
getDatagramChannel
in interface ISession
public void setDatagramChannel(java.nio.channels.DatagramChannel channel)
setDatagramChannel
in interface ISession
public long getCreationTime()
ISession
getCreationTime
in interface ISession
public java.lang.String getHashId()
ISession
public int getId()
ISession
public java.lang.String getFullIpAddress()
ISession
getFullIpAddress
in interface ISession
public java.lang.String getAddress()
ISession
getAddress
in interface ISession
public int getClientPort()
ISession
getClientPort
in interface ISession
public int getServerPort()
ISession
getServerPort
in interface ISession
public java.lang.String getFullServerIpAddress()
ISession
getFullServerIpAddress
in interface ISession
public java.lang.String getServerAddress()
ISession
getServerAddress
in interface ISession
public long getLastActivityTime()
ISession
getLastActivityTime
in interface ISession
public long getLastReadTime()
getLastReadTime
in interface ISession
public long getLastWriteTime()
getLastWriteTime
in interface ISession
public int getMaxIdleTime()
ISession
NOTE: This is valid until the client is not logged in, then the maxLoggedInIdleTime will be used.
getMaxIdleTime
in interface ISession
public com.smartfoxserver.bitswarm.sessions.IPacketQueue getPacketQueue()
getPacketQueue
in interface ISession
public java.lang.String getNodeId()
ISession
public java.lang.Object getProperty(java.lang.String key)
getProperty
in interface ISession
public void removeProperty(java.lang.String key)
removeProperty
in interface ISession
public long getReadBytes()
ISession
getReadBytes
in interface ISession
public java.lang.Object getSystemProperty(java.lang.String key)
getSystemProperty
in interface ISession
public void removeSystemProperty(java.lang.String key)
removeSystemProperty
in interface ISession
public SessionType getType()
ISession
getType
in interface ISession
SessionType
public long getWrittenBytes()
ISession
getWrittenBytes
in interface ISession
public boolean isConnected()
ISession
isConnected
in interface ISession
public void setConnected(boolean value)
setConnected
in interface ISession
public boolean isLoggedIn()
ISession
isLoggedIn
in interface ISession
public void setLoggedIn(boolean value)
setLoggedIn
in interface ISession
public int getMaxLoggedInIdleTime()
ISession
NOTE: This applies only if the client is logged in.
getMaxLoggedInIdleTime
in interface ISession
public void setMaxLoggedInIdleTime(int idleTime)
setMaxLoggedInIdleTime
in interface ISession
public long getLastLoggedInActivityTime()
ISession
getLastLoggedInActivityTime
in interface ISession
public void setLastLoggedInActivityTime(long timestamp)
setLastLoggedInActivityTime
in interface ISession
public boolean isLocal()
ISession
public boolean isMarkedForEviction()
isMarkedForEviction
in interface ISession
public boolean isUdpEnabled()
isUdpEnabled
in interface ISession
public void setConnection(java.nio.channels.SocketChannel connection)
setConnection
in interface ISession
public void setPacketQueue(com.smartfoxserver.bitswarm.sessions.IPacketQueue queue)
setPacketQueue
in interface ISession
public void setCreationTime(long timestamp)
setCreationTime
in interface ISession
public void setHashId(java.lang.String hash)
public void setLastActivityTime(long timestamp)
setLastActivityTime
in interface ISession
public void setLastReadTime(long timestamp)
setLastReadTime
in interface ISession
public void setLastWriteTime(long timestamp)
setLastWriteTime
in interface ISession
public void setMarkedForEviction()
setMarkedForEviction
in interface ISession
public void setMaxIdleTime(int idleTime)
setMaxIdleTime
in interface ISession
public void setNodeId(java.lang.String nodeId)
public void setProperty(java.lang.String key, java.lang.Object property)
setProperty
in interface ISession
public void setSystemProperty(java.lang.String key, java.lang.Object property)
setSystemProperty
in interface ISession
public void setType(SessionType type)
public int getDroppedMessages()
ISession
getDroppedMessages
in interface ISession
public void addDroppedMessages(int amount)
addDroppedMessages
in interface ISession
public com.smartfoxserver.bitswarm.sessions.ISessionManager getSessionManager()
getSessionManager
in interface ISession
public void setSessionManager(com.smartfoxserver.bitswarm.sessions.ISessionManager sessionManager)
setSessionManager
in interface ISession
public long getFreezeTime()
getFreezeTime
in interface ISession
public boolean isReconnectionTimeExpired()
isReconnectionTimeExpired
in interface ISession
public void close() throws java.io.IOException
public int getReconnectionSeconds()
ISession
getReconnectionSeconds
in interface ISession
public void setReconnectionSeconds(int value)
setReconnectionSeconds
in interface ISession
public boolean isEncrypted()
isEncrypted
in interface ISession
public java.lang.Object getCryptoKey()
getCryptoKey
in interface ISession
public void setCryptoKey(java.lang.Object key)
setCryptoKey
in interface ISession
public java.lang.String toString()
toString
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object