@SuppressWarnings("unchecked") @Override public T apply(Tuple input) { return (T) input.getValue(index); } }
@Override public ByteBuffer getMessageFromTuple(Tuple tuple) { return serializer.write((Values) tuple.getValue(1), null); } }
/** * AvroGenericRecordBolt must override this method because messages with different schemas cannot be written to the * same file. By treating the complete schema as the "key" AbstractHdfsBolt will associate a different writer for * every distinct schema. */ @Override protected String getWriterKey(Tuple tuple) { Schema recordSchema = ((GenericRecord) tuple.getValue(0)).getSchema(); return recordSchema.toString(); }
@Override protected AbstractHDFSWriter makeNewWriter(Path path, Tuple tuple) throws IOException { Schema recordSchema = ((GenericRecord) tuple.getValue(0)).getSchema(); return new AvroGenericRecordHDFSWriter(this.rotationPolicy, path, this.fs.create(path), recordSchema); } }
@Override public void execute(Tuple input) { IMetricsConsumer.TaskInfo taskInfo = (IMetricsConsumer.TaskInfo) input.getValue(0); Collection<IMetricsConsumer.DataPoint> dataPoints = (Collection) input.getValue(1); Collection<IMetricsConsumer.DataPoint> expandedDataPoints = _expander.expandDataPoints(dataPoints); List<IMetricsConsumer.DataPoint> filteredDataPoints = getFilteredDataPoints(expandedDataPoints); MetricsTask metricsTask = new MetricsTask(taskInfo, filteredDataPoints); while (!_taskQueue.offer(metricsTask)) { _taskQueue.poll(); } _collector.ack(input); }
@Override public void execute(Tuple tuple) { log.info("Received tuple : {}", tuple.getValue(0)); count++; if (count == 3) { collector.fail(tuple); } else { collector.ack(tuple); } }
public void fail(Tuple tuple) { Object id = tuple.getValue(0); synchronized (_tracked) { TrackingInfo track = _tracked.get(id); if (track != null) { track.failed = true; } } checkFinishId(tuple, TupleType.REGULAR); _delegate.fail(tuple); }
private void countObjAndAck(Tuple tuple) { Object obj = tuple.getValue(0); counter.incrementCount(obj); collector.ack(tuple); }
@Override public Values apply(Tuple input) { Values values = new Values(); for (int i : indices) { values.add(input.getValue(i)); } return values; } }
@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)); } } }
@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 protected void doWrite(Tuple tuple) throws IOException { GenericRecord avroRecord = (GenericRecord) tuple.getValue(0); avroWriter.append(avroRecord); offset = this.out.getPos(); this.needsRotation = this.rotationPolicy.mark(tuple, offset); }
@Override public void execute(Tuple tuple, BasicOutputCollector collector) { String arg = tuple.getString(0); Object retInfo = tuple.getValue(1); collector.emit(new Values(arg + "!!!", retInfo)); }
@Override public void execute(Tuple input) { Object id = input.getValue(0); IBatchBolt bolt = getBatchBolt(id); try { bolt.execute(input); _collector.ack(input); } catch (FailedException e) { LOG.error("Failed to process tuple in batch", e); _collector.fail(input); } }
private void setUpPunctuation(Tuple punctuation) { Mockito.when(punctuation.size()).thenReturn(1); Mockito.when(punctuation.getValue(0)).thenReturn(WindowNode.PUNCTUATION); Mockito.when(punctuation.getSourceComponent()).thenReturn("bolt0"); Mockito.when(punctuation.getSourceStreamId()).thenReturn("inputstream"); } }
private void setUpMockTuples(Tuple... tuples) { for (Tuple tuple : tuples) { Mockito.when(tuple.size()).thenReturn(1); Mockito.when(tuple.getValue(0)).thenReturn(100); Mockito.when(tuple.getSourceComponent()).thenReturn("bolt0"); Mockito.when(tuple.getSourceStreamId()).thenReturn("inputstream"); } }
private void setUpMockTuples(Tuple... tuples) { for (Tuple tuple : tuples) { Mockito.when(tuple.size()).thenReturn(1); Mockito.when(tuple.getValue(0)).thenReturn(Pair.of("k", "v")); Mockito.when(tuple.getSourceComponent()).thenReturn("bolt0"); Mockito.when(tuple.getSourceStreamId()).thenReturn("inputstream"); } } }