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 ISessionpublic void addWrittenBytes(long amount)
addWrittenBytes in interface ISessionpublic java.nio.channels.SocketChannel getConnection()
getConnection in interface ISessionpublic java.nio.channels.DatagramChannel getDatagramChannel()
getDatagramChannel in interface ISessionpublic void setDatagramChannel(java.nio.channels.DatagramChannel channel)
setDatagramChannel in interface ISessionpublic long getCreationTime()
ISessiongetCreationTime in interface ISessionpublic java.lang.String getHashId()
ISessionpublic int getId()
ISessionpublic java.lang.String getFullIpAddress()
ISessiongetFullIpAddress in interface ISessionpublic java.lang.String getAddress()
ISessiongetAddress in interface ISessionpublic int getClientPort()
ISessiongetClientPort in interface ISessionpublic int getServerPort()
ISessiongetServerPort in interface ISessionpublic java.lang.String getFullServerIpAddress()
ISessiongetFullServerIpAddress in interface ISessionpublic java.lang.String getServerAddress()
ISessiongetServerAddress in interface ISessionpublic long getLastActivityTime()
ISessiongetLastActivityTime in interface ISessionpublic long getLastReadTime()
getLastReadTime in interface ISessionpublic long getLastWriteTime()
getLastWriteTime in interface ISessionpublic int getMaxIdleTime()
ISessionNOTE: This is valid until the client is not logged in, then the maxLoggedInIdleTime will be used.
getMaxIdleTime in interface ISessionpublic com.smartfoxserver.bitswarm.sessions.IPacketQueue getPacketQueue()
getPacketQueue in interface ISessionpublic java.lang.String getNodeId()
ISessionpublic java.lang.Object getProperty(java.lang.String key)
getProperty in interface ISessionpublic void removeProperty(java.lang.String key)
removeProperty in interface ISessionpublic long getReadBytes()
ISessiongetReadBytes in interface ISessionpublic java.lang.Object getSystemProperty(java.lang.String key)
getSystemProperty in interface ISessionpublic void removeSystemProperty(java.lang.String key)
removeSystemProperty in interface ISessionpublic SessionType getType()
ISessiongetType in interface ISessionSessionTypepublic long getWrittenBytes()
ISessiongetWrittenBytes in interface ISessionpublic boolean isConnected()
ISessionisConnected in interface ISessionpublic void setConnected(boolean value)
setConnected in interface ISessionpublic boolean isLoggedIn()
ISessionisLoggedIn in interface ISessionpublic void setLoggedIn(boolean value)
setLoggedIn in interface ISessionpublic int getMaxLoggedInIdleTime()
ISessionNOTE: This applies only if the client is logged in.
getMaxLoggedInIdleTime in interface ISessionpublic void setMaxLoggedInIdleTime(int idleTime)
setMaxLoggedInIdleTime in interface ISessionpublic long getLastLoggedInActivityTime()
ISessiongetLastLoggedInActivityTime in interface ISessionpublic void setLastLoggedInActivityTime(long timestamp)
setLastLoggedInActivityTime in interface ISessionpublic boolean isLocal()
ISessionpublic boolean isMarkedForEviction()
isMarkedForEviction in interface ISessionpublic boolean isUdpEnabled()
isUdpEnabled in interface ISessionpublic void setConnection(java.nio.channels.SocketChannel connection)
setConnection in interface ISessionpublic void setPacketQueue(com.smartfoxserver.bitswarm.sessions.IPacketQueue queue)
setPacketQueue in interface ISessionpublic void setCreationTime(long timestamp)
setCreationTime in interface ISessionpublic void setHashId(java.lang.String hash)
public void setLastActivityTime(long timestamp)
setLastActivityTime in interface ISessionpublic void setLastReadTime(long timestamp)
setLastReadTime in interface ISessionpublic void setLastWriteTime(long timestamp)
setLastWriteTime in interface ISessionpublic void setMarkedForEviction()
setMarkedForEviction in interface ISessionpublic void setMaxIdleTime(int idleTime)
setMaxIdleTime in interface ISessionpublic void setNodeId(java.lang.String nodeId)
public void setProperty(java.lang.String key,
java.lang.Object property)
setProperty in interface ISessionpublic void setSystemProperty(java.lang.String key,
java.lang.Object property)
setSystemProperty in interface ISessionpublic void setType(SessionType type)
public int getDroppedMessages()
ISessiongetDroppedMessages in interface ISessionpublic void addDroppedMessages(int amount)
addDroppedMessages in interface ISessionpublic com.smartfoxserver.bitswarm.sessions.ISessionManager getSessionManager()
getSessionManager in interface ISessionpublic void setSessionManager(com.smartfoxserver.bitswarm.sessions.ISessionManager sessionManager)
setSessionManager in interface ISessionpublic long getFreezeTime()
getFreezeTime in interface ISessionpublic boolean isReconnectionTimeExpired()
isReconnectionTimeExpired in interface ISessionpublic void close()
throws java.io.IOException
public int getReconnectionSeconds()
ISessiongetReconnectionSeconds in interface ISessionpublic void setReconnectionSeconds(int value)
setReconnectionSeconds in interface ISessionpublic boolean isEncrypted()
isEncrypted in interface ISessionpublic java.lang.Object getCryptoKey()
getCryptoKey in interface ISessionpublic void setCryptoKey(java.lang.Object key)
setCryptoKey in interface ISessionpublic java.lang.String toString()
toString in class java.lang.Objectpublic boolean equals(java.lang.Object obj)
equals in class java.lang.Object