Package edu.sc.seis.seisFile.datalink
Class DataLink
- java.lang.Object
-
- edu.sc.seis.seisFile.datalink.DataLink
-
public class DataLink extends java.lang.ObjectPhilip Crotwell University of South Carolina, 2019 http://www.seis.sc.edu
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringDATALINK_PROTOCOLstatic java.lang.StringDEFAULT_HOSTstatic intDEFAULT_PORTstatic intDEFAULT_TIMEOUT_SECONDstatic java.lang.StringEEYORE_HOSTstatic intEEYORE_PORTstatic java.lang.StringENDSTREAMstatic java.lang.StringERRORstatic java.lang.StringIDstatic java.lang.StringINFOstatic java.lang.StringIRIS_HOSTstatic intIRIS_PORTstatic java.lang.StringMATCHstatic intMAX_PROC_NUMstatic java.lang.StringMSEED_TYPEstatic java.lang.StringOKstatic java.lang.StringPACKETstatic java.lang.StringQUERY_MODEstatic java.lang.StringREJECTstatic java.lang.StringSTREAMstatic java.lang.StringSTREAM_MODEstatic java.lang.StringUSER_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 booleanavailable()true if there is enough data in the instream to possibly read a data record.intavailableBytes()DataLinkResponseawaitDLCommand(java.lang.String command, java.lang.String dataString)voidclose()Send end and close connection.byte[]encodeDLCommand(java.lang.String command, java.lang.String dataString)encodes command with optional data section as a string.voidendStream()intgetClientIdNum()java.lang.StringgetHost()intgetPort()java.lang.StringgetServerId()java.lang.StringgetUsername()java.io.PrintWritergetVerboseWriter()booleanisConnected()booleanisVerbose()voidmatch(java.lang.String matchRegEx)DataLinkResponsereadPacket()Read a packet.voidreconnect()Would be really nice to keep state and reconnect plus backfill, but...voidreject(java.lang.String rejectRegEx)voidsendDLCommand(java.lang.String command, java.lang.String dataString)Sends a DL Command and awaits the response, either OK or ERROR.voidsendId()voidsetVerbose(boolean verbose)voidsetVerboseWriter(java.io.PrintWriter verboseWriter)voidstream()voidverbose(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 DataLinkExceptiondefault of IRIS DMC- Throws:
DataLinkException- if unable to connect
-
DataLink
public DataLink(java.lang.String host) throws DataLinkExceptionuses 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 DataLinkExceptionOpen 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 DataLinkExceptionOpen 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.IOExceptiontrue 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, DataLinkExceptionWould 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 DataLinkExceptionencodes 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 DataLinkExceptionSends 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()
-
-