Class 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.

    • Constructor Detail

      • Session

        public Session()
      • Session

        public Session​(java.net.SocketAddress address)
    • Method Detail

      • addReadBytes

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

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

        public java.nio.channels.SocketChannel getConnection()
        Specified by:
        getConnection in interface ISession
      • getDatagramChannel

        public java.nio.channels.DatagramChannel getDatagramChannel()
        Specified by:
        getDatagramChannel in interface ISession
      • setDatagramChannel

        public void setDatagramChannel​(java.nio.channels.DatagramChannel channel)
        Specified by:
        setDatagramChannel in interface ISession
      • getCreationTime

        public long getCreationTime()
        Description copied from interface: ISession
        The timestamp at which the connection was done (milliseconds Unix Time)
        Specified by:
        getCreationTime in interface ISession
        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
        Specified by:
        getHashId in interface ISession
        Returns:
        a unique string token used as an alternative session ID
      • 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 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 interface ISession
        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 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
      • 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 interface ISession
        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 interface ISession
        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 interface ISession
        Returns:
        the last time that the session has sent a packet (milliseconds Unix Time)
      • 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 interface ISession
        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 interface ISession
      • getNodeId

        public java.lang.String getNodeId()
        Description copied from interface: ISession
        Return the node Id in a cluster
        Specified by:
        getNodeId in interface ISession
        Returns:
        the node Id in a cluster
      • getProperty

        public java.lang.Object getProperty​(java.lang.String key)
        Specified by:
        getProperty in interface ISession
      • removeProperty

        public void removeProperty​(java.lang.String key)
        Specified by:
        removeProperty in interface ISession
      • 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
      • getSystemProperty

        public java.lang.Object getSystemProperty​(java.lang.String key)
        Specified by:
        getSystemProperty in interface ISession
      • removeSystemProperty

        public void removeSystemProperty​(java.lang.String key)
        Specified by:
        removeSystemProperty in interface ISession
      • 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
      • 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.
      • setConnected

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

        public void setLoggedIn​(boolean value)
        Specified by:
        setLoggedIn in interface ISession
      • 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.
      • 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)
      • isLocal

        public boolean isLocal()
        Description copied from interface: ISession
        See if the Session is local or hosted in another cluster node.
        Specified by:
        isLocal in interface ISession
        Returns:
        true if the session is local.
      • isIdle

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

        public void setConnection​(java.nio.channels.SocketChannel connection)
        Specified by:
        setConnection in interface ISession
      • setPacketQueue

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

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

        public void setHashId​(java.lang.String hash)
        Specified by:
        setHashId in interface ISession
      • setId

        public void setId​(int id)
        Specified by:
        setId in interface ISession
      • setLastReadTime

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

        public void setLastWriteTime​(long timestamp)
        Specified by:
        setLastWriteTime in interface ISession
      • setMaxIdleTime

        public void setMaxIdleTime​(int idleTime)
        Specified by:
        setMaxIdleTime in interface ISession
      • setNodeId

        public void setNodeId​(java.lang.String nodeId)
        Specified by:
        setNodeId in interface ISession
      • setProperty

        public void setProperty​(java.lang.String key,
                                java.lang.Object property)
        Specified by:
        setProperty in interface ISession
      • setSystemProperty

        public void setSystemProperty​(java.lang.String key,
                                      java.lang.Object property)
        Specified by:
        setSystemProperty in interface ISession
      • getDroppedMessages

        public int getDroppedMessages()
        Description copied from interface: ISession
        The number of messages that were dropped since the connection
        Specified by:
        getDroppedMessages in interface ISession
        Returns:
        the number of messages that were dropped since the connection
      • getSessionManager

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

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

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

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

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

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

        public java.lang.Object getCryptoKey()
        Specified by:
        getCryptoKey in interface ISession
      • setCryptoKey

        public void setCryptoKey​(java.lang.Object key)
        Specified by:
        setCryptoKey in interface ISession
      • toString

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

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object