public class SeedLinkConnection
extends java.lang.Object
SLClient
,
Socket
Modifier and Type | Field and Description |
---|---|
protected java.lang.String |
begin_time
Beginning of time window.
|
protected static int |
DFT_READBUF_SIZE
Default size for buffer to hold responses from server.
|
protected boolean |
dialup
Flag to indicate dial-up mode.
|
protected java.lang.String |
end_time
End of time window.
|
protected java.lang.String |
infoRequestString
INFO level to request.
|
protected java.lang.StringBuffer |
infoStrBuf
String to store INFO packet contents.
|
protected java.lang.String |
infoString
String containing concatination of contents of last terminated set of INFO packets
|
protected int |
keepalive
Interval to send keepalive/heartbeat (seconds).
|
protected boolean |
lastpkttime
Flag to control last packet time usage.
|
protected boolean |
multistation
Flag to indicate multistation mode.
|
protected int |
netdly
Network reconnect delay (seconds).
|
protected int |
netto
Network timeout (seconds).
|
protected static char |
QUOTE_CHAR
Character used for delimiting timestamp strings in the statefile.
|
protected boolean |
resume
Flag to control resuming with sequence numbers.
|
static java.lang.String |
SEEDLINK_PROTOCOL_PREFIX
URI/URL prefix for seedlink servers ("seedlnk://")
|
protected java.lang.String |
server_id
ID of the remote SeedLink server.
|
protected float |
server_version
Version of the remote SeedLink server
|
protected java.lang.String |
sladdr
The host:port of the SeedLink server.
|
protected SLLog |
sllog
Logging object.
|
protected java.net.Socket |
socket
The network socket.
|
protected java.io.InputStream |
socketInputStream
The network socket InputStream.
|
protected java.io.OutputStream |
socketOutputStream
The network socket OutputStream.
|
protected SLState |
state
Persistent state information.
|
protected java.lang.String |
statefile
File name for storing state information.
|
protected java.util.Vector |
streams
Vector of SLNetStation objects.
|
protected boolean |
terminateFlag
Flag to control connection termination.
|
protected static java.lang.String |
UNINETWORK
The network code used for uni-station mode
|
protected static java.lang.String |
UNISTATION
The station code used for uni-station mode
|
static java.nio.charset.Charset |
UTF_8
UTF-8
|
Constructor and Description |
---|
SeedLinkConnection(SLLog sllog)
Creates a new instance of SeedLinkConnection.
|
Modifier and Type | Method and Description |
---|---|
protected int |
addStream(java.lang.String net,
java.lang.String station,
java.lang.String selectors,
int seqnum,
java.lang.String timestamp)
Add a new stream entry to the stream chain for the given net/station parameters.
|
protected void |
appendInfoString(SLPacket slpacket)
Append the info String to the String Buffer.
|
protected boolean |
checkslcd()
Check this SeedLinkConnection description has valid parameters.
|
int |
checkVersion(float version)
Checks server version number against a given specified value.
|
void |
close()
Closes this SeedLinkConnection by closing the network socket and saving the state to the statefile, if it exists.
|
SLPacket |
collect()
Manage a connection to a SeedLink server based on the values given in this SeedLinkConnection, and to collect data.
|
void |
configLink()
Configure/negotiate data stream(s) with the remote SeedLink server.
|
void |
connect()
Open a network socket connection to a SeedLink server.
|
protected java.lang.String |
createInfoString(java.lang.StringBuffer strBuf)
Creates an info String from a String Buffer
|
void |
disconnect()
Close the network socket associated with this connection.
|
protected SLPacket |
doTerminate() |
static java.nio.charset.Charset |
getCharset(java.lang.String charsetName,
java.nio.charset.Charset defaultCharset)
Get the character set.
|
java.lang.String |
getInfoString()
Returns the results of the last INFO request.
|
protected int |
getInteger(edu.iris.Fissures.seed.container.Blockette blockette,
int fieldNum)
Get the integer value from the specified blockette field.
|
int |
getKeepAlive()
Returns the interval to send keepalive/heartbeat (seconds).
|
SLLog |
getLog()
Returns the SLLog logging object.
|
int |
getNetDelay()
Returns the network reconnect delay (seconds).
|
int |
getNetTimout()
Returns the network timeout (seconds).
|
java.lang.String |
getSLAddress()
Returns the host:port of the SeedLink server.
|
SLState |
getState()
Returns the SLState state object.
|
java.util.Vector |
getStreams()
Returns a copy of the Vector of SLNetStation objects.
|
static java.lang.String |
getString(byte[] bytes)
Get the string from the XML bytes.
|
boolean |
isConnected()
Returns connection state of the connection socket.
|
void |
negotiateMultiStation()
Negotiate a SeedLink connection using multi-station mode and issue the END action command.
|
void |
negotiateStation(SLNetStation curstream)
Negotiate a SeedLink connection for a single station and issue the DATA command.
|
void |
negotiateUniStation()
Negotiate a SeedLink connection in uni-station mode and issue the DATA command.
|
int |
parseStreamlist(java.lang.String streamlist,
java.lang.String defselect)
Parse a string of streams and selectors and add them to the stream chain for configuring a multi-station connection.
|
int |
readStreamList(java.lang.String streamfile,
java.lang.String defselect)
Read a list of streams and selectors from a file and add them to the stream chain for configuring a multi-station connection.
|
byte[] |
receiveData(int maxbytes,
java.lang.String code)
Read bytes from the server.
|
int |
recoverState(java.lang.String statefile)
Recover the state file and put the sequence numbers and time stamps into the pre-existing stream chain entries.
|
void |
requestInfo(java.lang.String infoLevel)
Add an INFO request to the SeedLink Connection Description.
|
int |
saveState(java.lang.String statefile)
Save all current s equence numbers and time stamps into the given state file.
|
void |
sayHello()
Send the HELLO command and attempt to parse the server version number from the returned string.
|
byte[] |
sendData(byte[] sendbytes,
java.lang.String code,
int resplen)
Send bytes to the server.
|
void |
sendInfoRequest(java.lang.String infoLevel,
int verb_level)
Sends a request for the specified INFO level.
|
void |
setBeginTime(java.lang.String startTimeStr)
Sets begin_time for initiation of continuous data transmission.
|
void |
setEndTime(java.lang.String endTimeStr)
Sets end_time for termitiation of data transmission.
|
void |
setKeepAlive(int keepalive)
Sets interval to send keepalive/heartbeat (seconds).
|
void |
setLastpkttime(boolean lastpkttime)
Sets a specified start time for beginning of data transmission .
|
void |
setLog(SLLog sllog)
Sets the SLLog logging object.
|
void |
setNetDelay(int netdly)
Sets the network reconnect delay (seconds).
|
void |
setNetTimout(int netto)
Sets the network timeout (seconds).
|
void |
setSLAddress(java.lang.String sladdr)
Sets the host:port of the SeedLink server.
|
int |
setStateFile(java.lang.String statefile)
Set the state file and recover state.
|
void |
setUniParams(java.lang.String selectors,
int seqnum,
java.lang.String timestamp)
Set the parameters for a uni-station mode connection for the given SLCD struct.
|
void |
terminate()
Sets terminate flag, closes connection and clears state as soon as possible
|
void |
updateStream(SLPacket slpacket)
Update the appropriate stream chain entry given a Mini-SEED record.
|
public static final java.nio.charset.Charset UTF_8
public static final java.lang.String SEEDLINK_PROTOCOL_PREFIX
protected static final java.lang.String UNISTATION
protected static final java.lang.String UNINETWORK
protected static final int DFT_READBUF_SIZE
protected static char QUOTE_CHAR
protected java.lang.String sladdr
protected int keepalive
protected int netto
protected int netdly
protected SLLog sllog
protected java.lang.String infoString
protected java.lang.String statefile
protected boolean lastpkttime
protected java.util.Vector streams
protected java.lang.String begin_time
protected java.lang.String end_time
protected boolean resume
protected boolean multistation
protected boolean dialup
protected boolean terminateFlag
protected java.lang.String server_id
protected float server_version
protected java.lang.String infoRequestString
protected java.net.Socket socket
protected java.io.InputStream socketInputStream
protected java.io.OutputStream socketOutputStream
protected SLState state
protected java.lang.StringBuffer infoStrBuf
public SeedLinkConnection(SLLog sllog)
sllog
- an SLLoc object to control info and error message logging.public static java.nio.charset.Charset getCharset(java.lang.String charsetName, java.nio.charset.Charset defaultCharset)
charsetName
- the character set name.defaultCharset
- the default character set or null for the default character set of this Java virtual machine.public static java.lang.String getString(byte[] bytes)
bytes
- the XML bytes.public boolean isConnected()
public SLState getState()
public void setLog(SLLog sllog)
sllog
- an SLLoc object to control info and error message logging.public SLLog getLog()
public void setNetTimout(int netto)
netto
- the network timeout in seconds.public int getNetTimout()
public void setKeepAlive(int keepalive)
keepalive
- the interval to send keepalive/heartbeat in seconds.public int getKeepAlive()
public void setNetDelay(int netdly)
netdly
- the network reconnect delay in seconds.public int getNetDelay()
public void setSLAddress(java.lang.String sladdr)
sladdr
- the host:port of the SeedLink server.public void setLastpkttime(boolean lastpkttime)
if
- true, beginning time of last packet recieved for each station is appended to DATA command on resume.public void setBeginTime(java.lang.String startTimeStr)
startTimeStr
- start time in in SeedLink string format: "year,month,day,hour,minute,second".public void setEndTime(java.lang.String endTimeStr)
endTimeStr
- start time in in SeedLink string format: "year,month,day,hour,minute,second".public void terminate()
public java.lang.String getSLAddress()
public java.util.Vector getStreams()
public java.lang.String getInfoString()
protected java.lang.String createInfoString(java.lang.StringBuffer strBuf)
strBuf
- the buffer to convert to an INFO String.protected boolean checkslcd()
public int readStreamList(java.lang.String streamfile, java.lang.String defselect) throws SeedLinkException
For example:[selectors]
# Comment lines begin with a '#' or '*' GE ISP BH?.D NL HGN MN AQU BH? HH?
streamfile
- name of file containing list of streams and slectors.defselect
- default selectors.SeedLinkException
- on error.public int parseStreamlist(java.lang.String streamlist, java.lang.String defselect) throws SeedLinkException
"IU_KONO:BHE BHN,GE_WLF,MN_AQU:HH?.D"
streamlist
- list of streams and slectors.defselect
- default selectors.SeedLinkException
- on error.protected int addStream(java.lang.String net, java.lang.String station, java.lang.String selectors, int seqnum, java.lang.String timestamp) throws SeedLinkException
net
- network code.station
- station code.selectors
- selectors for this net/station, null if none.seqnum
- SeedLink sequence number of last packet received, -1 to start at the next data.timestamp
- SeedLink time stamp in SEED "year,day-of-year,hour,minute,second" format for last packet received, null for none.SeedLinkException
- on error.public void setUniParams(java.lang.String selectors, int seqnum, java.lang.String timestamp) throws SeedLinkException
selectors
- selectors for this net/station, null if none.seqnum
- SeedLink sequence number of last packet received, -1 to start at the next data.timestamp
- SeedLink time stamp in SEED "year,day-of-year,hour,minute,second" format for last packet received, null for none.SeedLinkException
- on error.public int setStateFile(java.lang.String statefile) throws SeedLinkException
statefile
- path and name of statefile.SeedLinkException
- on error.public int recoverState(java.lang.String statefile) throws SeedLinkException
statefile
- path and name of statefile.SeedLinkException
- on error.public int saveState(java.lang.String statefile) throws SeedLinkException
statefile
- path and name of statefile.SeedLinkException
- on error.protected SLPacket doTerminate()
public SLPacket collect() throws SeedLinkException
SeedLinkException
- on error.protected void appendInfoString(SLPacket slpacket)
slpacket
- the SeedLink packet.protected int getInteger(edu.iris.Fissures.seed.container.Blockette blockette, int fieldNum) throws edu.iris.Fissures.seed.exception.SeedException
blockette
- the blockette.fieldNum
- the field number.edu.iris.Fissures.seed.exception.SeedException
- if error.public void connect() throws SeedLinkException, java.io.IOException
SeedLinkException
- on error or no response or bad response from server.java.io.IOException
- if an I/O error occurs.public void disconnect()
public void close()
public byte[] sendData(byte[] sendbytes, java.lang.String code, int resplen) throws SeedLinkException, java.io.IOException
sendbytes
- bytes to send.code
- a string to include in error messages for identification.resplen
- if > 0 then read up to resplen response bytes after sending.SeedLinkException
- on error or no response or bad response from server.java.io.IOException
- if an I/O error occurs.public byte[] receiveData(int maxbytes, java.lang.String code) throws java.io.IOException
maxbytes
- maximum number of bytes to read.code
- a string to include in error messages for identification.java.io.IOException
- if an I/O error occurs.public void sayHello() throws SeedLinkException, java.io.IOException
SeedLinkException
- on error.java.io.IOException
- if an I/O error occurs.public void requestInfo(java.lang.String infoLevel) throws SeedLinkException
infoLevel
- the INFO level (one of: ID, STATIONS, STREAMS, GAPS, CONNECTIONS, ALL)SeedLinkException
- if an INFO request is already pending.public void sendInfoRequest(java.lang.String infoLevel, int verb_level) throws SeedLinkException, java.io.IOException
infoLevel
- the INFO level (one of: ID, STATIONS, STREAMS, GAPS, CONNECTIONS, ALL).SeedLinkException
- on error.java.io.IOException
- if an I/O error occurs.public int checkVersion(float version)
version
- specified version value to test.public void configLink() throws SeedLinkException, java.io.IOException
SeedLinkException
- on error.SeedLinkException
- if multi-station and SeedLink version does not support multi-station protocol.java.io.IOException
public void negotiateStation(SLNetStation curstream) throws SeedLinkException, java.io.IOException
curstream
- the description of the station to negotiate.SeedLinkException
- on error.java.io.IOException
- if an I/O error occurs.public void negotiateUniStation() throws SeedLinkException, java.io.IOException
SeedLinkException
- on error.java.io.IOException
- if an I/O error occurs.public void negotiateMultiStation() throws SeedLinkException, java.io.IOException
SeedLinkException
- on error.java.io.IOException
- if an I/O error occurs.public void updateStream(SLPacket slpacket) throws SeedLinkException
slpacket
- the packet containing a Mini-SEED record.SeedLinkException
- on error.