public void process(
     IncomingMessageEnvelope envelope, MessageCollector collector, TaskCoordinator coordinator) {
   System.out.println(
       "Adding " + envelope.getMessage() + " => " + envelope.getMessage() + " to the store.");
   store.put((String) envelope.getMessage(), (String) envelope.getMessage());
   coordinator.commit(RequestScope.ALL_TASKS_IN_CONTAINER);
 }
Пример #2
0
 @Override
 public void process(
     IncomingMessageEnvelope envelope, MessageCollector collector, TaskCoordinator coordinator) {
   String key = (String) envelope.getKey();
   String epoch = (String) envelope.getMessage();
   checkEpoch(epoch);
   this.store.put(key, epoch);
 }
  public void process(
      IncomingMessageEnvelope envelope, MessageCollector collector, TaskCoordinator coordinator)
      throws Exception {
    Map<String, Object> msg = (Map<String, Object>) envelope.getMessage();

    int logval;
    try {
      logval = Integer.parseInt((String) msg.get("log")); // 这里少了trim!!!
    } catch (Exception e) {
      e.printStackTrace();
      return;
    }
    if (logval >= 10) {
      collector.send(
          new OutgoingMessageEnvelope(new SystemStream("kafka", "g10"), envelope.getKey(), msg));
    }

    // check if it's a debug message
    if (msg.containsKey("mode") && msg.get("mode").equals("DEBUG")) {
      msg.put("path", "B");
      collector.send(
          new OutgoingMessageEnvelope(new SystemStream("kafka", "debug"), msg.get("user"), msg));
    }
  }
  @Override
  public void process(
      IncomingMessageEnvelope envelope, MessageCollector collector, TaskCoordinator coordinator) {
    if ("positive-words".equals(envelope.getSystemStreamPartition().getStream())) {
      positiveWords.add(((String) envelope.getMessage()));
    } else if ("negative-words".equals(envelope.getSystemStreamPartition().getStream())) {
      negativeWords.add(((String) envelope.getMessage()));
    } else if ("english-tweets".equals(envelope.getSystemStreamPartition().getStream())) {
      tweets++;

      int positive = 0;
      int negative = 0;
      String words = ((String) envelope.getMessage());

      for (String word : words.split(" ")) {
        if (positiveWords.contains(word)) {
          positive++;
        } else if (negativeWords.contains(word)) {
          negative++;
        }
      }

      if (positive > negative) {
        positiveTweets++;
      }

      if (negative > positive) {
        negativeTweets++;
      }

      if (positive > maxPositive) {
        maxPositive = positive;
      }

      if (negative > maxNegative) {
        maxNegative = negative;
      }
    }
  }