use of backtype.storm.tuple.Tuple in project jstorm by alibaba.
the class BoltExecutors method onEvent.
@Override
public void onEvent(Object event, long sequence, boolean endOfBatch) throws Exception {
if (event == null) {
return;
}
long start = System.currentTimeMillis();
try {
if (event instanceof Tuple) {
Tuple tuple = (Tuple) event;
int tupleNum = 1;
Long startTime = System.currentTimeMillis();
long lifeCycleStart = ((TupleExt) tuple).getCreationTimeStamp();
task_stats.tupleLifeCycle(tuple.getSourceComponent(), tuple.getSourceStreamId(), lifeCycleStart, startTime);
if (((TupleExt) tuple).isBatchTuple()) {
List<Object> values = ((Tuple) event).getValues();
tupleNum = values.size();
if (bolt instanceof IRichBatchBolt) {
processControlEvent();
processTupleBatchEvent(tuple);
} else {
for (Object value : values) {
Pair<MessageId, List<Object>> val = (Pair<MessageId, List<Object>>) value;
TupleImplExt t = new TupleImplExt(sysTopologyCtx, val.getSecond(), val.getFirst(), ((TupleImplExt) event));
processControlEvent();
processTupleEvent(t);
}
}
} else {
processTupleEvent(tuple);
}
task_stats.recv_tuple(tuple.getSourceComponent(), tuple.getSourceStreamId(), tupleNum);
if (ackerNum == 0) {
// get tuple process latency
if (JStormMetrics.enabled) {
long endTime = System.currentTimeMillis();
task_stats.update_bolt_acked_latency(tuple.getSourceComponent(), tuple.getSourceStreamId(), startTime, endTime, tupleNum);
}
}
} else if (event instanceof TimerTrigger.TimerEvent) {
processTimerEvent((TimerTrigger.TimerEvent) event);
} else {
LOG.warn("Bolt executor received unknown message");
}
} finally {
if (JStormMetrics.enabled) {
exeTime = System.currentTimeMillis() - start;
}
}
}
use of backtype.storm.tuple.Tuple in project jstorm by alibaba.
the class CtrlEventDispatcher method process.
@Override
public void process(Object event) throws Exception {
if (event instanceof UpdateConfigEvent) {
update(((UpdateConfigEvent) event).getConf());
return;
}
Tuple input = (Tuple) event;
TopoMasterCtrlEvent ctlEvent = (TopoMasterCtrlEvent) input.getValues().get(0);
if (ctlEvent != null) {
if (ctlEvent.isTransactionEvent()) {
snapshotStateMaster.process(input);
} else {
String errorInfo = "Received unexpected control event, {}" + event.toString();
LOG.warn(errorInfo);
zkCluster.report_task_error(context.getTopologyId(), context.getThisTaskId(), errorInfo, ErrorConstants.WARN, ErrorConstants.CODE_USER);
}
}
}
use of backtype.storm.tuple.Tuple in project jstorm by alibaba.
the class TaskHeartbeatUpdater method process.
@Override
public void process(Object event) throws Exception {
synchronized (_lock) {
if (event instanceof UpdateConfigEvent) {
update(((UpdateConfigEvent) event).getConf());
return;
}
Tuple input = (Tuple) event;
int sourceTask = input.getSourceTask();
int uptime = (Integer) input.getValue(0);
TaskStatus executorStatus = new TaskStatus();
if (input.getValues().size() < 2) {
// for compatibility
executorStatus.setStatus(TaskStatus.RUN);
} else {
executorStatus.setStatus((byte) input.getValue(1));
}
boolean isSendSpoutTaskFinishStream = false;
if (spoutsExecutorStatusMap.containsKey(sourceTask)) {
spoutsExecutorStatusMap.put(sourceTask, executorStatus);
} else if (boltsExecutorStatusMap.containsKey(sourceTask)) {
boltsExecutorStatusMap.put(sourceTask, executorStatus);
} else if (sourceTask != taskId) {
LOG.warn("received invalid task heartbeat {}", input);
}
if (executorStatus.getStatus() == TaskStatus.INIT && spoutsExecutorStatusMap.get(sourceTask) != null) {
boolean existInitStatusBolt = false;
for (TaskStatus status : boltsExecutorStatusMap.values()) {
if (status.getStatus() == TaskStatus.INIT || status.getStatus() == TaskStatus.SHUTDOWN) {
existInitStatusBolt = true;
break;
}
}
if (!existInitStatusBolt)
isSendSpoutTaskFinishStream = true;
}
if (client == null) {
client = new NimbusClientWrapper();
client.init(stormConf);
}
// Update the heartbeat for source task, but don't update it if task is initial status
if (executorStatus.getStatus() != TaskStatus.INIT && uptime > 0) {
TaskHeartbeat taskHb = taskHbMap.get().get(sourceTask);
if (taskHb == null) {
taskHb = new TaskHeartbeat(TimeUtils.current_time_secs(), uptime);
TaskHeartbeat tmpTaskHb = taskHbMap.get().putIfAbsent(sourceTask, taskHb);
if (tmpTaskHb != null) {
taskHb = tmpTaskHb;
}
}
taskHb.set_time(TimeUtils.current_time_secs());
taskHb.set_uptime(uptime);
} else if (isSendSpoutTaskFinishStream) {
TopoMasterCtrlEvent finishInitEvent = new TopoMasterCtrlEvent(TopoMasterCtrlEvent.EventType.topologyFinishInit);
((BoltCollector) (collector.getDelegate())).emitDirectCtrl(sourceTask, Common.TOPOLOGY_MASTER_CONTROL_STREAM_ID, null, new Values(finishInitEvent));
LOG.info("all bolts' task finish init operation, so tm will notify the spout task-{}", sourceTask);
}
// Send heartbeat info of all tasks to nimbus
if (sourceTask == taskId) {
uploadHB();
}
}
}
use of backtype.storm.tuple.Tuple in project jstorm by alibaba.
the class MetricsUpdater method process.
@Override
public void process(Object event) {
Tuple input = (Tuple) event;
updateMetrics(input);
}
use of backtype.storm.tuple.Tuple 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);
}
}
}
Aggregations