Class ClientImpl

  • All Implemented Interfaces:
    java.lang.AutoCloseable, Client
    Direct Known Subclasses:
    ClientReplayImpl

    public class ClientImpl
    extends java.lang.Object
    implements Client, java.lang.AutoCloseable
    • Field Detail

      • logger

        private static final Logger logger
      • socket

        private final java.net.Socket socket
      • compressionSequence

        private final MutableInt compressionSequence
      • lock

        private final java.util.concurrent.locks.ReentrantLock lock
      • closed

        private boolean closed
      • socketTimeout

        private int socketTimeout
      • waitTimeout

        private int waitTimeout
      • disablePipeline

        private final boolean disablePipeline
      • context

        protected Context context
    • Constructor Detail

      • ClientImpl

        public ClientImpl​(Configuration conf,
                          HostAddress hostAddress,
                          java.util.concurrent.locks.ReentrantLock lock,
                          boolean skipPostCommands)
                   throws java.sql.SQLException
        Throws:
        java.sql.SQLException
    • Method Detail

      • assignStream

        private void assignStream​(java.io.OutputStream out,
                                  java.io.InputStream in,
                                  Configuration conf,
                                  java.lang.Long threadId)
      • destroySocket

        protected void destroySocket()
        Closing socket in case of Connection error after socket creation.
      • handleTimezone

        private java.lang.String handleTimezone()
                                         throws java.sql.SQLException
        load server timezone and ensure this corresponds to client timezone
        Throws:
        java.sql.SQLException - if any socket error.
      • postConnectionQueries

        private void postConnectionQueries()
                                    throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • createSessionVariableQuery

        public java.lang.String createSessionVariableQuery​(java.lang.String serverTz)
      • setReadOnly

        public void setReadOnly​(boolean readOnly)
                         throws java.sql.SQLException
        Specified by:
        setReadOnly in interface Client
        Throws:
        java.sql.SQLException
      • sendQuery

        public int sendQuery​(ClientMessage message)
                      throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • execute

        public java.util.List<Completion> execute​(ClientMessage message)
                                           throws java.sql.SQLException
        Specified by:
        execute in interface Client
        Throws:
        java.sql.SQLException
      • executePipeline

        public java.util.List<Completion> executePipeline​(ClientMessage[] messages,
                                                          Statement stmt,
                                                          int fetchSize,
                                                          long maxRows,
                                                          int resultSetConcurrency,
                                                          int resultSetType,
                                                          boolean closeOnCompletion)
                                                   throws java.sql.SQLException
        Specified by:
        executePipeline in interface Client
        Throws:
        java.sql.SQLException
      • execute

        public java.util.List<Completion> execute​(ClientMessage message,
                                                  Statement stmt,
                                                  int fetchSize,
                                                  long maxRows,
                                                  int resultSetConcurrency,
                                                  int resultSetType,
                                                  boolean closeOnCompletion)
                                           throws java.sql.SQLException
        Specified by:
        execute in interface Client
        Throws:
        java.sql.SQLException
      • readResponse

        public java.util.List<Completion> readResponse​(Statement stmt,
                                                       ClientMessage message,
                                                       int fetchSize,
                                                       long maxRows,
                                                       int resultSetConcurrency,
                                                       int resultSetType,
                                                       boolean closeOnCompletion)
                                                throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • readResponse

        public void readResponse​(ClientMessage message)
                          throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • readStreamingResults

        public void readStreamingResults​(java.util.List<Completion> completions,
                                         int fetchSize,
                                         long maxRows,
                                         int resultSetConcurrency,
                                         int resultSetType,
                                         boolean closeOnCompletion)
                                  throws java.sql.SQLException
        Specified by:
        readStreamingResults in interface Client
        Throws:
        java.sql.SQLException
      • readResults

        private void readResults​(Statement stmt,
                                 ClientMessage message,
                                 java.util.List<Completion> completions,
                                 int fetchSize,
                                 long maxRows,
                                 int resultSetConcurrency,
                                 int resultSetType,
                                 boolean closeOnCompletion)
                          throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • readPacket

        public Completion readPacket​(ClientMessage message)
                              throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • readPacket

        public Completion readPacket​(Statement stmt,
                                     ClientMessage message,
                                     int fetchSize,
                                     long maxRows,
                                     int resultSetConcurrency,
                                     int resultSetType,
                                     boolean closeOnCompletion)
                              throws java.sql.SQLException
        Read server response packet.
        Parameters:
        stmt - current statement (null if internal)
        message - current message
        fetchSize - default fetch size
        resultSetConcurrency - concurrency
        resultSetType - type
        closeOnCompletion - must resultset close statement on completion
        Throws:
        java.sql.SQLException - if any exception
        See Also:
        server response packets
      • checkNotClosed

        protected void checkNotClosed()
                               throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • closeSocket

        private void closeSocket()
      • isClosed

        public boolean isClosed()
        Specified by:
        isClosed in interface Client
      • abort

        public void abort​(java.util.concurrent.Executor executor)
                   throws java.sql.SQLException
        Specified by:
        abort in interface Client
        Throws:
        java.sql.SQLException
      • setSocketTimeout

        public void setSocketTimeout​(int milliseconds)
                              throws java.sql.SQLException
        Specified by:
        setSocketTimeout in interface Client
        Throws:
        java.sql.SQLException
      • close

        public void close()
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface Client
      • isPrimary

        public boolean isPrimary()
        Specified by:
        isPrimary in interface Client
      • reset

        public void reset()
        Specified by:
        reset in interface Client