示例#1
0
 public void execute(Tuple tuple, BasicOutputCollector collector) {
   String args = tuple.getString(0);
   String returnInfo = tuple.getString(1);
   long requestId = rand.nextLong();
   collector.emit(ARGS_STREAM, new Values(requestId, args));
   collector.emit(RETURN_STREAM, new Values(requestId, returnInfo));
   collector.emit(ID_STREAM, new Values(requestId));
 }
  public void execute(Tuple input, BasicOutputCollector collector) {
    String line = input.getString(0);
    String[] triple = StringUtils.split(line, delim);
    if (triple.length != 3) throw new RuntimeException("Line is not a triple: " + input);

    // make sure that parts of the filter that are not variables match the respective parts in the
    // input triple
    // also make sure repeated variables receive the same value (ie ?a_foo_?a shouldn't accept
    // A_foo_B)
    Map<String, String> bindings = new TreeMap<String, String>();
    for (int i = 0; i < 3; i++)
      if (filter[i].startsWith(varIndicator)) {
        if (bindings.containsKey(filter[i])) {
          if (!bindings.get(filter[i]).equals(triple[i])) {
            return;
          }
        } else {
          bindings.put(filter[i], triple[i]);
        }
      } else {
        if (!triple[i].equals(filter[i])) {
          return;
        }
      }

    collector.emit(new Values(bindings));
  }
示例#3
0
 @Override
 public void hanleData(
     String msisdnId,
     String sessionId,
     Long currentTime,
     double realInfoFee,
     String channelId,
     String productId,
     String rules,
     String provinceId,
     int orderType,
     String bookId) {
   collector.emit(
       StreamId.ABNORMALDATASTREAM.name(),
       new Values(
           msisdnId,
           sessionId,
           currentTime,
           realInfoFee,
           channelId,
           productId,
           provinceId,
           orderType,
           bookId,
           rules));
 }
 @Override
 public void execute(Tuple input, BasicOutputCollector collector) {
   //
   String track = input.getString(0);
   if (track != null) {
     String arr[] = track.split("\n");
     List<TrackerVo> list = new ArrayList<TrackerVo>();
     for (String s : arr) {
       String cols[] = s.split("\\t");
       //				System.out.println("cols:"+cols.length);
       // 过滤一:列小于30的丢弃
       if (cols.length < 30) {
         continue;
       }
       // 过滤二:过滤来自百度的爬虫数据
       if (s.contains("http://www.baidu.com/search/spider.html")) {
         continue;
       }
       TrackerVo tracker = new TrackerVo(s);
       // 过滤三:过滤button_position 不为空的
       if (tracker.getButton_position() != null
           && !"null".equals(tracker.getButton_position())
           && tracker.getButton_position().length() > 1) {
         //					System.out.println("button:"+tracker.getButton_position());
         continue;
       }
       list.add(tracker);
       //				System.out.println(arr.length+"------:"+cols.length+"--"+tracker.getId());
     }
     if (list.size() > 0) {
       collector.emit(new Values(list));
     }
   }
 }
 @Override
 public void execute(Tuple input, BasicOutputCollector collector) {
   String text = input.getString(0);
   System.out.println("text: " + text);
   for (String word : text.split(" ")) {
     collector.emit(new Values(word));
   }
 }
 @Override
 public void execute(Tuple tuple, BasicOutputCollector collector) {
   String word = tuple.getString(0);
   Integer count = counts.get(word);
   if (count == null) count = 0;
   count++;
   counts.put(word, count);
   collector.emit(new Values(word, count));
 }
示例#7
0
  public void execute(Tuple tuple, BasicOutputCollector collector) {
    tpsCounter.count();

    Long tupleId = tuple.getLong(0);
    Pair pair = (Pair) tuple.getValue(1);

    sum.addAndGet(pair.getValue());

    collector.emit(new Values(tupleId, pair));
  }
 public void execute(Tuple tuple, BasicOutputCollector collector) {
   String word = tuple.getString(0);
   Integer count = counts.get(word);
   if (count == null) {
     count = 0;
   }
   count++;
   counts.put(word, count);
   collector.emit(new Values(word, count));
   System.err.println(word + "----------------------" + count);
 }
示例#9
0
 @Override
 public void execute(Tuple tuple, BasicOutputCollector collector) {
   Object id = tuple.getValue(0);
   String tweeter = tuple.getString(1);
   List<String> followers = FOLLOWERS_DB.get(tweeter);
   if (followers != null) {
     for (String follower : followers) {
       collector.emit(new Values(id, follower));
     }
   }
 }
示例#10
0
 @Override
 public void execute(Tuple tuple, BasicOutputCollector collector) {
   Object id = tuple.getValue(0);
   String url = tuple.getString(1);
   List<String> tweeters = TWEETERS_DB.get(url);
   if (tweeters != null) {
     for (String tweeter : tweeters) {
       collector.emit(new Values(id, tweeter));
     }
   }
 }
 @Override
 public void execute(Tuple tuple, BasicOutputCollector collector) {
   String word = tuple.getString(0);
   if (log.isDebugEnabled()) {
     log.debug("Received event: " + tuple.toString());
   }
   eventsReceived = true;
   Integer count = counts.get(word);
   if (count == null) count = 0;
   count++;
   eventCount++;
   collector.emit(new Values(word, count));
 }
 public void execute(Tuple input, BasicOutputCollector collector) {
   try {
     String msg = input.getString(0);
     System.out.println(msg + "-------------------");
     if (msg != null) {
       String[] s = msg.split(" ");
       for (String string : s) {
         collector.emit(new Values(string));
       }
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
  @Override
  public void execute(Tuple tuple, BasicOutputCollector collector) {
    TransactionAttempt attempt = (TransactionAttempt) tuple.getValue(0);

    if (tuple.getSourceStreamId().equals(MasterBatchCoordinator.SUCCESS_STREAM_ID)) {
      _state.cleanupBefore(attempt.getTransactionId());
      _coord.success(attempt.getTransactionId());
    } else {
      long txid = attempt.getTransactionId();
      Object prevMeta = _state.getPreviousState(txid);
      Object meta = _coord.initializeTransaction(txid, prevMeta, _state.getState(txid));
      _state.overrideState(txid, meta);
      collector.emit(MasterBatchCoordinator.BATCH_STREAM_ID, new Values(attempt, meta));
    }
  }
示例#14
0
  @Override
  public void execute(Tuple input, BasicOutputCollector collector) {
    String address = input.getStringByField("address");
    Long time = input.getLongByField("time");

    GeocoderRequest request =
        new GeocoderRequestBuilder().setAddress(address).setLanguage("en").getGeocoderRequest();
    GeocodeResponse response = geocoder.geocode(request);
    GeocoderStatus status = response.getStatus();
    if (GeocoderStatus.OK.equals(status)) {
      GeocoderResult firstResult = response.getResults().get(0);
      LatLng latLng = firstResult.getGeometry().getLocation();
      Long timeInterval = time / (15 * 1000);
      String city = extractCity(firstResult);
      collector.emit(new Values(timeInterval, latLng, city));
    }
  }
  @Override
  public void execute(Tuple arg0, BasicOutputCollector collector) {

    /*
     *
     * Msg Receiving format from kafka
     *
     * [{ "timestamp":1407394935908, "publisher":"publisher_0",
     * "advertiser":"advertiser_2" ,"website":"website_7689.com",
     * "geo":"MI", "bid":0.14403514698631104, "cookie":"cookie_7447"}]
     */

    String inputValue = arg0.getString(0).toString();
    ObjectNode obj2 = null;
    try {
      obj2 = mapper.readValue(inputValue, ObjectNode.class);
    } catch (IOException e) {
    }

    // System.out.println(" obj2-------> "+obj2);

    Values val = new Values();
    String geo = obj2.get("geo").asText();
    val.add(geo);
    String pub = obj2.get("publisher").asText();
    val.add(pub);
    val.add(obj2.get("advertiser").asText());
    val.add(obj2.get("website").asText());
    double bid = obj2.get("bid").asDouble();
    val.add(new Double(bid).toString());
    val.add(obj2.get("cookie").asText());
    String timeStampStr = obj2.get("timestamp").asText();
    // System.out.println(" timeStamp---str------> "+timeStampStr);
    long timeStamp = Long.parseLong(timeStampStr);
    // System.out.println(" timeStamp---------> "+timeStamp);
    SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss aa");

    String fullTime = DATE_FORMAT.format(timeStamp);
    val.add(fullTime);
    val.add(geo + pub + getDateUptoMinute(fullTime));

    // System.out.println(" val ---------> "+val);
    collector.emit(val);
  }
 @Override
 public void processSlide(BasicOutputCollector collector) {
   try {
     T reduceValue = null;
     // TODO: implement window data structure with tree, no need to for loop
     for (T t : reduceList) {
       if (null == reduceValue) {
         reduceValue = t;
       } else {
         reduceValue = fun.reduce(reduceValue, t);
       }
     }
     collector.emit(new Values(slideIndexInBuffer, reduceValue));
     // clear data
     reduceList.set((slideInWindow + 1) % WINDOW_SIZE, null);
   } catch (Exception e) {
     logger.error(e.toString());
   }
 }
  @Override
  public void execute(Tuple input, BasicOutputCollector collector) {
    String author = input.getString(0);
    double[] features = (double[]) input.getValue(1);
    double[] posteriorProbability = (double[]) input.getValue(2);

    double[] Nk = new double[features.length];

    for (int i = 0; i < Nk.length; i++) {
      Nk[i] += posteriorProbability[i];
    }

    if (!this.features.containsKey(author)
        && !this.posteriorProbability.containsKey(author)
        && !this.Nk.containsKey(author)) {
      collector.emit(new Values(author, features, posteriorProbability, Nk));

      this.features.put(author, features);
      this.posteriorProbability.put(author, posteriorProbability);
      this.Nk.put(author, Nk);
    }
  }
示例#18
0
  /**
   * Function will examine the origin of the message in order to determine whether or not the
   * message needs to be formatted and published to the Item Master Bolt, which would send item
   * updates to the Item Master first, else push information to the next Bolt which will then
   * process the information and push to multiple bolts which require the item update for their
   * local copy of item.
   */
  public void execute(Tuple input, BasicOutputCollector collector) {
    String eventOrigin = input.getString(0);
    String eventObject = input.getString(1);
    String correlationId = input.getString(2);

    logger.info("Item Event Notification Orgin is: " + eventOrigin);
    if (!eventOrigin.equals(MASTER_ORIGIN)) {
      logger.info(
          "["
              + correlationId
              + "] - "
              + "Process is needing to send a notification to Item Master for master update ....");
      logger.info("[" + correlationId + "] - " + "Event Object: " + eventObject);

      /*
       *	Another Bolt will end up perform the transformation and then
       *  another Bolt will perform any additional calls to the Master Item
       *  Micro Service.
       */
      collector.emit(new Values(correlationId, eventObject));
    }
  }
示例#19
0
 @Override
 public void execute(Tuple input, BasicOutputCollector collector) {
   for (String split : input.getString(0).split(" ")) {
     collector.emit(Lists.<Object>newArrayList(split));
   }
 }
示例#20
0
 @Override
 public void execute(Tuple tuple, BasicOutputCollector outputCollector) {
   String commit = tuple.getStringByField("commit");
   String[] parts = commit.split(" ");
   outputCollector.emit(new Values(parts[1]));
 }
示例#21
0
 private void emitRankings(BasicOutputCollector collector) {
   collector.emit(new Values(rankings.copy()));
   getLogger().debug("Rankings: " + rankings);
 }
示例#22
0
 @Override
 public void execute(Tuple tuple, BasicOutputCollector collector) {
   collector.emit(new Values(tuple.getValue(0)));
 }