Class Session

java.lang.Object
com.smartfoxserver.bitswarm.sessions.Session
All Implemented Interfaces:
ISession

public class Session extends 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 tunneling and more. Each connected User in the system is backed by its own Session.

  • Field Details

  • Constructor Details

    • Session

      public Session()
    • Session

      public Session(SocketAddress address)
  • Method Details

    • destroy

      public void destroy()
      Specified by:
      destroy in interface ISession
    • addReadBytes

      public void addReadBytes(long amount)
      Specified by:
      addReadBytes in interface ISession
      Internal
    • addWrittenBytes

      public void addWrittenBytes(long amount)
      Specified by:
      addWrittenBytes in interface ISession
      Internal
    • getConnection

      public SocketChannel getConnection()
      Specified by:
      getConnection in interface ISession
      Internal
    • getCreationTime

      public long getCreationTime()
      Description copied from interface: ISession
      The Session's creation time as Unix Time in milliseconds.
      Specified by:
      getCreationTime in interface ISession
      Returns:
      the creation time
      Internal
    • getHashId

      public String getHashId()
      Description copied from interface: ISession
      A unique string token that identifies the Session
      Specified by:
      getHashId in interface ISession
      Returns:
      the unique Session token
      Internal
    • getId

      public int getId()
      Description copied from interface: ISession
      Get the unique session Id
      Specified by:
      getId in interface ISession
      Returns:
      the unique session id
    • getFullIpAddress

      public 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 interface ISession
      Returns:
      the ip address and port of the client
    • getAddress

      public String getAddress()
      Description copied from interface: ISession
      Get the session IP address
      Specified by:
      getAddress in interface ISession
      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 interface ISession
      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 interface ISession
      Returns:
      get the server port to which the user connected to
      Internal
    • getFullServerIpAddress

      public 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 interface ISession
      Returns:
      get the server address and port to which the user connected to
      Internal
    • getServerAddress

      public String getServerAddress()
      Description copied from interface: ISession
      Get the server address to which the user connected to
      Specified by:
      getServerAddress in interface ISession
      Returns:
      get the server address to which the user connected to
      Internal
    • getLastActivityTime

      public long getLastActivityTime()
      Description copied from interface: ISession
      The last time that the client Session has sent a packet (milliseconds Unix Time)
      Specified by:
      getLastActivityTime in interface ISession
      Returns:
      the last time that the Session has sent a packet (milliseconds Unix Time)
      Internal
    • getLastReadTime

      public long getLastReadTime()
      Specified by:
      getLastReadTime in interface ISession
      Internal
    • getLastWriteTime

      public long getLastWriteTime()
      Specified by:
      getLastWriteTime in interface ISession
      Internal
    • getMaxIdleTime

      public int getMaxIdleTime()
      Description copied from interface: ISession
      Get the maximum time of socket inactivity after which the system will consider the Session "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 interface ISession
      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:
      getPacketOutQueue in interface ISession
      Internal
    • getDatagramOutQueue

      public com.smartfoxserver.bitswarm.sessions.IPacketQueue getDatagramOutQueue()
      Specified by:
      getDatagramOutQueue in interface ISession
      Internal
    • containsProperty

      public boolean containsProperty(String name)
      Specified by:
      containsProperty in interface ISession
    • getProperty

      public Object getProperty(String key)
      Description copied from interface: ISession
      Get a custom property from the Session
      Specified by:
      getProperty in interface ISession
      Parameters:
      key - the property name
      Returns:
      the associated value, null if no property exists
    • removeProperty

      public void removeProperty(String key)
      Description copied from interface: ISession
      Remove an asoociated property
      Specified by:
      removeProperty in interface ISession
      Parameters:
      key - name of the property
    • 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 interface ISession
      Returns:
      the amount of data in bytes that the user has sent so far
      Internal
    • containsSystemProperty

      public boolean containsSystemProperty(String name)
      Specified by:
      containsSystemProperty in interface ISession
      Internal
    • getSystemProperty

      public Object getSystemProperty(String key)
      Specified by:
      getSystemProperty in interface ISession
      Internal
    • removeSystemProperty

      public void removeSystemProperty(String key)
      Specified by:
      removeSystemProperty in interface ISession
      Internal
    • getType

      public SessionType getType()
      Description copied from interface: ISession
      Get the Session type
      Specified by:
      getType in interface ISession
      Returns:
      the Session type
      See Also:
      Internal
    • 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 interface ISession
      Returns:
      the amount of data that was sent to the client so far
      Internal
    • isConnected

      public boolean isConnected()
      Description copied from interface: ISession
      Check if the session is connected.
      Specified by:
      isConnected in interface ISession
      Returns:
      true if the session is connected.
      Internal
    • setConnected

      public void setConnected(boolean value)
      Specified by:
      setConnected in interface ISession
      Internal
    • handshakeComplete

      public boolean handshakeComplete()
      Specified by:
      handshakeComplete in interface ISession
      Internal
    • handshakeComplete

      public void handshakeComplete(boolean value)
      Specified by:
      handshakeComplete in interface ISession
      Internal
    • isLoggedIn

      public boolean isLoggedIn()
      Description copied from interface: ISession
      Check if the the Session is logged in.
      Specified by:
      isLoggedIn in interface ISession
      Returns:
      true if the session has performed the login process
      Internal
    • setLoggedIn

      public void setLoggedIn(boolean value)
      Specified by:
      setLoggedIn in interface ISession
      Internal
    • 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 interface ISession
      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:
      setMaxLoggedInIdleTime in interface ISession
      Internal
    • getMaxUdpIdleTime

      public int getMaxUdpIdleTime()
      Description copied from interface: ISession
      Get the maximum idle time for User's UDP connection before it is considered disconnected

      NOTE: This applies only if the client has an active UDP connection

      Specified by:
      getMaxUdpIdleTime in interface ISession
      Returns:
      the max number of idle seconds
      Internal
    • setMaxUdpIdleTime

      public void setMaxUdpIdleTime(int seconds)
      Specified by:
      setMaxUdpIdleTime in interface ISession
      Internal
    • isUdpKeepAlive

      public boolean isUdpKeepAlive()
      Specified by:
      isUdpKeepAlive in interface ISession
      Internal
    • setUdpKeepAlive

      public void setUdpKeepAlive(boolean value)
      Specified by:
      setUdpKeepAlive in interface ISession
      Internal
    • 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 interface ISession
      Returns:
      the last time that the Session has sent a request (milliseconds Unix Time)
      Internal
    • setLastLoggedInActivityTime

      public void setLastLoggedInActivityTime(long timestamp)
      Specified by:
      setLastLoggedInActivityTime in interface ISession
      Internal
    • getUdpConnection

      public com.smartfoxserver.bitswarm.data.UDPConnection getUdpConnection()
      Specified by:
      getUdpConnection in interface ISession
      Internal
    • setUdpConnection

      public void setUdpConnection(com.smartfoxserver.bitswarm.data.UDPConnection conn)
      Specified by:
      setUdpConnection in interface ISession
      Internal
    • isIdle

      public boolean isIdle()
      Specified by:
      isIdle in interface ISession
      Internal
    • isMarkedForEviction

      public boolean isMarkedForEviction()
      Specified by:
      isMarkedForEviction in interface ISession
      Internal
    • isUdpConnected

      public boolean isUdpConnected()
      Specified by:
      isUdpConnected in interface ISession
      Internal
    • setConnection

      public void setConnection(SocketChannel connection)
      Specified by:
      setConnection in interface ISession
      Internal
    • setPacketOutQueue

      public void setPacketOutQueue(com.smartfoxserver.bitswarm.sessions.IPacketQueue queue)
      Specified by:
      setPacketOutQueue in interface ISession
      Internal
    • setDatagramOutQueue

      public void setDatagramOutQueue(com.smartfoxserver.bitswarm.sessions.IPacketQueue queue)
      Specified by:
      setDatagramOutQueue in interface ISession
      Internal
    • setCreationTime

      public void setCreationTime(long timestamp)
      Specified by:
      setCreationTime in interface ISession
      Internal
    • setHashId

      public void setHashId(String hash)
      Specified by:
      setHashId in interface ISession
      Internal
    • setId

      public void setId(int id)
      Specified by:
      setId in interface ISession
      Internal
    • setLastActivityTime

      public void setLastActivityTime(long timestamp)
      Specified by:
      setLastActivityTime in interface ISession
      Internal
    • setLastReadTime

      public void setLastReadTime(long timestamp)
      Specified by:
      setLastReadTime in interface ISession
      Internal
    • setLastWriteTime

      public void setLastWriteTime(long timestamp)
      Specified by:
      setLastWriteTime in interface ISession
      Internal
    • setMarkedForEviction

      public void setMarkedForEviction()
      Specified by:
      setMarkedForEviction in interface ISession
      Internal
    • setMaxIdleTime

      public void setMaxIdleTime(int idleTime)
      Specified by:
      setMaxIdleTime in interface ISession
      Internal
    • setProperty

      public void setProperty(String key, Object property)
      Description copied from interface: ISession
      Can 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:
      setProperty in interface ISession
      Parameters:
      key - name of the property
      property - any Object
    • setSystemProperty

      public void setSystemProperty(String key, Object property)
      Specified by:
      setSystemProperty in interface ISession
      Internal
    • setType

      public void setType(SessionType type)
      Specified by:
      setType in interface ISession
      Internal
    • getTcpDroppedPackets

      public long getTcpDroppedPackets()
      Specified by:
      getTcpDroppedPackets in interface ISession
      Internal
    • addTcpDroppedPackets

      public void addTcpDroppedPackets(int amount)
      Specified by:
      addTcpDroppedPackets in interface ISession
      Internal
    • getUdpDroppedPackets

      public long getUdpDroppedPackets()
      Specified by:
      getUdpDroppedPackets in interface ISession
      Internal
    • addUdpDroppedPackets

      public void addUdpDroppedPackets(int amount)
      Specified by:
      addUdpDroppedPackets in interface ISession
      Internal
    • getSessionManager

      public com.smartfoxserver.bitswarm.sessions.ISessionManager getSessionManager()
      Specified by:
      getSessionManager in interface ISession
      Internal
    • setSessionManager

      public void setSessionManager(com.smartfoxserver.bitswarm.sessions.ISessionManager sessionManager)
      Specified by:
      setSessionManager in interface ISession
      Internal
    • isFrozen

      public boolean isFrozen()
      Specified by:
      isFrozen in interface ISession
      Internal
    • freeze

      public void freeze()
      Specified by:
      freeze in interface ISession
      Internal
    • unfreeze

      public void unfreeze()
      Specified by:
      unfreeze in interface ISession
      Internal
    • getFreezeTime

      public long getFreezeTime()
      Specified by:
      getFreezeTime in interface ISession
      Internal
    • isReconnectionTimeExpired

      public boolean isReconnectionTimeExpired()
      Specified by:
      isReconnectionTimeExpired in interface ISession
      Internal
    • close

      public void close() throws IOException
      Specified by:
      close in interface ISession
      Throws:
      IOException
      Internal
    • 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 interface ISession
      Returns:
      the amount of seconds allowed for a reconnection.
      Internal
    • setReconnectionSeconds

      public void setReconnectionSeconds(int value)
      Specified by:
      setReconnectionSeconds in interface ISession
      Internal
    • isEncrypted

      public boolean isEncrypted()
      Specified by:
      isEncrypted in interface ISession
      Internal
    • getCryptoKey

      public Object getCryptoKey()
      Specified by:
      getCryptoKey in interface ISession
      Internal
    • setCryptoKey

      public void setCryptoKey(Object key)
      Specified by:
      setCryptoKey in interface ISession
      Internal
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • handleRDPDisconnection

      public void handleRDPDisconnection()
      Specified by:
      handleRDPDisconnection in interface ISession
      Internal
    • getInSeqProcessor

      public com.smartfoxserver.bitswarm.sessions.ISeqProcessor getInSeqProcessor()
      Specified by:
      getInSeqProcessor in interface ISession
    • setInSeqProcessor

      public void setInSeqProcessor(com.smartfoxserver.bitswarm.sessions.ISeqProcessor processor)
      Specified by:
      setInSeqProcessor in interface ISession