public class FSPsession extends Object
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.
FSPpacket
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_DELAY
default resent delay (msec)
|
static int |
DEFAULT_TIMEOUT
default timeout (msec)
|
static int |
MAX_DELAY
maximum resent delay.
|
static int |
MIN_DELAY
minimum resent delay (msec)
|
Constructor and Description |
---|
FSPsession(InetAddress host,
int port)
Creates a new FSP session
|
FSPsession(String host,
int port)
Creates a new FSP session
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Close a session.
|
void |
finalize()
closes session before doing GC.
|
int |
getDelay()
Gets the delay time before we resent packet for first time.
|
InetAddress |
getHost()
Get FSP host.
|
int |
getMaxDelay()
Gets the maximum delay time between packet resents.
|
int |
getPort()
Get FSP port.
|
int |
getTimeout()
Get timeout value used by session.
|
FSPpacket |
interact(byte cmd,
long filepos,
byte[] data1,
int offset1,
int length1,
byte[] data2,
int offset2,
int length2)
Sends FSP packet and waits for reply, packet is resent if lost.
|
void |
lockWriter(Object lock,
boolean wait)
Set Writer lock.
|
void |
setDelay(int delay)
Sets the delay.
|
void |
setMaxDelay(int delay)
Sets the maximum delay time between resent packets.
|
void |
setTimeout(int timeout)
Set timeout value.
|
void |
unlockWriter(Object lock)
Release Writer lock.
|
public static final int MIN_DELAY
public static final int DEFAULT_DELAY
public static final int MAX_DELAY
public static final int DEFAULT_TIMEOUT
public FSPsession(String host, int port) throws SocketException, UnknownHostException
host
- hostname of fsp serverport
- port number on fsp serverSocketException
- if socket can not be createdUnknownHostException
- if hostname fails to resolvepublic FSPsession(InetAddress host, int port) throws SocketException
host
- address of fsp serverport
- port number on fsp serverSocketException
- if socket can not be createdpublic FSPpacket interact(byte cmd, long filepos, byte[] data1, int offset1, int length1, byte[] data2, int offset2, int length2) throws SocketTimeoutException
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 dataSocketTimeoutException
- if server can't be reached within timeoutpublic void close()
Session object can't be used after session is closed. This also sends CC_BYE command to server.
public int getDelay()
public void setDelay(int 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
delay
- new delay in millisecondspublic int getMaxDelay()
public void setMaxDelay(int delay)
delay
- new maximum delay time in milliseconds.public int getTimeout()
public void setTimeout(int timeout)
If no packet from server is received in this time, session will time out.
timeout
- timeout value in milliseconds. 0 means infinite timeoutpublic InetAddress getHost()
Get InetAddress of FSP server we are connected to.
public int getPort()
Get port of connected FSP server.
public void finalize()
If session is not closed, close it before doing GC on this object. Timeout is set to 7 sec when doing it.
public void lockWriter(Object lock, boolean wait)
lock
- object writing to FSP sessionwait
- wait if we can't acquire lock nowIllegalStateException
- if session is already write locked and
no wait was specifiedpublic void unlockWriter(Object lock)
lock
- object writing to fsp sessionIllegalStateException
- if lock is invalidCopyright © 2020 FSP Project. All rights reserved.