@Override
 public void execute(
     final TridentTuple tuple,
     final Map.Entry<Integer, double[]> result,
     final TridentCollector collector) {
   collector.emit(new Values(localPartition, result));
 }
  public void execute(TridentTuple tuple, TridentCollector collector) {
    Map<String, Object> event = new HashMap<String, Object>();
    if (tuple.get(0) instanceof byte[]) {
      byte[] messageBytes = (byte[]) tuple.get(0);
      String messageString = new String(messageBytes);
      System.out.println("flight delay tweet: " + messageString);

      try {
        JSONObject json = new JSONObject(messageString);
        System.out.println("Created json object");

        Iterator keyIt = json.keys();
        while (keyIt.hasNext()) {
          String key = (String) keyIt.next();
          if (!tweetKeyWhiteList.contains(key)) {
            continue;
          }
          Object value = json.get(key);
          event.put(key, value);
        }
      } catch (Exception e) {
        System.out.println("Error parsing json from tweet object");
        log.error(e);
      }
      try {

        String id = event.get("user_id").toString();

        double lat = Double.parseDouble(event.get("lat").toString());
        double lon = Double.parseDouble(event.get("lon").toString());

        if (lat > 0 || lat < 0) {
          MessageDigest md = MessageDigest.getInstance("SHA-256");
          md.update(id.getBytes());

          byte byteData[] = md.digest();

          // convert the byte to hex format method 1
          StringBuilder sb = new StringBuilder();
          for (int i = 0; i < byteData.length; i++) {
            sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1));
          }
          id = sb.toString();
          GroupByField idField = new GroupByField("TWEET_USER_ID", id);
          GroupByField objectType = new GroupByField("OBJECT_TYPE", "TWITTER_USER");
          event.put("TWEET_USER_ID", id);
          event.put("user_id", id);

          collector.emit(new Values(idField, objectType, event));
        }

      } catch (Exception e) {
        log.error("Error parsing tweet info", e);
      }

    } else {
      System.out.println("object at tuple index 0: " + tuple.get(0).getClass().getName());
    }
  }
 @Override
 public void execute(TridentTuple tuple, TridentCollector collector) {
   for (String word : tuple.getString(0).split("[ ;,:\\?\\-\\\"\\!\\.\\r()]+")) {
     if (word.length() > size) {
       collector.emit(new Values(word.toLowerCase()));
     }
   }
 }
 @Override
 public void execute(TridentTuple tuple, TridentCollector collector) {
   String[] lines = tuple.getString(0).split(",");
   if (3 == lines.length) {
     collector.emit(new Values(Integer.valueOf(lines[0]), lines[1], lines[2]));
   } else {
     LOG.error("##### Goods format error message:" + tuple.getString(0));
   }
 }
示例#5
0
 @Override
 public void execute(TridentTuple tuple, TridentCollector collector) {
   List l = (List) tuple.getValue(0);
   if (l != null) {
     for (Object o : l) {
       collector.emit(new Values(o));
     }
   }
 }
  @Override
  public void execute(TridentTuple tuple, TridentCollector collector) {
    try {
      String assetPhysical = tuple.getStringByField("asset_physical");
      String beginTime = tuple.getStringByField("begin_time");
      String endTime = tuple.getStringByField("end_time");
      String clientAddress = tuple.getStringByField("client_address"); // 获取对端IP

      String filePath = tuple.getStringByField("file_path");
      String fileSize = tuple.getStringByField("file_size"); // 获取文件大小,单位为byte

      String ftpAccount = tuple.getStringByField("ftp_account");
      Long operateType = tuple.getLongByField("operate_type");
      String serverName = tuple.getStringByField("server_name");
      String version = tuple.getStringByField("version");

      // 由于业务变更,改成属性映射获取业务类型数据与属性字典(暂时只包括businessType和Area编码映射)
      Map<String, Object> dictionaryMap = DictionaryMappingUtil.transfer(filePath);

      // 获取业务类型编码
      String businessType =
          dictionaryMap.get(DictionaryMappingUtil.BUSINESSTYPE_KEY).toString(); // "A0001";
      LOG.info("**businessType==>" + businessType);

      // 获取区域编码
      Long area =
          Long.parseLong(dictionaryMap.get(DictionaryMappingUtil.PROVINCECODE_KEY).toString());
      LOG.info("**area==>" + area);

      // 资产名从物理文件名中获取
      String assetEnName = DictionaryMappingUtil.getName(assetPhysical, businessType);
      LOG.info("**assetEnName==>" + assetEnName);

      MonitorDTO monitor = new MonitorDTO();
      monitor.setBusiness_type(businessType);
      monitor.setAsset_en_name(assetEnName);
      monitor.setAsset_physical(assetPhysical);
      monitor.setArea(area);
      monitor.setOperate_type(operateType);
      monitor.setBegin_time(beginTime);
      monitor.setEnd_time(endTime);
      monitor.setVersion(version);
      monitor.setServer_name(serverName);
      monitor.setFtp_account(ftpAccount);
      monitor.setFile_path(filePath);
      monitor.setFile_size(new Long(fileSize));
      monitor.setClient_address(clientAddress);

      Values values = new Values();
      values.add(monitor);

      collector.emit(values);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
 @Override
 public void updateState(
     Snapshottable state, List<TridentTuple> tuples, TridentCollector collector) {
   if (tuples.size() != 1) {
     throw new IllegalArgumentException(
         "Combiner state updater should receive a single tuple. Received: " + tuples.toString());
   }
   Object newVal = state.update(new CombinerValueUpdater(_agg, tuples.get(0).getValue(0)));
   collector.emit(new Values(newVal));
 }
示例#8
0
 @Override
 public void execute(TridentTuple tuple, TridentCollector collector) {
   String pvString = tuple.getString(0);
   PageView pageView = PageView.fromString(pvString);
   if (null == pageView) {
     LOG.error("invalid pageview string '" + pvString + "'");
     return;
   }
   List<Object> values = new ArrayList<Object>();
   for (Item field : fields) {
     values.add(pageView.getValue(field));
   }
   collector.emit(values);
 }
示例#9
0
 @Override
 public void emitBatch(long batchId, TridentCollector collector) {
   List<List<Object>> batch = this.batches.get(batchId);
   if (batch == null) {
     batch = new ArrayList<List<Object>>();
     if (index >= outputs.length && cycle) {
       index = 0;
     }
     for (int i = 0; index < outputs.length && i < maxBatchSize; index++, i++) {
       batch.add(outputs[index]);
     }
     this.batches.put(batchId, batch);
   }
   for (List<Object> list : batch) {
     collector.emit(list);
   }
 }
 @Override
 @SuppressWarnings({"rawtypes", "unchecked"})
 public void execute(TridentTuple tuple, TridentCollector collector) {
   List<KeyValue> keyValueList = (List<KeyValue>) tuple.getValue(0);
   for (KeyValue keyValue : keyValueList) {
     Values values = new Values();
     if (this.rowKey) {
       if (this.rowKeyDeserializer != null) {
         values.add(this.rowKeyDeserializer.deserialize(keyValue.key()));
       } else {
         values.add(new String(keyValue.key()));
       }
     }
     if (this.family) {
       if (this.columnFamilyDeserializer != null) {
         values.add(this.columnFamilyDeserializer.deserialize(keyValue.family()));
       } else {
         values.add(new String(keyValue.family()));
       }
     }
     if (this.qualifier) {
       if (this.columnQualifierDeserializer != null) {
         values.add(this.columnFamilyDeserializer.deserialize(keyValue.qualifier()));
       } else {
         values.add(new String(keyValue.qualifier()));
       }
     }
     if (this.value) {
       if (this.valueDeserializer != null) {
         values.add(this.valueDeserializer.deserialize(keyValue.value()));
       } else {
         values.add(new String(keyValue.value()));
       }
     }
     if (this.timestamp) {
       values.add(keyValue.timestamp());
     }
     collector.emit(values);
   }
 }
示例#11
0
  @Override
  public void execute(TridentTuple tuple, TridentCollector collector) {
    GameState gameState = (GameState) tuple.get(0);
    Board currentBoard = gameState.getBoard();
    List<Board> history = new ArrayList<Board>();
    history.addAll(gameState.getHistory());
    history.add(currentBoard);

    if (!currentBoard.isEndState()) {
      String nextPlayer = Player.next(gameState.getPlayer());
      List<Board> boards = gameState.getBoard().nextBoards(nextPlayer);
      Log.debug(
          "Generated [" + boards.size() + "] children boards for [" + gameState.toString() + "]");
      for (Board b : boards) {
        GameState newGameState = new GameState(b, history, nextPlayer);
        List<Object> values = new ArrayList<Object>();
        values.add(newGameState);
        collector.emit(values);
      }
    } else {
      Log.debug("End game found! [" + currentBoard + "]");
    }
  }
 @Override
 public void execute(
     TridentTuple tuple, Map.Entry<Double, double[]> result, TridentCollector collector) {
   collector.emit(new Values(result.getKey()));
 }
 @Override
 public void execute(TridentTuple tuple, TridentCollector collector) {
   System.out.println("####### tuple = " + tuple.getValues());
   collector.emit(tuple.getValues());
 }
 public void complete(Result val, TridentCollector collector) {
   collector.emit(new Values(val.obj));
 }