Class FSPsession

  • All Implemented Interfaces:

    
    public class FSPsession
    
                        

    This class represents one live FSP session.

    FSPsession class takes care about FSP session management. It handles packet resends on timeouts and key management. It also handles locks for synchronizing multi session access to same FSP server.

    Since:

    1.0

    Author:

    Radim Kolar

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      int getTimeout() Get timeout value used by session.
      void setTimeout(int timeout) Set FSP session timeout value.
      int getDelay() Gets the delay time before we resent packet for first time.
      void setDelay(int delay) Sets the retransmit delay.
      int getPort() Get FSP port.
      InetAddress getHost() Get FSP host.
      FSPpacket interact(byte cmd, long filepos, Array<byte> data1, int offset1, int length1, Array<byte> data2, int offset2, int length2) Sends FSP packet and waits for reply, packet is resent if lost.
      void close() Close a session.
      int getMaxDelay() Gets the maximum delay time between packet resents.
      void setMaxDelay(int maxdelay) Sets the maximum delay time between resent packets.
      void finalize() closes session before doing GC.
      void lockWriter(Object lock, boolean wait) Set Writer lock.
      void unlockWriter(Object lock) Release Writer lock.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • FSPsession

        FSPsession(String host, int port)

        Creates a new FSP session

        Parameters:
        host - hostname of fsp server
        port - port number on fsp server
      • FSPsession

        FSPsession(InetAddress host, int port)

        Creates a new FSP session

        Parameters:
        host - address of fsp server
        port - port number on fsp server
    • Method Detail

      • getTimeout

         int getTimeout()

        Get timeout value used by session.

        Returns:

        timeout value in milliseconds. 0 means infinite timeout

        Since:

        1.0

      • setTimeout

         void setTimeout(int timeout)

        Set FSP session timeout value.

        If no packet from server is received in this time, session will time out.

        Parameters:
        timeout - timeout value in milliseconds.
        Since:

        1.0

      • getDelay

         int getDelay()

        Gets the delay time before we resent packet for first time.

        Returns:

        delay in milliseconds

        Since:

        1.0

      • setDelay

         void setDelay(int delay)

        Sets the retransmit delay.

        This functions sets delay parameter of FSP protocol stack. This is timeout value for first packet. If packet is lost delay is multiplied by 1.5. Delay is in milliseconds and must be between MIN_DELAY and MAX_DELAY

        Parameters:
        delay - new delay in milliseconds
        Since:

        1.0

      • getPort

         int getPort()

        Get FSP port.

        Get port of connected FSP server.

        Returns:

        port of connected FSP Server or zero if session is closed

        Since:

        1.0rc7

      • getHost

         InetAddress getHost()

        Get FSP host.

        Get InetAddress of FSP server we are connected to.

        Returns:

        InetAddress of connected FSP server or null if session is closed.

        Since:

        1.0rc7

      • interact

         FSPpacket interact(byte cmd, long filepos, Array<byte> data1, int offset1, int length1, Array<byte> data2, int offset2, int length2)

        Sends FSP packet and waits for reply, packet is resent if lost.

        Parameters:
        cmd - FSP command to be sent to server
        filepos - position in file
        data1 - array contains data for FSP packet
        offset1 - starting offset of data in array
        length1 - length of data
        data2 - array with extra data
        offset2 - starting offset of data in array
        length2 - length of extra data
        Returns:

        Received valid packet

        Since:

        1.0

      • close

         void close()

        Close a session.

        Session object can't be used after session is closed. Closing session also sends CC_BYE command to server.

        Since:

        1.0

      • getMaxDelay

         int getMaxDelay()

        Gets the maximum delay time between packet resents.

        Returns:

        max delay in milliseconds

        Since:

        1.0

      • setMaxDelay

         void setMaxDelay(int maxdelay)

        Sets the maximum delay time between resent packets.

        Since:

        1.0

      • finalize

         void finalize()

        closes session before doing GC.

        If session is not closed, close it before doing GC on this object. Timeout is set to 7 sec when doing it.

        Since:

        1.0

      • lockWriter

         void lockWriter(Object lock, boolean wait)

        Set Writer lock. FSP protocol supports only one writer per session. If you need more writers you need to open more sessions to target server. For synchronization purposes before starting write operation you have to call lockWriter.

        Parameters:
        lock - object writing to FSP session
        wait - wait if we can't acquire lock right now
        Since:

        1.0rc8

      • unlockWriter

         void unlockWriter(Object lock)

        Release Writer lock. After you are done writing data to FSP server you have to call this function for writer lock release. Failure to call this function will leave other threads waiting.

        Parameters:
        lock - object writing to fsp session
        Since:

        1.0rc8