@Override public void nextTuple() { Utils.sleep(100); String[] sentences = new String[] { "the cow jumped over the moon", "an apple a day keeps the doctor away", "four score and seven years ago", "snow white and the seven dwarfs", "i am at two with nature" }; String sentence = sentences[_rand.nextInt(sentences.length)]; _collector.emit(new Values(sentence)); }
public Values(Object... vals) { super(vals.length); for (Object o : vals) { add(o); } type = OBJECT; }
@Override 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)); }
@Override public List<Integer> emit(String ignore, List<Object> values, Object msgId) { long batchIdVal = _rand.nextLong(); Object batchId = new RichSpoutBatchId(batchIdVal); FinishCondition finish = new FinishCondition(); finish.msgId = msgId; List<Integer> tasks = new ArrayList<>(); _collector.emit(_stream, new ConsList(batchId, values), new CollectorCb(tasks)); _collector.flush(); Set<Integer> outTasksSet = new HashSet<>(tasks); for(Integer t: _outputTasks) { int count = 0; if(outTasksSet.contains(t)) { count = 1; } long r = _rand.nextLong(); _collector.emitDirect(t, _coordStream, new Values(batchId, count), r); finish.vals.add(r); _msgIdToBatchId.put(r, batchIdVal); } _finishConditions.put(batchIdVal, finish); return tasks; }
private void sync() { // note that sometimes the tuples active may be less than max_spout_pending, e.g. // max_spout_pending = 3 // tx 1, 2, 3 active, tx 2 is acked. there won't be a commit for tx 2 (because tx 1 isn't committed yet), // and there won't be a batch for tx 4 because there's max_spout_pending tx active TransactionStatus maybeCommit = _activeTx.get(_currTransaction); if (maybeCommit != null && maybeCommit.status == AttemptStatus.PROCESSED) { maybeCommit.status = AttemptStatus.COMMITTING; LOG.debug("send commit stream {}", maybeCommit); _collector.emit(TRANSACTION_COMMIT_STREAM_ID, new Values(maybeCommit.attempt), maybeCommit.attempt); } try { if (_activeTx.size() < _maxTransactionActive) { BigInteger curr = _currTransaction; for (int i = 0; i < _maxTransactionActive; i++) { if ((_coordinatorState.hasCache(curr) || _coordinator.isReady()) && !_activeTx.containsKey(curr)) { TransactionAttempt attempt = new TransactionAttempt(curr, _rand.nextLong()); Object state = _coordinatorState.getState(curr, _initializer); _activeTx.put(curr, new TransactionStatus(attempt)); LOG.debug("send batch stream {}", attempt); _collector.emit(TRANSACTION_BATCH_STREAM_ID, new Values(attempt, state, previousTransactionId(_currTransaction)), attempt); } curr = nextTransactionId(curr); } } } catch (FailedException e) { LOG.warn("Failed to get metadata for a transaction", e); } }
@Override public void emitBatch(long batchId, TridentCollector collector) { for (int i = 0; i < this.maxBatchSize; i++) { Values values = new Values(); double[] features = new double[this.featureSize]; for (int j = 0; j < this.featureSize; j++) { features[j] = j + this.random.nextGaussian() * this.variance; } if (this.withLabel) { values.add(FEATURES_TO_LABEL.apply(features)); } for (double feature : features) { values.add(feature); } collector.emit(values); } }
@Override public void execute(Tuple tuple) { String sourceIp = tuple.getString(1); Integer sourcePort = tuple.getInteger(2); if (differentNode) { if (ip.equals(sourceIp)) { fail(tuple, _collector); return; } else if (port.equals(sourcePort)) { fail(tuple, _collector); return; } _collector.emit(tuple, new Values(tuple.getValue(0), ip, port)); _collector.ack(tuple); return; } else { if (ip.equals(sourceIp) == false) { fail(tuple, _collector); return; } _collector.emit(tuple, new Values(tuple.getValue(0), ip, port)); _collector.ack(tuple); } }
returnInfo.put("port", client.getPort()); gotRequest = true; _collector.emit(new Values(req.get_func_args(), JSONValue.toJSONString(returnInfo)), new DRPCMessageId(req.get_request_id(), i)); break; returnInfo.put("port", 0); gotRequest = true; _collector.emit(new Values(req.get_func_args(), JSONValue.toJSONString(returnInfo)), new DRPCMessageId(req.get_request_id(), 0)); Utils.sleep(1);
public void execute(Tuple tuple) { Object requestId = tuple.getValue(0); if (tuple.getSourceComponent().equals(returnComponent)) { returns.put(requestId, tuple); } else { results.put(requestId, tuple); } if (returns.containsKey(requestId) && results.containsKey(requestId)) { Tuple result = results.remove(requestId); Tuple returner = returns.remove(requestId); LOG.debug(result.getValue(1).toString()); List<Tuple> anchors = new ArrayList<>(); anchors.add(result); anchors.add(returner); _collector.emit(anchors, new Values("" + result.getValue(1), returner.getValue(1))); _collector.ack(result); _collector.ack(returner); } }
@Override public void execute(Tuple tuple) { _rootLogger.debug("root: This is a DEBUG message"); _rootLogger.info("root: This is an INFO message"); _rootLogger.warn("root: This is a WARN message"); _rootLogger.error("root: This is an ERROR message"); _logger.debug("myapp: This is a DEBUG message"); _logger.info("myapp: This is an INFO message"); _logger.warn("myapp: This is a WARN message"); _logger.error("myapp: This is an ERROR message"); _subLogger.debug("myapp.sub: This is a DEBUG message"); _subLogger.info("myapp.sub: This is an INFO message"); _subLogger.warn("myapp.sub: This is a WARN message"); _subLogger.error("myapp.sub: This is an ERROR message"); _collector.emit(tuple, new Values(tuple.getString(0) + "!!!")); _collector.ack(tuple); counter.incrementAndGet(); }
public void execute(Tuple input) { Integer sourceId = input.getInteger(0); Long eventId = input.getLong(1); Long recentEvent = recentEventId.get(sourceId); if (null != recentEvent && eventId <= recentEvent) { String error = "Error: event id is not in strict order! event source Id: " + sourceId + ", last event Id: " + recentEvent + ", current event Id: " + eventId; _collector.emit(input, new Values(error)); } recentEventId.put(sourceId, eventId); _collector.ack(input); }
@Override public void execute(Tuple tuple) { Object obj = tuple.getValue(0); long count = tuple.getLong(1); int source = tuple.getSourceTask(); Map<Integer, Long> subCounts = counts.get(obj); if (subCounts == null) { subCounts = new HashMap<Integer, Long>(); counts.put(obj, subCounts); } // Update the current count for this object subCounts.put(source, count); // Output the sum of all the known counts so for this key long sum = 0; for (Long val : subCounts.values()) { sum += val; } collector.emit(new Values(obj, sum)); }