/** * Creates a (defensive) copy of itself. */ public Rankings copy() { return new Rankings(this); } }
public void updateWith(Rankable r) { synchronized(rankedItems) { addOrReplace(r); rerank(); shrinkRankingsIfNeeded(); } }
private void addOrReplace(Rankable r) { Integer rank = findRankOf(r); if (rank != null) { rankedItems.set(rank, r); } else { rankedItems.add(r); } }
/** * Copy constructor. * @param other */ public Rankings(Rankings other) { this(other.maxSize()); updateWith(other); }
public void updateWith(Rankings other) { for (Rankable r : other.getRankings()) { updateWith(r); } }
@Override void updateRankingsWithTuple(Tuple tuple) { Rankings rankingsToBeMerged = (Rankings) tuple.getValue(0); super.getRankings().updateWith(rankingsToBeMerged); super.getRankings().pruneZeroCounts(); }
@Override void updateRankingsWithTuple(Tuple tuple) { Rankable rankable = RankableObjectWithFields.from(tuple); super.getRankings().updateWith(rankable); }
private void emitRankings(BasicOutputCollector collector) { collector.emit(new Values(rankings.copy())); getLogger().debug("Rankings: " + rankings); }
@Override public void execute(Tuple tuple) { Rankings rankableList = (Rankings) tuple.getValue(0); for (Rankable r: rankableList.getRankings()){ String word = r.getObject().toString(); Long count = r.getCount(); redis.publish("WordCountTopology", word + "|" + Long.toString(count)); } // access the first column 'word' //String word = tuple.getStringByField("word"); // access the second column 'count' //String word = rankedWords.toString(); //Integer count = tuple.getIntegerByField("count"); //Long count = new Long(100); // publish the word count to redis using word as the key //redis.publish("WordCountTopology", word + ":" + Long.toString(count)); }
public AbstractRankerBolt(int topN, int emitFrequencyInSeconds) { if (topN < 1) { throw new IllegalArgumentException("topN must be >= 1 (you requested " + topN + ")"); } if (emitFrequencyInSeconds < 1) { throw new IllegalArgumentException( "The emit frequency must be >= 1 seconds (you requested " + emitFrequencyInSeconds + " seconds)"); } count = topN; this.emitFrequencyInSeconds = emitFrequencyInSeconds; rankings = new Rankings(count); }