Class FSPsession
-
- All Implemented Interfaces:
public class FSPsessionThis 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
Radim Kolar
-
-
Field Summary
Fields Modifier and Type Field Description public inttimeoutpublic intdelaypublic intportpublic InetAddresshostpublic final static intMIN_DELAYpublic final static intDEFAULT_DELAYpublic final static intMAX_DELAYpublic final static intDEFAULT_TIMEOUT
-
Constructor Summary
Constructors Constructor Description FSPsession(String host, int port)Creates a new FSP session FSPsession(InetAddress host, int port)Creates a new FSP session
-
Method Summary
Modifier and Type Method Description intgetTimeout()Get timeout value used by session. voidsetTimeout(int timeout)Set FSP session timeout value. intgetDelay()Gets the delay time before we resent packet for first time. voidsetDelay(int delay)Sets the retransmit delay. intgetPort()Get FSP port. InetAddressgetHost()Get FSP host. FSPpacketinteract(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. voidclose()Close a session. intgetMaxDelay()Gets the maximum delay time between packet resents. voidsetMaxDelay(int maxdelay)Sets the maximum delay time between resent packets. voidfinalize()closes session before doing GC. voidlockWriter(Object lock, boolean wait)Set Writer lock. voidunlockWriter(Object lock)Release Writer lock. -
-
Constructor Detail
-
FSPsession
FSPsession(String host, int port)
Creates a new FSP session
- Parameters:
host- hostname of fsp serverport- port number on fsp server
-
FSPsession
FSPsession(InetAddress host, int port)
Creates a new FSP session
- Parameters:
host- address of fsp serverport- 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 serverfilepos- position in filedata1- array contains data for FSP packetoffset1- starting offset of data in arraylength1- length of datadata2- array with extra dataoffset2- starting offset of data in arraylength2- 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 sessionwait- 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
-
-
-
-