Java Code Examples for org.apache.cassandra.transport.messages.OptionsMessage

Following code examples demonstrate how to use org.apache.cassandra.transport.messages.OptionsMessagefrom cassandra. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use org.apache.cassandra.transport.messages.OptionsMessageand various code implementation of this class.

   private Message.Request parseLine(String line) {
      Splitter splitter = Splitter.on(' ').trimResults().omitEmptyStrings();
      Iterator<String> iter = splitter.split(line).iterator();
      if(!iter.hasNext()) {
         return null;
      } else {
         String msgType = ((String)iter.next()).toUpperCase();
         if(msgType.equals("STARTUP")) {
            Map<String, String> options = new HashMap();
            options.put("CQL_VERSION", "3.0.0");

            while(iter.hasNext()) {
               String next = (String)iter.next();
               if(next.toLowerCase().equals("snappy")) {
                  options.put("COMPRESSION", "snappy");
                  this.connection.setCompressor(FrameCompressor.SnappyCompressor.instance);
               }
            }

            return new StartupMessage(options);
         } else {
            String type;
            if(msgType.equals("QUERY")) {
               line = line.substring(6);
               type = line;
               int pageSize = -1;
               if(line.matches(".+ !\\d+$")) {
                  int idx = line.lastIndexOf(33);
                  type = line.substring(0, idx - 1);

                  try {
                     pageSize = Integer.parseInt(line.substring(idx + 1, line.length()));
                  } catch (NumberFormatException var11) {
                     return null;
                  }
               }

               return new QueryMessage(type, QueryOptions.create(ConsistencyLevel.ONE, Collections.emptyList(), false, pageSize, (PagingState)null, (ConsistencyLevel)null, this.version, (String)null));
            } else if(msgType.equals("PREPARE")) {
               type = line.substring(8);
               return new PrepareMessage(type, (String)null);
            } else if(msgType.equals("EXECUTE")) {
               try {
                  byte[] id = Hex.hexToBytes((String)iter.next());
                  byte[] preparedStatementId = Hex.hexToBytes((String)iter.next());

                  ArrayList values;
                  ByteBuffer bb;
                  for(values = new ArrayList(); iter.hasNext(); values.add(bb)) {
                     String next = (String)iter.next();

                     try {
                        int v = Integer.parseInt(next);
                        bb = Int32Type.instance.decompose(Integer.valueOf(v));
                     } catch (NumberFormatException var12) {
                        bb = UTF8Type.instance.decompose(next);
                     }
                  }

                  return new ExecuteMessage(MD5Digest.wrap(id), MD5Digest.wrap(preparedStatementId), QueryOptions.forInternalCalls(ConsistencyLevel.ONE, values));
               } catch (Exception var14) {
                  return null;
               }
            } else if(msgType.equals("OPTIONS")) {
               return new OptionsMessage();
            } else if(msgType.equals("AUTHENTICATE")) {
               Map<String, String> credentials = this.readCredentials(iter);
               if(credentials != null && credentials.containsKey("username") && credentials.containsKey("password")) {
                  return new AuthResponse(this.encodeCredentialsForSasl(credentials));
               } else {
                  System.err.println("[ERROR] Authentication requires both 'username' and 'password'");
                  return null;
               }
            } else if(msgType.equals("REGISTER")) {
               type = line.substring(9).toUpperCase();

               try {
                  return new RegisterMessage(Collections.singletonList(Enum.valueOf(Event.Type.class, type)));
               } catch (IllegalArgumentException var13) {
                  System.err.println("[ERROR] Unknown event type: " + type);
                  return null;
               }
            } else {
               return null;
            }
         }
      }
   } 


Advertisement
Javadoc
Message to indicate that the server is ready to receive requests.
Advertisement