use of com.yahoo.bullet.pubsub.Metadata in project bullet-storm by yahoo.
the class JoinBolt method onQuery.
private void onQuery(Tuple tuple) {
String id = tuple.getString(TopologyConstants.ID_POSITION);
String query = tuple.getString(TopologyConstants.QUERY_POSITION);
Metadata metadata = (Metadata) tuple.getValue(TopologyConstants.QUERY_METADATA_POSITION);
Querier querier;
try {
querier = createQuerier(Querier.Mode.ALL, id, query, config);
Optional<List<BulletError>> optionalErrors = querier.initialize();
if (!optionalErrors.isPresent()) {
setupQuery(id, query, metadata, querier);
return;
}
emitErrorsAsResult(id, metadata, optionalErrors.get());
} catch (RuntimeException re) {
// Includes JSONParseException
emitErrorsAsResult(id, metadata, ParsingError.makeError(re, query));
}
log.error("Failed to initialize query for request {} with query {}", id, query);
}
use of com.yahoo.bullet.pubsub.Metadata in project bullet-storm by yahoo.
the class JoinBolt method emitMetaSignal.
// METADATA_STREAM emitters
private void emitMetaSignal(String id, Metadata.Signal signal) {
log.error("Emitting {} signal to the feedback stream for {}", signal, id);
collector.emit(FEEDBACK_STREAM, new Values(id, new Metadata(signal, null)));
}
use of com.yahoo.bullet.pubsub.Metadata in project bullet-storm by yahoo.
the class LoopBolt method execute.
@Override
public void execute(Tuple tuple) {
String id = tuple.getString(TopologyConstants.ID_POSITION);
Metadata metadata = (Metadata) tuple.getValue(TopologyConstants.METADATA_POSITION);
log.info("Looping back metadata with signal {} for {}", metadata.getSignal(), id);
publish(new PubSubMessage(id, null, metadata), tuple);
}
use of com.yahoo.bullet.pubsub.Metadata in project bullet-storm by yahoo.
the class ResultBolt method execute.
@Override
public void execute(Tuple tuple) {
String id = tuple.getString(TopologyConstants.ID_POSITION);
String result = tuple.getString(TopologyConstants.RESULT_POSITION);
Metadata metadata = (Metadata) tuple.getValue(TopologyConstants.RESULT_METADATA_POSITION);
publish(new PubSubMessage(id, result, metadata), tuple);
}
use of com.yahoo.bullet.pubsub.Metadata in project bullet-storm by yahoo.
the class DRPCQuerySubscriber method getMessages.
@Override
public List<PubSubMessage> getMessages() throws PubSubException {
// Try and read from DRPC. The DRPCSpout does a sleep for 1 ms if there are no tuples, so we don't have to do it.
spout.nextTuple();
if (!collector.haveOutput()) {
return null;
}
// The DRPCSpout only should have emitted one tuple
List<List<Object>> tuples = collector.reset();
log.debug("Have a message through DRPC {}", tuples);
List<Object> tupleAndID = tuples.get(0);
// The first object is the actual DRPCSpout tuple and the second is the DRPC messageID.
List<Object> tuple = (List<Object>) tupleAndID.get(0);
Object drpcID = tupleAndID.get(1);
// The first object in the tuple is our PubSubMessage as JSON
String pubSubMessageJSON = (String) tuple.get(0);
// The second object in the tuple is the serialized returnInfo added by the DRPCSpout
String returnInfo = (String) tuple.get(1);
log.debug("Read message\n{}\nfrom DRPC with return information {}", pubSubMessageJSON, returnInfo);
PubSubMessage pubSubMessage = PubSubMessage.fromJSON(pubSubMessageJSON);
// Add returnInfo as metadata. Cannot add it to pubSubMessage
String id = pubSubMessage.getId();
String content = pubSubMessage.getContent();
int sequence = pubSubMessage.getSequence();
PubSubMessage message = new PubSubMessage(id, content, new Metadata(null, returnInfo), sequence);
emittedIDs.put(ImmutablePair.of(id, sequence), drpcID);
return Collections.singletonList(message);
}
Aggregations