Package edu.sc.seis.seisFile.seedlink
Class SeedlinkReader
java.lang.Object
edu.sc.seis.seisFile.seedlink.SeedlinkReader
Reader for the seedlink protocol in multistation mode. Protocol documentation can be found at
seedlink
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
FieldsModifier and TypeFieldDescriptionstatic final String
static final String
static final String
static final int
static final int
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
-
Constructor Summary
ConstructorsConstructorDescriptiondefault of IRIS DMCSeedlinkReader
(boolean verbose) default of IRIS DMCSeedlinkReader
(SeedlinkState state) SeedlinkReader
(SeedlinkState state, int timeoutSeconds, boolean verbose, int connectTimeoutSeconds) SeedlinkReader
(String host) uses the default port of 18000SeedlinkReader
(String host, boolean verbose) uses the default port of 18000SeedlinkReader
(String host, int port) SeedlinkReader
(String host, int port, boolean verbose) SeedlinkReader
(String host, int port, int timeoutSeconds) SeedlinkReader
(String host, int port, int timeoutSeconds, boolean verbose) SeedlinkReader
(String host, int port, int timeoutSeconds, boolean verbose, int connectTimeoutSeconds) -
Method Summary
Modifier and TypeMethodDescriptionboolean
true if there is enough data in the instream to possibly read a data record.int
Returns available() from the underlying InputStream, in bytesvoid
close()
static boolean
containsWildcard
(String cmd) static String
createResumeDataCommand
(String lastNet, String lastStation, SeedlinkState state) void
Ends the handshaking phase and starts data flowing.getHost()
Get the SeedLink information string for streams.getInfoString
(String infoType) Get the SeedLink information string.getInfoString
(String infoType, boolean addNewlines) Get the SeedLink information string.int
getPort()
getState()
SeedlinkState is a utility object to allow the client to keep track of the last sequence number for each station and the sequence of commands that affect data that were sent to the server.boolean
hasNext()
Determine if a packet may be available.void
send an INFO command.protected void
internalSendCmd
(String cmd) boolean
boolean
next()
Get the next packet.static String
protected String
readLine()
Read the next packet.void
Does a simple reconnect, replaying the original commands and restarting data.void
restartData
(String seqNum) Deprecated.use repeated selectData(String network, String station, List<String> locchan, int seqNum) followed by endHandshake()void
resume()
Deprecated.use resumeGlobalSequencestatic SeedlinkReader
resume
(SeedlinkState seedlinkState, boolean verbose) Resumes the connection at the last successful packet using the sequence number.static SeedlinkReader
resumeGlobalSequence
(SeedlinkState seedlinkState) static SeedlinkReader
resumeGlobalSequence
(SeedlinkState seedlinkState, boolean verbose) Resumes the connection at the last successful packet using the global last sequence number.void
Deprecated.use selectData() or selectTime() insteadvoid
Deprecated.use selectData() or selectTime() insteadvoid
selectData
(String network, String station, List<String> locchan) void
void
void
void
void
void
Deprecated.use selectData() or selectTime() insteadvoid
void
void
selectTimeOfType
(String network, String station, List<String> locchan, Instant start, Instant end, String type) void
Sends a SeedLink modifier command, generally should be limited to STATION, SELECT, FETCH, DATA and TIME.void
sendData()
void
void
void
String[]
void
sendSelect
(String locationChannel) Send a SELECT command for the given location-channel and with type of 'D'.void
sendSelect
(String locationChannel, String type) Send a SELECT command for the given location-channel and type.void
sendStation
(String network, String station) Send a STATION command for the given network and station.void
void
void
setVerbose
(boolean verbose) void
setVerboseWriter
(PrintWriter verboseWriter) void
Deprecated.use repeated selectData() or selectTime() followed by endHandshake()void
Deprecated.use repeated selectData() followed by endHandshake()void
Deprecated.use repeated selectTime() followed by endHandshake()
-
Field Details
-
lastSeqNum
-
EMPTY
- See Also:
-
DATA_TYPE
- See Also:
-
DATA_COMMAND
- See Also:
-
TIME_COMMAND
- See Also:
-
DEFAULT_HOST
- See Also:
-
DEFAULT_PORT
public static final int DEFAULT_PORT- See Also:
-
DEFAULT_TIMEOUT_SECOND
public static final int DEFAULT_TIMEOUT_SECOND- See Also:
-
INFO_ID
- See Also:
-
INFO_CAPABILITIES
- See Also:
-
INFO_STATIONS
- See Also:
-
INFO_STREAMS
- See Also:
-
INFO_GAPS
- See Also:
-
INFO_CONNECTIONS
- See Also:
-
INFO_ALL
- See Also:
-
-
Constructor Details
-
SeedlinkReader
default of IRIS DMC- Throws:
IOException
-
SeedlinkReader
default of IRIS DMC- Throws:
IOException
-
SeedlinkReader
uses the default port of 18000- Throws:
IOException
-
SeedlinkReader
uses the default port of 18000- Throws:
IOException
-
SeedlinkReader
- Throws:
IOException
-
SeedlinkReader
- Throws:
IOException
-
SeedlinkReader
- Throws:
IOException
-
SeedlinkReader
public SeedlinkReader(String host, int port, int timeoutSeconds, boolean verbose) throws IOException - Throws:
IOException
-
SeedlinkReader
public SeedlinkReader(String host, int port, int timeoutSeconds, boolean verbose, int connectTimeoutSeconds) throws IOException - Throws:
IOException
-
SeedlinkReader
-
SeedlinkReader
public SeedlinkReader(SeedlinkState state, int timeoutSeconds, boolean verbose, int connectTimeoutSeconds)
-
-
Method Details
-
hasNext
Determine 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:
IOException
- if an I/O Exception occurs.- See Also:
-
available
true if there is enough data in the instream to possibly read a data record. This should not block, unlike hasNext() and next().- Throws:
IOException
-
availableBytes
Returns available() from the underlying InputStream, in bytes- Throws:
IOException
-
getInfoString
Get the SeedLink information string for streams.- Returns:
- the SeedLink information string or null if error.
- Throws:
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 String getInfoString(String infoType) throws IOException, SeedlinkException, SeedFormatException Get the SeedLink information string.- Parameters:
infoType
- the information type.- Returns:
- the SeedLink information string or null if error.
- Throws:
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 String getInfoString(String infoType, boolean addNewlines) throws IOException, SeedlinkException, SeedFormatException Get 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 or null if error.
- Throws:
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:
IOException
- if an I/O Exception occurs.SeedlinkException
- if no packets or there is an error creating the packet.- See Also:
-
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:
IOException
- if an I/O Exception occurs.SeedlinkException
- if there is an error creating the packet.- See Also:
-
info
send an INFO command. The resulting packets can be retrieved with calls to next(), checking isInfoContinuesPacket() to see if more packets will be returned. INFO requests should probably not be sent after the end of the handshake as real data packets may arrive causing confusion. GetInfoString() is preferred as it iterates over all returned packets and returns the result as a single String.- Throws:
IOException
-
endHandshake
Ends the handshaking phase and starts data flowing.- Throws:
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:
IOException
SeedlinkException
-
resume
Deprecated.use resumeGlobalSequenceResumes the connection at the last successful packet using the global last sequence number. Note that this assumes that sequence numbers are global, not per station. Each DATA or TIME command in the original command sequence is replaced with 'DATA seq' to restart with the last received sequence number. If the server uses per station sequence numbering then the client must keep track of sequence numbers and use resume(SeedlinkState) to supply the sequence numbers.- Throws:
IOException
SeedlinkException
-
resumeGlobalSequence
public static SeedlinkReader resumeGlobalSequence(SeedlinkState seedlinkState) throws IOException, SeedlinkException - Throws:
IOException
SeedlinkException
-
resumeGlobalSequence
public static SeedlinkReader resumeGlobalSequence(SeedlinkState seedlinkState, boolean verbose) throws IOException, SeedlinkException Resumes the connection at the last successful packet using the global last sequence number. Note that this assumes that sequence numbers are global, not per station. Each DATA or TIME command in the original command sequence is replaced with 'DATA seq' to restart with the last received sequence number, which should work with wildcards.. If the server uses per station sequence numbering then the client must keep track of sequence numbers and use resume(SeedlinkState) to supply the sequence numbers, possibly with custom commands to handle wildcards.- Throws:
IOException
SeedlinkException
-
resume
public static SeedlinkReader resume(SeedlinkState seedlinkState, boolean verbose) throws IOException, SeedlinkException Resumes the connection at the last successful packet using the sequence number. Note that this uses a supplied per station last seq number. The map key is of the form NN.SSSSS where NN is the network code and SSSSS is the station code. It is also assumed that there is a DATA or TIME command in the original handshaking phase after each STATION command. Some servers allow multiple STATION commands before a DATA command, but this breaks restarting each station at the last sequence. The caller should call endHandshake() after creationg in order to begin data flow. This does not function correctly if wildcards have been used in the original request as there is no guarantee that all stations/channels that might match the wildcards have actually been seen before the interruption, and so the wildcard commands may need to be repeated. Resuming after STATION comamnds with wildcards should be handled externally by the client.- Throws:
IOException
SeedlinkException
-
createResumeDataCommand
public static String createResumeDataCommand(String lastNet, String lastStation, SeedlinkState state) -
nextSeq
-
containsWildcard
-
sendHello
- Throws:
IOException
SeedlinkException
-
readLine
- Throws:
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.IOException
- if an I/O Exception occurs.
-
select
@Deprecated public void select(String network, String station, String location, String channel) throws SeedlinkException, IOException Deprecated.use selectData() or selectTime() insteadSelect 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.IOException
- if an I/O Exception occurs.
-
selectData
public void selectData(String network, String station, List<String> locchan) throws SeedlinkException, IOException - Throws:
SeedlinkException
IOException
-
selectOfType
@Deprecated public void selectOfType(String network, String station, List<String> locchan, String type) throws SeedlinkException, IOException Deprecated.use selectData() or selectTime() insteadUtility function to select the stream. This sends a STATION followed by a SELECT command.- Parameters:
network
- the network.station
- the station.locchan
- list of location channel.type
- the data type.- Throws:
SeedlinkException
IOException
-
selectDataOfType
public void selectDataOfType(String network, String station, List<String> locchan, String type) throws SeedlinkException, IOException - Throws:
SeedlinkException
IOException
-
selectData
public void selectData(String network, String station, List<String> locchan, String seqNum) throws SeedlinkException, IOException - Throws:
SeedlinkException
IOException
-
selectDataOfType
public void selectDataOfType(String network, String station, List<String> locchan, String seqNum, String type) throws SeedlinkException, IOException - Throws:
SeedlinkException
IOException
-
selectData
public void selectData(String network, String station, List<String> locchan, Instant start) throws SeedlinkException, IOException - Throws:
SeedlinkException
IOException
-
selectDataOfType
public void selectDataOfType(String network, String station, List<String> locchan, Instant start, String type) throws SeedlinkException, IOException - Throws:
SeedlinkException
IOException
-
selectTime
public void selectTime(String network, String station, List<String> locchan, Instant start) throws SeedlinkException, IOException - Throws:
SeedlinkException
IOException
-
selectTime
public void selectTime(String network, String station, List<String> locchan, Instant start, Instant end) throws SeedlinkException, IOException - Throws:
SeedlinkException
IOException
-
selectTimeOfType
public void selectTimeOfType(String network, String station, List<String> locchan, Instant start, Instant end, String type) throws SeedlinkException, IOException - Throws:
SeedlinkException
IOException
-
select
@Deprecated public void select(String network, String station, String location, String channel, String type) throws SeedlinkException, IOException Deprecated.use selectData() or selectTime() insteadUtility 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
IOException
-
sendStation
Send 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
IOException
-
sendSelect
Send 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 sendStation().- Parameters:
locationChannel
- the combined location and channel, eg 00HHZ.- Throws:
SeedlinkException
IOException
-
sendSelect
Send 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
IOException
-
startData
Deprecated.use repeated selectData() or selectTime() followed by endHandshake()Start the data transfer.- Throws:
SeedlinkException
- if a SeedLink error occurs.IOException
- if an I/O Exception occurs.
-
startData
Deprecated.use repeated selectTime() followed by endHandshake()Start 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.IOException
- if an I/O Exception occurs.
-
startData
Deprecated.use repeated selectData() followed by endHandshake()Start 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.IOException
- if an I/O Exception occurs.
-
sendData
- Throws:
SeedlinkException
IOException
-
sendData
- Throws:
SeedlinkException
IOException
-
sendData
- Throws:
SeedlinkException
IOException
-
sendData
- Throws:
SeedlinkException
IOException
-
sendTime
- Throws:
SeedlinkException
IOException
-
sendTime
- Throws:
SeedlinkException
IOException
-
restartData
Deprecated.use repeated selectData(String network, String station, List<String> locchan, int seqNum) followed by endHandshake()- Parameters:
seqNum
-- Throws:
SeedlinkException
IOException
-
internalSendCmd
- Throws:
IOException
SeedlinkException
-
isVerbose
public boolean isVerbose() -
setVerbose
public void setVerbose(boolean verbose) -
getVerboseWriter
-
setVerboseWriter
-
getHost
-
getPort
public int getPort() -
getState
SeedlinkState is a utility object to allow the client to keep track of the last sequence number for each station and the sequence of commands that affect data that were sent to the server. SeedlinkReader does not automatically keep track of these per station sequence numbers as it requires parsing the miniseed records. Clients that desire this should call SeedlinkState.update(SeedlinkPacket) to update the per station sequence number.
-