Example #1
0
 @Override
 public void run() {
   try {
     Thread.currentThread().setName("AeshProcess: " + operation.getPid());
     myThread = Thread.currentThread();
     setExitResult(consoleCallback.execute(operation));
   } catch (InterruptedException e) {
     setExitResult(-1);
     // e.printStackTrace();
   } finally {
     manager.processHaveFinished(this);
   }
 }
 public void start() throws IOException {
   String s;
   Pattern set = Pattern.compile("set (?<key>.*) (?<value>.*)");
   Pattern get = Pattern.compile("get (?<key>.*)");
   Pattern call = Pattern.compile("call (?<key>.*)");
   Pattern getAll = Pattern.compile("getall");
   StateSingleton state = StateSingleton.getInstance();
   while ((s = in.readLine().toLowerCase()) != null) {
     Matcher m;
     if ((m = set.matcher(s)).matches()) {
       state.setValue(m.group("key"), m.group("value"));
     } else if ((m = get.matcher(s)).matches()) {
       out.println(state.getValue(m.group("key")));
     } else if ((m = getAll.matcher(s)).matches()) {
       for (String key : state.getAllKeys()) {
         out.println(key);
       }
     } else if ((m = call.matcher(s)).matches()) {
       ConsoleCallback callback = calls.get(m.group("key"));
       if (callback != null) callback.call(out);
     }
   }
 }