Java Code Examples for storm.trident.tuple.TridentTuple#get()
The following examples show how to use
storm.trident.tuple.TridentTuple#get() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ScoreUpdater.java From storm-example with Apache License 2.0 | 6 votes |
@Override public void execute(TridentTuple tuple, TridentCollector collector) { Board board = (Board) tuple.get(0); int score = tuple.getInteger(1); String player = tuple.getString(2); String key = board.toKey(); LOG.debug("Got (" + board.toKey() + ") => [" + score + "] for [" + player + "]"); // Always compute things from X's perspective // We'll flip things when we interpret it if it is O's turn. synchronized (MUTEX) { Integer currentScore = scores.get(key); if (currentScore == null || (player.equals("X") && score > currentScore)) { updateScore(board, score); } else if (player.equals("O") && score > currentScore) { updateScore(board, score); } } }
Example 2
Source File: GenerateBoards.java From storm-example with Apache License 2.0 | 6 votes |
@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 + "]"); } }
Example 3
Source File: ScoreFunction.java From storm-example with Apache License 2.0 | 6 votes |
@Override public void execute(TridentTuple tuple, TridentCollector collector) { GameState gameState = (GameState) tuple.get(0); String player = gameState.getPlayer(); int score = gameState.score(); List<Object> values = new ArrayList<Object>(); values.add(gameState.getBoard()); values.add(score); values.add(player); collector.emit(values); for (Board b : gameState.getHistory()) { player = Player.next(player); values = new ArrayList<Object>(); values.add(b); values.add(score); values.add(player); collector.emit(values); } }
Example 4
Source File: isEndGame.java From storm-example with Apache License 2.0 | 5 votes |
@Override public boolean isKeep(TridentTuple tuple) { GameState gameState = (GameState) tuple.get(0); boolean keep = (gameState.getBoard().isEndState()); if (keep) { LOG.info("END GAME [" + gameState + "]"); } return keep; }
Example 5
Source File: FindBestMove.java From storm-example with Apache License 2.0 | 5 votes |
@Override public void aggregate(BestMove currentBestMove, TridentTuple tuple, TridentCollector collector) { Board board = (Board) tuple.get(0); Integer score = tuple.getInteger(1); if (score > currentBestMove.score) { currentBestMove.score = score; currentBestMove.bestMove = board; } }
Example 6
Source File: ExtractLocation.java From trident-tutorial with Apache License 2.0 | 5 votes |
@Override public void execute(TridentTuple tuple, TridentCollector collector) { Status status = (Status) tuple.get(0); Content content = (Content) tuple.get(1); collector.emit(new Values(status.getPlace().getCountryCode(), content.getContentName())); }
Example 7
Source File: LocalQueuerFunction.java From storm-example with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Override public void execute(TridentTuple tuple, TridentCollector collector) { T object = (T) tuple.get(0); Log.debug("Queueing [" + object + "]"); this.emitter.enqueue(object); }
Example 8
Source File: ExtractFollowerClassAndContentName.java From trident-tutorial with Apache License 2.0 | 5 votes |
@Override public void execute(TridentTuple tuple, TridentCollector collector) { Content content = (Content)tuple.get(0); User user = (User)tuple.get(1); String followerClass = classify(user.getFollowersCount()); collector.emit(new Values(followerClass, content.getContentName())); }
Example 9
Source File: WithDefaultValue.java From trident-tutorial with Apache License 2.0 | 5 votes |
@Override public void execute(TridentTuple tuple, TridentCollector collector) { if(tuple.get(0) == null){ collector.emit(new Values(t)); }else{ collector.emit(new Values(tuple.get(0))); } }
Example 10
Source File: ParseTweet.java From trident-tutorial with Apache License 2.0 | 5 votes |
@Override public void execute(TridentTuple tuple, TridentCollector collector) { if(extracter == null) extracter = new ContentExtracter(); String rawTweetJson = (String)tuple.get(0); Status parsed = parse(rawTweetJson); User user = parsed.getUser(); for (Content content : extracter.extract(parsed)) { collector.emit(new Values(parsed, content, user)); } }
Example 11
Source File: Part02_AdvancedPrimitives1.java From trident-tutorial with Apache License 2.0 | 5 votes |
@Override public void execute(TridentTuple tuple, TridentCollector collector) { Map<String,Integer> val = (Map<String,Integer>)tuple.get(0); Map<String,Integer> ret = new HashMap<String, Integer>(); for (Map.Entry<String, Integer> e : val.entrySet()) { ret.put(e.getKey(), e.getValue() * 10); } collector.emit(new Values(ret)); }
Example 12
Source File: TridentMinMaxOfVehiclesTest.java From jstorm with Apache License 2.0 | 4 votes |
@Override public void accept(TridentTuple input) { Vehicle vehicle = (Vehicle) input.get(0); assertEquals(efficiency, vehicle.getEfficiency(), 0); }
Example 13
Source File: TridentMinMaxOfVehiclesTest.java From jstorm with Apache License 2.0 | 4 votes |
@Override public void accept(TridentTuple input) { Vehicle vehicle = (Vehicle) input.get(0); assertEquals(speed, vehicle.getSpeed()); }
Example 14
Source File: Part02_AdvancedPrimitives1.java From trident-tutorial with Apache License 2.0 | 4 votes |
@Override public boolean isKeep(TridentTuple tuple) { Map<String,Integer> val = (Map<String,Integer>)tuple.get(0); return val != null && val.keySet().contains("Spain"); }
Example 15
Source File: OnlyGeo.java From trident-tutorial with Apache License 2.0 | 4 votes |
@Override public boolean isKeep(TridentTuple tuple) { Status status = (Status) tuple.get(0); return !(null == status.getPlace() || null == status.getPlace().getCountryCode()); }
Example 16
Source File: DivideAsDouble.java From trident-tutorial with Apache License 2.0 | 4 votes |
@Override public void execute(TridentTuple tuple, TridentCollector collector) { Number n1 = (Number)tuple.get(0); Number n2 = (Number)tuple.get(1); collector.emit(new Values(n1.doubleValue() / n2.doubleValue())); }
Example 17
Source File: OnlyHashtags.java From trident-tutorial with Apache License 2.0 | 4 votes |
@Override public boolean isKeep(TridentTuple tuple) { Content content = (Content)tuple.get(0); return "hashtag".equals(content.getContentType()); }
Example 18
Source File: OnlyEnglish.java From trident-tutorial with Apache License 2.0 | 4 votes |
@Override public boolean isKeep(TridentTuple tuple) { User user = (User)tuple.get(0); return "en".equals(user.getLang()); }