joshelser commented on a change in pull request #476: HBASE-11062 hbtop
URL: https://github.com/apache/hbase/pull/476#discussion_r317672834
 
 

 ##########
 File path: 
hbase-hbtop/src/main/java/org/apache/hadoop/hbase/hbtop/terminal/impl/KeyPressGenerator.java
 ##########
 @@ -0,0 +1,477 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.hbtop.terminal.impl;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.nio.charset.StandardCharsets;
+import java.util.Queue;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+import org.apache.hadoop.hbase.hbtop.terminal.KeyPress;
+import org.apache.yetus.audience.InterfaceAudience;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * This generates {@link KeyPress} objects from the given input stream and 
offers them to the
+ * given queue.
+ */
+@InterfaceAudience.Private
+public class KeyPressGenerator {
+
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(KeyPressGenerator.class);
+
+  private enum ParseState {
+    START, ESCAPE, ESCAPE_SEQUENCE_PARAM1, ESCAPE_SEQUENCE_PARAM2
+  }
+
+  private final Queue<KeyPress> keyPressQueue;
+  private final BlockingQueue<Character> inputCharacterQueue = new 
LinkedBlockingQueue<>();
+  private final Reader input;
+  private final InputStream inputStream;
+  private final AtomicBoolean stopThreads = new AtomicBoolean();
+  private final Thread readerThread = new Thread(this::readerThread);
+  private final Thread generatorThread = new Thread(this::generatorThread);
+
+  private ParseState parseState;
+  private int param1;
+  private int param2;
+
+  public KeyPressGenerator(InputStream inputStream, Queue<KeyPress> 
keyPressQueue) {
+    this.inputStream = inputStream;
+    input = new InputStreamReader(inputStream, StandardCharsets.UTF_8);
+    this.keyPressQueue = keyPressQueue;
+
+    initState();
+  }
+
+  public void start() {
+    readerThread.start();
 
 Review comment:
   It would be good to use an ExecutorService to launch these (e.g. 
`newFixedThreadPool(2)`) and then, for both, set:
   * daemon(true)
   * a name
   * uncaughtExceptionHandler()

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to