Package edu.sc.seis.seisFile.seedlink
Class SeedlinkReader
java.lang.Object
edu.sc.seis.seisFile.seedlink.SeedlinkReader
public class SeedlinkReader
extends java.lang.Object
Reader for the seedlink protocol in multistation mode. Protocol documentation can be found at
https://www.seiscomp.de/seiscomp3/doc/applications/seedlink.html
Note this implementatino assumes multistation mode. It may be possible to use this in single station mode, but
this has not been tested.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
DATA_COMMAND
static java.lang.String
DATA_TYPE
static java.lang.String
DEFAULT_HOST
static int
DEFAULT_PORT
static int
DEFAULT_TIMEOUT_SECOND
static java.lang.String
EMPTY
static java.lang.String
INFO_ALL
static java.lang.String
INFO_CAPABILITIES
static java.lang.String
INFO_CONNECTIONS
static java.lang.String
INFO_GAPS
static java.lang.String
INFO_ID
static java.lang.String
INFO_STATIONS
static java.lang.String
INFO_STREAMS
java.lang.String
lastSeqNum
static java.lang.String
TIME_COMMAND
-
Constructor Summary
Constructors Constructor Description SeedlinkReader()
default of IRIS DMCSeedlinkReader(java.lang.String host)
uses the default port of 18000SeedlinkReader(java.lang.String host, int port)
SeedlinkReader(java.lang.String host, int port, int timeoutSeconds)
SeedlinkReader(java.lang.String host, int port, int timeoutSeconds, boolean verbose)
-
Method Summary
Modifier and Type Method Description boolean
available()
true if there is enough data in the instream to possibly read a data record.int
availableBytes()
Returns available() from the underlying InputStream, in bytesvoid
close()
void
endHandshake()
java.lang.String
getHost()
java.lang.String
getInfoString()
Get the SeedLink information string for streams.java.lang.String
getInfoString(java.lang.String infoType)
Get the SeedLink information string.java.lang.String
getInfoString(java.lang.String infoType, boolean addNewlines)
Get the SeedLink information string.int
getPort()
java.io.PrintWriter
getVerboseWriter()
boolean
hasNext()
Determine if a packet may be available.void
info(java.lang.String level)
send an INFO command.protected void
internalSendCmd(java.lang.String cmd)
boolean
isConnected()
boolean
isVerbose()
SeedlinkPacket
next()
Get the next packet.protected java.lang.String
readLine()
SeedlinkPacket
readPacket()
Read the next packet.void
reconnect()
Does a simple reconnect, replaying the original commands and restarting data.void
restartData(java.lang.String seqNum)
void
resume()
Resumes the connection at the last successful packet using the sequence number.void
select(java.lang.String network, java.lang.String station, java.lang.String location, java.lang.String channel)
Select the stream.void
select(java.lang.String network, java.lang.String station, java.lang.String location, java.lang.String channel, java.lang.String type)
Utility function to select the stream.void
sendCmd(java.lang.String cmd)
Sends a SeedLink modifier command, generally should be limited to STATION, SELECT, FETCH, DATA and TIME.java.lang.String[]
sendHello()
void
sendSelect(java.lang.String locationChannel)
Send a SELECT command for the given location-channel and with type of 'D'.void
sendSelect(java.lang.String locationChannel, java.lang.String type)
Send a SELECT command for the given location-channel and type.void
sendStation(java.lang.String network, java.lang.String station)
Send a STATION command for the given network and station.void
setVerbose(boolean verbose)
void
setVerboseWriter(java.io.PrintWriter verboseWriter)
void
startData()
Start the data transfer.void
startData(java.lang.String start, java.lang.String end)
Start the data transfer.void
startData(java.time.Instant start, java.time.Instant end)
Start the data transfer.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
lastSeqNum
public java.lang.String lastSeqNum -
EMPTY
public static final java.lang.String EMPTY- See Also:
- Constant Field Values
-
DATA_TYPE
public static final java.lang.String DATA_TYPE- See Also:
- Constant Field Values
-
DATA_COMMAND
public static final java.lang.String DATA_COMMAND- See Also:
- Constant Field Values
-
TIME_COMMAND
public static final java.lang.String TIME_COMMAND- See Also:
- Constant Field Values
-
DEFAULT_HOST
public static final java.lang.String DEFAULT_HOST- See Also:
- Constant Field Values
-
DEFAULT_PORT
public static final int DEFAULT_PORT- See Also:
- Constant Field Values
-
DEFAULT_TIMEOUT_SECOND
public static final int DEFAULT_TIMEOUT_SECOND- See Also:
- Constant Field Values
-
INFO_ID
public static final java.lang.String INFO_ID- See Also:
- Constant Field Values
-
INFO_CAPABILITIES
public static final java.lang.String INFO_CAPABILITIES- See Also:
- Constant Field Values
-
INFO_STATIONS
public static final java.lang.String INFO_STATIONS- See Also:
- Constant Field Values
-
INFO_STREAMS
public static final java.lang.String INFO_STREAMS- See Also:
- Constant Field Values
-
INFO_GAPS
public static final java.lang.String INFO_GAPS- See Also:
- Constant Field Values
-
INFO_CONNECTIONS
public static final java.lang.String INFO_CONNECTIONS- See Also:
- Constant Field Values
-
INFO_ALL
public static final java.lang.String INFO_ALL- See Also:
- Constant Field Values
-
-
Constructor Details
-
SeedlinkReader
public SeedlinkReader() throws java.net.UnknownHostException, java.io.IOExceptiondefault of IRIS DMC- Throws:
java.net.UnknownHostException
java.io.IOException
-
SeedlinkReader
public SeedlinkReader(java.lang.String host) throws java.net.UnknownHostException, java.io.IOExceptionuses the default port of 18000- Throws:
java.net.UnknownHostException
java.io.IOException
-
SeedlinkReader
public SeedlinkReader(java.lang.String host, int port) throws java.net.UnknownHostException, java.io.IOException- Throws:
java.net.UnknownHostException
java.io.IOException
-
SeedlinkReader
public SeedlinkReader(java.lang.String host, int port, int timeoutSeconds) throws java.net.UnknownHostException, java.io.IOException- Throws:
java.net.UnknownHostException
java.io.IOException
-
SeedlinkReader
public SeedlinkReader(java.lang.String host, int port, int timeoutSeconds, boolean verbose) throws java.net.UnknownHostException, java.io.IOException- Throws:
java.net.UnknownHostException
java.io.IOException
-
-
Method Details
-
hasNext
public boolean hasNext() throws java.io.IOExceptionDetermine if a packet may be available. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.- Returns:
- true if a packet may be available, false if end was received.
- Throws:
java.io.IOException
- if an I/O Exception occurs.- See Also:
readPacket()
-
available
public boolean available() throws java.io.IOExceptiontrue if there is enough data in the instream to possibly read a data record. This should not block, unlike hasNext() and next().- Throws:
java.io.IOException
-
availableBytes
public int availableBytes() throws java.io.IOExceptionReturns available() from the underlying InputStream, in bytes- Throws:
java.io.IOException
-
getInfoString
public java.lang.String getInfoString() throws java.io.IOException, SeedlinkException, SeedFormatExceptionGet the SeedLink information string for streams.- Returns:
- the SeedLink information string.
- Throws:
java.io.IOException
- if an I/O Exception occurs.SeedlinkException
- if no packets or there is an error creating the packet.SeedFormatException
- if there is an error with the SEED format.
-
getInfoString
public java.lang.String getInfoString(java.lang.String infoType) throws java.io.IOException, SeedlinkException, SeedFormatExceptionGet the SeedLink information string.- Parameters:
infoType
- the information type.- Returns:
- the SeedLink information string.
- Throws:
java.io.IOException
- if an I/O Exception occurs.SeedlinkException
- if no packets or there is an error creating the packet.SeedFormatException
- if there is an error with the SEED format.
-
getInfoString
public java.lang.String getInfoString(java.lang.String infoType, boolean addNewlines) throws java.io.IOException, SeedlinkException, SeedFormatExceptionGet the SeedLink information string.- Parameters:
infoType
- the information type.addNewlines
- true to add newlines to support XML parsing, false otherwise.- Returns:
- the SeedLink information string.
- Throws:
java.io.IOException
- if an I/O Exception occurs.SeedlinkException
- if no packets or there is an error creating the packet.SeedFormatException
- if there is an error with the SEED format.
-
next
Get the next packet. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.- Returns:
- the packet or null if none.
- Throws:
java.io.IOException
- if an I/O Exception occurs.SeedlinkException
- if no packets or there is an error creating the packet.- See Also:
hasNext()
,readPacket()
-
readPacket
Read the next packet. This method should be called after calling the 'hasNext' method. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.- Returns:
- the next packet.
- Throws:
java.io.IOException
- if an I/O Exception occurs.SeedlinkException
- if there is an error creating the packet.- See Also:
hasNext()
-
info
public void info(java.lang.String level) throws java.io.IOExceptionsend an INFO command. The resulting packets can be retrieved with calls to next(), although it seems there is no good way to determine how many packets will be returned or when they have all arrived without parsing the xml. This appears to be a shortcoming of the seedlink protocol. INFO requests should probably not be sent after the end of the handshake as real data packets may arrive causing confusion.- Throws:
java.io.IOException
-
endHandshake
public void endHandshake() throws java.io.IOException- Throws:
java.io.IOException
-
close
public void close() -
isConnected
public boolean isConnected() -
reconnect
Does a simple reconnect, replaying the original commands and restarting data. This does not resume from the last packet, so data may be lost that arrived during the outage. See resume to reconnect and resume data flow from the last successful packet.- Throws:
java.io.IOException
SeedlinkException
-
resume
Resumes the connection at the last successful packet using the sequence number.- Throws:
java.io.IOException
SeedlinkException
-
sendHello
- Throws:
java.io.IOException
SeedlinkException
-
readLine
- Throws:
java.io.IOException
SeedlinkException
-
sendCmd
Sends a SeedLink modifier command, generally should be limited to STATION, SELECT, FETCH, DATA and TIME.- Parameters:
cmd
- the command.- Throws:
SeedlinkException
- if a SeedLink error occurs.java.io.IOException
- if an I/O Exception occurs.
-
select
public void select(java.lang.String network, java.lang.String station, java.lang.String location, java.lang.String channel) throws SeedlinkException, java.io.IOExceptionSelect the stream. This sends a STATION followed by a SELECT command.- Parameters:
network
- the network.station
- the station.location
- the location or empty if none.channel
- the channel.- Throws:
SeedlinkException
- if a SeedLink error occurs.java.io.IOException
- if an I/O Exception occurs.
-
select
public void select(java.lang.String network, java.lang.String station, java.lang.String location, java.lang.String channel, java.lang.String type) throws SeedlinkException, java.io.IOExceptionUtility function to select the stream. This sends a STATION followed by a SELECT command.- Parameters:
network
- the network.station
- the station.location
- the location or empty if none.channel
- the channel.type
- the data type.- Throws:
SeedlinkException
java.io.IOException
-
sendStation
public void sendStation(java.lang.String network, java.lang.String station) throws SeedlinkException, java.io.IOExceptionSend a STATION command for the given network and station. If either is length zero, a wildcard of "*" is inserted in its place. In the Seedlink protocol, a STATION command should be followed by one or more SELECT commands. See sendSelect().- Parameters:
network
- the network.station
- the station.- Throws:
SeedlinkException
java.io.IOException
-
sendSelect
public void sendSelect(java.lang.String locationChannel) throws SeedlinkException, java.io.IOExceptionSend a SELECT command for the given location-channel and with type of 'D'. In the Seedlink protocol, a STATION command should be followed by one or more SELECT commands. See sendSelect().- Parameters:
locationChannel
- the combined location and channel, eg 00HHZ.- Throws:
SeedlinkException
java.io.IOException
-
sendSelect
public void sendSelect(java.lang.String locationChannel, java.lang.String type) throws SeedlinkException, java.io.IOExceptionSend a SELECT command for the given location-channel and type. In the Seedlink protocol, one or more SELECT commands should follow a STATION command. See sendStation().- Parameters:
locationChannel
- the combined location and channel, eg 00HHZ.type
- the data type.- Throws:
SeedlinkException
java.io.IOException
-
startData
Start the data transfer.- Throws:
SeedlinkException
- if a SeedLink error occurs.java.io.IOException
- if an I/O Exception occurs.
-
startData
public void startData(java.time.Instant start, java.time.Instant end) throws SeedlinkException, java.io.IOExceptionStart the data transfer. Note the DMC only goes back 48 hours. The start and end time format is year,month,day,hour,minute,second, e.g. '2002,08,05,14,00'.- Parameters:
start
- the start time or null if none.end
- the end time or null if none (ignored if no start time.)- Throws:
SeedlinkException
- if a SeedLink error occurs.java.io.IOException
- if an I/O Exception occurs.
-
startData
public void startData(java.lang.String start, java.lang.String end) throws SeedlinkException, java.io.IOExceptionStart the data transfer. Note the DMC only goes back 48 hours. The start and end time format is year,month,day,hour,minute,second, e.g. '2002,08,05,14,00'.- Parameters:
start
- the start time or empty string if none.end
- the end time or empty string if none (ignored if no start time.)- Throws:
SeedlinkException
- if a SeedLink error occurs.java.io.IOException
- if an I/O Exception occurs.
-
restartData
- Throws:
SeedlinkException
java.io.IOException
-
internalSendCmd
- Throws:
java.io.IOException
SeedlinkException
-
isVerbose
public boolean isVerbose() -
setVerbose
public void setVerbose(boolean verbose) -
getVerboseWriter
public java.io.PrintWriter getVerboseWriter() -
setVerboseWriter
public void setVerboseWriter(java.io.PrintWriter verboseWriter) -
getHost
public java.lang.String getHost() -
getPort
public int getPort()
-