Esempio n. 1
0
 @Override
 public boolean runCmd(String[] args) throws Exception {
   if (args.length < 2) {
     return false;
   }
   String errorMsg = null;
   try {
     if (HedwigCommands.SHOW_HUBS.equals(args[1])) {
       errorMsg = "Unable to fetch the list of hub servers";
       showHubs();
     } else if (HedwigCommands.SHOW_TOPICS.equals(args[1])) {
       errorMsg = "Unable to fetch the list of topics";
       showTopics();
     } else {
       System.err.println("ERROR: Unknown show command '" + args[1] + "'");
       return false;
     }
   } catch (Exception e) {
     if (null != errorMsg) {
       System.err.println(errorMsg);
     }
     e.printStackTrace();
   }
   return true;
 }
Esempio n. 2
0
 @Override
 public boolean runCmd(String[] args) throws Exception {
   if (args.length < 7) {
     return false;
   }
   String topicPrefix = args[1];
   int startTopic = Integer.parseInt(args[2]);
   int endTopic = Integer.parseInt(args[3]);
   String subPrefix = args[4];
   int startSub = Integer.parseInt(args[5]);
   int endSub = Integer.parseInt(args[6]);
   if (startTopic > endTopic || endSub < startSub) {
     return false;
   }
   for (int i = startTopic; i <= endTopic; i++) {
     ByteString topic = ByteString.copyFromUtf8(topicPrefix + i);
     try {
       for (int j = startSub; j <= endSub; j++) {
         ByteString sub = ByteString.copyFromUtf8(subPrefix + j);
         subscriber.subscribe(topic, sub, CreateOrAttach.CREATE_OR_ATTACH);
         subscriber.unsubscribe(topic, sub);
       }
       System.out.println("RMSUB " + topic.toStringUtf8() + " DONE");
     } catch (Exception e) {
       System.err.println("RMSUB " + topic.toStringUtf8() + " FAILED");
       e.printStackTrace();
     }
   }
   return true;
 }
Esempio n. 3
0
    @Override
    public boolean runCmd(String[] args) throws Exception {
      if (args.length < 3) {
        return false;
      }
      ByteString topic = ByteString.copyFromUtf8(args[1]);

      StringBuilder sb = new StringBuilder();
      for (int i = 2; i < args.length; i++) {
        sb.append(args[i]);
        if (i != args.length - 1) {
          sb.append(' ');
        }
      }
      ByteString msgBody = ByteString.copyFromUtf8(sb.toString());
      Message msg = Message.newBuilder().setBody(msgBody).build();
      try {
        publisher.publish(topic, msg);
        System.out.println("PUB DONE");
      } catch (Exception e) {
        System.err.println("PUB FAILED");
        e.printStackTrace();
      }
      return true;
    }
Esempio n. 4
0
 @Override
 public boolean runCmd(String[] args) throws Exception {
   if (args.length < 3) {
     return false;
   }
   ByteString topic = ByteString.copyFromUtf8(args[1]);
   ByteString subId = ByteString.copyFromUtf8(args[2]);
   try {
     subscriber.stopDelivery(topic, subId);
     subscriber.unsubscribe(topic, subId);
     System.out.println("UNSUB DONE");
   } catch (Exception e) {
     System.err.println("UNSUB FAILED");
     e.printStackTrace();
   }
   return true;
 }
Esempio n. 5
0
 @Override
 public boolean runCmd(String[] args) throws Exception {
   CreateOrAttach mode;
   boolean receive = true;
   if (args.length < 3) {
     return false;
   } else if (args.length == 3) {
     mode = CreateOrAttach.ATTACH;
     receive = true;
   } else {
     try {
       mode = CreateOrAttach.valueOf(Integer.parseInt(args[3]));
     } catch (Exception e) {
       System.err.println("Unknow mode : " + args[3]);
       return false;
     }
     if (args.length >= 5) {
       try {
         receive = Boolean.parseBoolean(args[4]);
       } catch (Exception e) {
         receive = false;
       }
     }
   }
   if (mode == null) {
     System.err.println("Unknow mode : " + args[3]);
     return false;
   }
   ByteString topic = ByteString.copyFromUtf8(args[1]);
   ByteString subId = ByteString.copyFromUtf8(args[2]);
   try {
     SubscriptionOptions options =
         SubscriptionOptions.newBuilder().setCreateOrAttach(mode).setForceAttach(false).build();
     subscriber.subscribe(topic, subId, options);
     if (receive) {
       subscriber.startDelivery(topic, subId, consoleHandler);
       System.out.println("SUB DONE AND RECEIVE");
     } else {
       System.out.println("SUB DONE BUT NOT RECEIVE");
     }
   } catch (Exception e) {
     System.err.println("SUB FAILED");
     e.printStackTrace();
   }
   return true;
 }
Esempio n. 6
0
  protected boolean processCmd(MyCommandOptions co) {
    String[] args = co.getArgArray();
    String cmd = co.getCommand();
    if (args.length < 1) {
      usage();
      return false;
    }
    if (!getHedwigCommands().containsKey(cmd)) {
      usage();
      return false;
    }

    LOG.debug("Processing {}", cmd);

    MyCommand myCommand = myCommands.get(cmd);
    if (myCommand == null) {
      System.err.println("No Command Processor found for command " + cmd);
      usage();
      return false;
    }

    long startTime = MathUtils.now();
    boolean success = false;
    try {
      success = myCommand.runCmd(args);
    } catch (Exception e) {
      e.printStackTrace();
      success = false;
    }
    long elapsedTime = MathUtils.now() - startTime;
    if (inConsole) {
      if (success) {
        System.out.println("Finished " + ((double) elapsedTime / 1000) + " s.");
      } else {
        COMMAND c = getHedwigCommands().get(cmd);
        if (c != null) {
          c.printUsage();
        }
      }
    }
    return success;
  }