use of backtype.storm.tuple.TupleImplExt in project jstorm by alibaba.
the class KryoTupleDeserializer method deserialize.
public Tuple deserialize(Input input) {
int targetTaskId = 0;
long timeStamp = 0l;
int taskId = 0;
int streamId = 0;
String componentName = null;
String streamName = null;
MessageId id = null;
boolean isBatchTuple = false;
try {
targetTaskId = input.readInt();
timeStamp = input.readLong();
isBatchTuple = input.readBoolean();
taskId = input.readInt(true);
streamId = input.readInt(true);
componentName = _context.getComponentId(taskId);
streamName = _ids.getStreamName(componentName, streamId);
List<Object> values = null;
if (isBatchTuple) {
values = new ArrayList<Object>();
int len = input.readInt(true);
if (_ackerNum > 0) {
for (int i = 0; i < len; i++) {
values.add(new Pair<MessageId, List<Object>>(MessageId.deserialize(input), _kryo.deserializeFrom(input)));
}
} else {
for (int i = 0; i < len; i++) {
values.add(new Pair<MessageId, List<Object>>(null, _kryo.deserializeFrom(input)));
}
}
} else {
id = MessageId.deserialize(input);
values = _kryo.deserializeFrom(input);
}
TupleImplExt tuple = new TupleImplExt(_context, values, taskId, streamName, id);
tuple.setBatchTuple(isBatchTuple);
tuple.setTargetTaskId(targetTaskId);
tuple.setCreationTimeStamp(timeStamp);
return tuple;
} catch (Exception e) {
StringBuilder sb = new StringBuilder();
sb.append("Deserialize error:");
sb.append("targetTaskId:").append(targetTaskId);
sb.append(",creationTimeStamp:").append(timeStamp);
sb.append(",isBatchTuple:").append(isBatchTuple);
sb.append(",taskId:").append(taskId);
sb.append(",streamId:").append(streamId);
sb.append(",componentName:").append(componentName);
sb.append(",streamName:").append(streamName);
sb.append(",MessageId").append(id);
LOG.error("Kryo error!!! {} {}", sb.toString(), e);
throw new RuntimeException(e);
}
}
use of backtype.storm.tuple.TupleImplExt in project jstorm by alibaba.
the class BoltBatchCollector method sendBatch.
public List<Integer> sendBatch(String outStreamId, String outTaskId, List<MsgInfo> batchTobeFlushed, boolean isFlush) {
final long start = emitTimer.getTime();
try {
Map<Object, List<MsgInfo>> outTasks = null;
if (outTaskId != null) {
outTasks = sendTargets.getBatch(Integer.valueOf(outTaskId), outStreamId, batchTobeFlushed);
} else {
outTasks = sendTargets.getBatch(outStreamId, batchTobeFlushed);
}
if (outTasks == null || outTasks.size() == 0) {
} else {
for (Map.Entry<Object, List<MsgInfo>> entry : outTasks.entrySet()) {
Object target = entry.getKey();
List<Integer> tasks = (target instanceof Integer) ? JStormUtils.mk_list((Integer) target) : ((List<Integer>) target);
List<MsgInfo> batch = entry.getValue();
for (Integer t : tasks) {
List<Object> batchValues = new ArrayList<Object>();
for (MsgInfo msg : batch) {
BoltMsgInfo msgInfo = (BoltMsgInfo) msg;
Pair<MessageId, List<Object>> pair = new Pair<MessageId, List<Object>>(getMessageId(msgInfo.anchors), msgInfo.values);
batchValues.add(pair);
}
TupleImplExt batchTuple = new TupleImplExt(topologyContext, batchValues, task_id, outStreamId, null);
batchTuple.setTargetTaskId(t);
batchTuple.setBatchTuple(true);
taskTransfer.transfer(batchTuple);
}
for (MsgInfo msg : batch) {
if (msg.callback != null) {
msg.callback.execute(outStreamId, tasks, msg.values);
}
}
}
}
for (MsgInfo msg : batchTobeFlushed) {
Collection<Tuple> anchors = ((BoltMsgInfo) msg).anchors;
if (anchors != null && anchors.size() > 0) {
for (Tuple a : anchors) {
synchronized (pendingTuples) {
Integer pendingCount = pendingTuples.get(a);
if (pendingCount != null) {
if (--pendingCount <= 0) {
pendingTuples.remove(a);
} else {
pendingTuples.put(a, pendingCount);
}
}
}
}
}
}
return null;
} catch (Exception e) {
LOG.error("bolt emit", e);
} finally {
emitTimer.updateTime(start);
}
return new ArrayList<Integer>();
}
use of backtype.storm.tuple.TupleImplExt in project jstorm by alibaba.
the class BoltCollector method sendCtrlMsg.
protected List<Integer> sendCtrlMsg(String out_stream_id, List<Object> values, Collection<Tuple> anchors, Integer out_task_id) {
final long start = emitTimer.getTime();
java.util.List<Integer> out_tasks = null;
try {
if (out_task_id != null) {
out_tasks = sendTargets.get(out_task_id, out_stream_id, values, anchors, null);
} else {
out_tasks = sendTargets.get(out_stream_id, values, anchors, null);
}
tryRotate();
for (Integer t : out_tasks) {
MessageId msgid = getMessageId(anchors);
TupleImplExt tp = new TupleImplExt(topologyContext, values, task_id, out_stream_id, msgid);
tp.setTargetTaskId(t);
transferCtr(tp);
}
} catch (Exception e) {
LOG.error("bolt emit", e);
} finally {
emitTimer.updateTime(start);
}
return out_tasks;
}
use of backtype.storm.tuple.TupleImplExt in project jstorm by alibaba.
the class BoltCollector method sendMsg.
public List<Integer> sendMsg(String out_stream_id, List<Object> values, Collection<Tuple> anchors, Integer out_task_id, ICollectorCallback callback) {
final long start = emitTimer.getTime();
List<Integer> outTasks = null;
try {
if (out_task_id != null) {
outTasks = sendTargets.get(out_task_id, out_stream_id, values, anchors, null);
} else {
outTasks = sendTargets.get(out_stream_id, values, anchors, null);
}
tryRotate();
for (Integer t : outTasks) {
MessageId msgid = getMessageId(anchors);
TupleImplExt tp = new TupleImplExt(topologyContext, values, task_id, out_stream_id, msgid);
tp.setTargetTaskId(t);
taskTransfer.transfer(tp);
}
} catch (Exception e) {
LOG.error("bolt emit", e);
} finally {
if (outTasks == null) {
outTasks = new ArrayList<Integer>();
}
if (callback != null)
callback.execute(out_stream_id, outTasks, values);
emitTimer.updateTime(start);
}
return outTasks;
}
use of backtype.storm.tuple.TupleImplExt in project jstorm by alibaba.
the class BoltExecutors method processTupleBatchEvent.
private void processTupleBatchEvent(Tuple tuple) {
try {
if ((!isSystemBolt && tuple.getSourceStreamId().equals(Common.TOPOLOGY_MASTER_CONTROL_STREAM_ID)) || tuple.getSourceStreamId().equals(Common.TOPOLOGY_MASTER_REGISTER_METRICS_RESP_STREAM_ID)) {
if (tuple.getValues().get(0) instanceof Pair) {
for (Object value : tuple.getValues()) {
Pair<MessageId, List<Object>> val = (Pair<MessageId, List<Object>>) value;
TupleImplExt t = new TupleImplExt(sysTopologyCtx, val.getSecond(), val.getFirst(), ((TupleImplExt) tuple));
processTupleEvent(t);
}
}
} else {
bolt.execute(tuple);
}
} catch (Throwable e) {
error = e;
LOG.error("bolt execute error ", e);
report_error.report(e);
}
}
Aggregations