Package edu.sc.seis.seisFile.datalink
Class DataLink
- java.lang.Object
-
- edu.sc.seis.seisFile.datalink.DataLink
-
public class DataLink extends java.lang.Object
Philip Crotwell University of South Carolina, 2019 http://www.seis.sc.edu
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
DATALINK_PROTOCOL
static java.lang.String
DEFAULT_HOST
static int
DEFAULT_PORT
static int
DEFAULT_TIMEOUT_SECOND
static java.lang.String
EEYORE_HOST
static int
EEYORE_PORT
static java.lang.String
ENDSTREAM
static java.lang.String
ERROR
static java.lang.String
ID
static java.lang.String
INFO
static java.lang.String
IRIS_HOST
static int
IRIS_PORT
static java.lang.String
MATCH
static int
MAX_PROC_NUM
static java.lang.String
MSEED_TYPE
static java.lang.String
OK
static java.lang.String
PACKET
static java.lang.String
QUERY_MODE
static java.lang.String
REJECT
static java.lang.String
STREAM
static java.lang.String
STREAM_MODE
static java.lang.String
USER_BROWSER
-
Constructor Summary
Constructors Constructor Description DataLink()
default of IRIS DMCDataLink(java.lang.String host)
uses the default port of 18000DataLink(java.lang.String host, int port)
Open DataLink socket connectionDataLink(java.lang.String host, int port, int timeoutSeconds)
Open DataLink socket connectionDataLink(java.lang.String host, int port, int timeoutSeconds, boolean verbose)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
available()
true if there is enough data in the instream to possibly read a data record.int
availableBytes()
DataLinkResponse
awaitDLCommand(java.lang.String command, java.lang.String dataString)
void
close()
Send end and close connection.byte[]
encodeDLCommand(java.lang.String command, java.lang.String dataString)
encodes command with optional data section as a string.void
endStream()
int
getClientIdNum()
java.lang.String
getHost()
int
getPort()
java.lang.String
getServerId()
java.lang.String
getUsername()
java.io.PrintWriter
getVerboseWriter()
boolean
isConnected()
boolean
isVerbose()
void
match(java.lang.String matchRegEx)
DataLinkResponse
readPacket()
Read a packet.void
reconnect()
Would be really nice to keep state and reconnect plus backfill, but...void
reject(java.lang.String rejectRegEx)
void
sendDLCommand(java.lang.String command, java.lang.String dataString)
Sends a DL Command and awaits the response, either OK or ERROR.void
sendId()
void
setVerbose(boolean verbose)
void
setVerboseWriter(java.io.PrintWriter verboseWriter)
void
stream()
void
verbose(java.lang.String message)
-
-
-
Field Detail
-
IRIS_HOST
public static final java.lang.String IRIS_HOST
- See Also:
- Constant Field Values
-
IRIS_PORT
public static final int IRIS_PORT
- See Also:
- Constant Field Values
-
EEYORE_HOST
public static final java.lang.String EEYORE_HOST
- See Also:
- Constant Field Values
-
EEYORE_PORT
public static final int EEYORE_PORT
- 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
-
DATALINK_PROTOCOL
public static final java.lang.String DATALINK_PROTOCOL
- See Also:
- Constant Field Values
-
QUERY_MODE
public static final java.lang.String QUERY_MODE
- See Also:
- Constant Field Values
-
STREAM_MODE
public static final java.lang.String STREAM_MODE
- See Also:
- Constant Field Values
-
MAX_PROC_NUM
public static final int MAX_PROC_NUM
- See Also:
- Constant Field Values
-
USER_BROWSER
public static final java.lang.String USER_BROWSER
- See Also:
- Constant Field Values
-
ID
public static final java.lang.String ID
- See Also:
- Constant Field Values
-
OK
public static final java.lang.String OK
- See Also:
- Constant Field Values
-
ERROR
public static final java.lang.String ERROR
- See Also:
- Constant Field Values
-
INFO
public static final java.lang.String INFO
- See Also:
- Constant Field Values
-
MATCH
public static final java.lang.String MATCH
- See Also:
- Constant Field Values
-
REJECT
public static final java.lang.String REJECT
- See Also:
- Constant Field Values
-
PACKET
public static final java.lang.String PACKET
- See Also:
- Constant Field Values
-
STREAM
public static final java.lang.String STREAM
- See Also:
- Constant Field Values
-
ENDSTREAM
public static final java.lang.String ENDSTREAM
- See Also:
- Constant Field Values
-
MSEED_TYPE
public static final java.lang.String MSEED_TYPE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
DataLink
public DataLink() throws DataLinkException
default of IRIS DMC- Throws:
DataLinkException
- if unable to connect
-
DataLink
public DataLink(java.lang.String host) throws DataLinkException
uses the default port of 18000- Parameters:
host
- host to connect to- Throws:
DataLinkException
- if unable to connect
-
DataLink
public DataLink(java.lang.String host, int port) throws DataLinkException
Open DataLink socket connection- Parameters:
host
- host to connect toport
- port to connect to- Throws:
DataLinkException
- if unable to connect
-
DataLink
public DataLink(java.lang.String host, int port, int timeoutSeconds) throws DataLinkException
Open DataLink socket connection- Parameters:
host
- host to connect toport
- port to connect totimeoutSeconds
- timeout value- Throws:
DataLinkException
- if unable to connect
-
DataLink
public DataLink(java.lang.String host, int port, int timeoutSeconds, boolean verbose) throws DataLinkException
- Throws:
DataLinkException
-
-
Method Detail
-
readPacket
public DataLinkResponse readPacket() throws java.io.IOException, DataLinkException
Read a packet. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.- Returns:
- packet if available.
- Throws:
java.io.IOException
- if an I/O Exception occurs.DataLinkException
- if not connected- See Also:
readPacket()
-
stream
public void stream() throws DataLinkException
- Throws:
DataLinkException
-
endStream
public void endStream() throws DataLinkException
- Throws:
DataLinkException
-
match
public void match(java.lang.String matchRegEx) throws DataLinkException
- Throws:
DataLinkException
-
reject
public void reject(java.lang.String rejectRegEx) throws DataLinkException
- Throws:
DataLinkException
-
available
public boolean available() throws java.io.IOException
true if there is enough data in the instream to possibly read a data record. This should not block, unlike hasNext() and next().- Returns:
- true if enough data to read a record
- Throws:
java.io.IOException
- if input stream throws
-
availableBytes
public int availableBytes() throws java.io.IOException
- Returns:
- available() from the underlying InputStream, in bytes
- Throws:
java.io.IOException
- from underlying input stream
-
close
public void close()
Send end and close connection.
-
isConnected
public boolean isConnected()
- Returns:
- true is connected
-
reconnect
public void reconnect() throws java.io.IOException, DataLinkException
Would be really nice to keep state and reconnect plus backfill, but...- Throws:
java.io.IOException
- from underlying socketDataLinkException
- if error with datalink protocol
-
encodeDLCommand
public byte[] encodeDLCommand(java.lang.String command, java.lang.String dataString) throws DataLinkException
encodes command with optional data section as a string. This works for client generated commands but not for a PACKET, which would have binary data. PACKET is what client receives, but usually never sends if it does not generate data.- Parameters:
command
- command to senddataString
- optional data- Throws:
DataLinkException
- if command is too long
-
sendDLCommand
public void sendDLCommand(java.lang.String command, java.lang.String dataString) throws DataLinkException
Sends a DL Command and awaits the response, either OK or ERROR.- Parameters:
command
- command to senddataString
- optional associated data- Throws:
DataLinkException
- if error sending or with response
-
awaitDLCommand
public DataLinkResponse awaitDLCommand(java.lang.String command, java.lang.String dataString) throws DataLinkException
- Throws:
DataLinkException
-
sendId
public void sendId() throws DataLinkException
- Throws:
DataLinkException
-
verbose
public void verbose(java.lang.String message)
-
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()
-
getServerId
public java.lang.String getServerId()
-
getClientIdNum
public int getClientIdNum()
-
getUsername
public java.lang.String getUsername()
-
-