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 DMC
    DataLink​(java.lang.String host)
    uses the default port of 18000
    DataLink​(java.lang.String host, int port)
    Open DataLink socket connection
    DataLink​(java.lang.String host, int port, int timeoutSeconds)
    Open DataLink socket connection
    DataLink​(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()  
    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)  

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • 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 to
      port - 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 to
      port - port to connect to
      timeoutSeconds - 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 Details

    • 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 socket
      DataLinkException - 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 send
      dataString - 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 send
      dataString - 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()