use of backtype.storm.tuple.MessageId in project jstorm by alibaba.
the class SpoutCollector method sendMsg.
public List<Integer> sendMsg(String out_stream_id, List<Object> values, Object message_id, Integer out_task_id, ICollectorCallback callback) {
final long startTime = emitTotalTimer.getTime();
try {
boolean needAck = (message_id != null) && (ackerNum > 0);
Long root_id = getRootId(message_id);
List<Integer> outTasks = null;
if (out_task_id != null) {
outTasks = sendTargets.get(out_task_id, out_stream_id, values, null, root_id);
} else {
outTasks = sendTargets.get(out_stream_id, values, null, root_id);
}
List<Long> ackSeq = new ArrayList<Long>();
for (Integer t : outTasks) {
MessageId msgid;
if (needAck) {
// Long as = MessageId.generateId();
Long as = MessageId.generateId(random);
msgid = MessageId.makeRootId(root_id, as);
ackSeq.add(as);
} else {
msgid = null;
}
TupleImplExt tp = new TupleImplExt(topology_context, values, task_id, out_stream_id, msgid);
tp.setTargetTaskId(t);
transfer_fn.transfer(tp);
}
sendMsgToAck(out_stream_id, values, message_id, root_id, ackSeq, needAck);
if (callback != null)
callback.execute(out_stream_id, outTasks, values);
return outTasks;
} finally {
emitTotalTimer.updateTime(startTime);
}
}
use of backtype.storm.tuple.MessageId in project jstorm by alibaba.
the class SpoutExecutors method onEvent.
/**
* Handle acker message
*
* @see com.lmax.disruptor.EventHandler#onEvent(java.lang.Object, long, boolean)
*/
@Override
public void onEvent(Object event, long sequence, boolean endOfBatch) throws Exception {
try {
if (event == null) {
return;
}
Runnable runnable = null;
if (event instanceof Tuple) {
if (((TupleExt) event).isBatchTuple()) {
List<Object> values = ((Tuple) event).getValues();
for (Object value : values) {
Pair<MessageId, List<Object>> val = (Pair<MessageId, List<Object>>) value;
TupleImplExt tuple = new TupleImplExt(sysTopologyCtx, val.getSecond(), val.getFirst(), ((TupleImplExt) event));
processControlEvent();
runnable = processTupleEvent(tuple);
if (runnable != null) {
runnable.run();
runnable = null;
}
}
} else {
runnable = processTupleEvent((Tuple) event);
}
} else if (event instanceof TimerTrigger.TimerEvent) {
processTimerEvent((TimerTrigger.TimerEvent) event);
return;
} else if (event instanceof IAckMsg) {
runnable = (Runnable) event;
} else if (event instanceof Runnable) {
runnable = (Runnable) event;
} else {
LOG.warn("Receive one unknow event-" + event.toString() + " " + idStr);
return;
}
if (runnable != null)
runnable.run();
} catch (Throwable e) {
if (!taskStatus.isShutdown()) {
LOG.info("Unknow excpetion ", e);
report_error.report(e);
}
}
}
use of backtype.storm.tuple.MessageId in project jstorm by alibaba.
the class KryoTupleSerializer method serializeTuple.
/**
* @@@ in the furture, it will skill serialize 'targetTask' through check some flag
* @see backtype.storm.serialization.ITupleSerializer#serialize(int, backtype.storm.tuple.Tuple)
*/
private void serializeTuple(Output output, Tuple tuple) {
try {
boolean isBatchTuple = false;
if (tuple instanceof TupleExt) {
output.writeInt(((TupleExt) tuple).getTargetTaskId());
output.writeLong(((TupleExt) tuple).getCreationTimeStamp());
output.writeBoolean(((TupleExt) tuple).isBatchTuple());
isBatchTuple = ((TupleExt) tuple).isBatchTuple();
}
output.writeInt(tuple.getSourceTask(), true);
output.writeInt(_ids.getStreamId(tuple.getSourceComponent(), tuple.getSourceStreamId()), true);
if (isBatchTuple) {
List<Object> values = tuple.getValues();
int len = values.size();
output.writeInt(len, true);
if (_ackerNum > 0) {
for (Object value : values) {
Pair<MessageId, List<Object>> pairValue = (Pair<MessageId, List<Object>>) value;
if (pairValue.getFirst() != null) {
pairValue.getFirst().serialize(output);
} else {
output.writeInt(0, true);
}
_kryo.serializeInto(pairValue.getSecond(), output);
}
} else {
for (Object value : values) {
Pair<MessageId, List<Object>> pairValue = (Pair<MessageId, List<Object>>) value;
_kryo.serializeInto(pairValue.getSecond(), output);
}
}
} else {
MessageId msgId = tuple.getMessageId();
if (msgId != null) {
msgId.serialize(output);
} else {
output.writeInt(0, true);
}
_kryo.serializeInto(tuple.getValues(), output);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of backtype.storm.tuple.MessageId in project jstorm by alibaba.
the class SpoutCollector method sendCtrlMsg.
protected List<Integer> sendCtrlMsg(String out_stream_id, List<Object> values, Object message_id, Integer out_task_id) {
final long startTime = emitTotalTimer.getTime();
try {
boolean needAck = (message_id != null) && (ackerNum > 0);
Long root_id = getRootId(message_id);
java.util.List<Integer> out_tasks = null;
if (out_task_id != null) {
out_tasks = sendTargets.get(out_task_id, out_stream_id, values, null, root_id);
} else {
out_tasks = sendTargets.get(out_stream_id, values, null, root_id);
}
List<Long> ackSeq = new ArrayList<Long>();
for (Integer t : out_tasks) {
MessageId msgid;
if (needAck) {
// Long as = MessageId.generateId();
Long as = MessageId.generateId(random);
msgid = MessageId.makeRootId(root_id, as);
ackSeq.add(as);
} else {
msgid = null;
}
TupleImplExt tp = new TupleImplExt(topology_context, values, task_id, out_stream_id, msgid);
tp.setTargetTaskId(t);
transferCtr(tp);
}
sendMsgToAck(out_stream_id, values, message_id, root_id, ackSeq, needAck);
return out_tasks;
} finally {
emitTotalTimer.updateTime(startTime);
}
}
use of backtype.storm.tuple.MessageId in project storm by nathanmarz.
the class KryoTupleDeserializer method deserialize.
public Tuple deserialize(byte[] ser) {
try {
_kryoInput.setBuffer(ser);
int taskId = _kryoInput.readInt(true);
int streamId = _kryoInput.readInt(true);
String componentName = _context.getComponentId(taskId);
String streamName = _ids.getStreamName(componentName, streamId);
MessageId id = MessageId.deserialize(_kryoInput);
List<Object> values = _kryo.deserializeFrom(_kryoInput);
return new TupleImpl(_context, values, taskId, streamName, id);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
Aggregations