Class DataLink


  • public class DataLink
    extends java.lang.Object
    Philip Crotwell University of South Carolina, 2019 http://www.seis.sc.edu
    • Constructor Detail

      • 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
    • 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()
      • 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
      • 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()