use of com.alibaba.jstorm.callback.AsyncLoopThread in project jstorm by alibaba.
the class Worker method startDispatchThread.
private AsyncLoopThread startDispatchThread() {
// send tuple directly from netty server
// send control tuple to dispatch thread
// startDispatchDisruptor();
IContext context = workerData.getContext();
String topologyId = workerData.getTopologyId();
//create recv connection
Map stormConf = workerData.getStormConf();
long timeout = JStormUtils.parseLong(stormConf.get(Config.TOPOLOGY_DISRUPTOR_WAIT_TIMEOUT), 10);
WaitStrategy waitStrategy = new TimeoutBlockingWaitStrategy(timeout, TimeUnit.MILLISECONDS);
int queueSize = JStormUtils.parseInt(stormConf.get(Config.TOPOLOGY_CTRL_BUFFER_SIZE), 256);
DisruptorQueue recvControlQueue = DisruptorQueue.mkInstance("Dispatch-control", ProducerType.MULTI, queueSize, waitStrategy, false, 0, 0);
//metric for recvControlQueue
QueueGauge revCtrlGauge = new QueueGauge(recvControlQueue, MetricDef.RECV_CTRL_QUEUE);
JStormMetrics.registerWorkerMetric(JStormMetrics.workerMetricName(MetricDef.RECV_CTRL_QUEUE, MetricType.GAUGE), new AsmGauge(revCtrlGauge));
IConnection recvConnection = context.bind(topologyId, workerData.getPort(), workerData.getDeserializeQueues(), recvControlQueue, false, workerData.getTaskids());
workerData.setRecvConnection(recvConnection);
// create recvice control messages's thread
RunnableCallback recvControlDispather = new VirtualPortCtrlDispatch(workerData, recvConnection, recvControlQueue, MetricDef.RECV_THREAD);
return new AsyncLoopThread(recvControlDispather, false, Thread.MAX_PRIORITY, true);
}
use of com.alibaba.jstorm.callback.AsyncLoopThread in project jstorm by alibaba.
the class WorkerData method setDeserializeThreads.
protected List<AsyncLoopThread> setDeserializeThreads() {
WorkerTopologyContext workerTopologyContext = contextMaker.makeWorkerTopologyContext(sysTopology);
int tasksNum = shutdownTasks.size();
double workerRatio = ConfigExtension.getWorkerDeserializeThreadRatio(stormConf);
int workerDeseriaThreadNum = Utils.getInt(Math.ceil(workerRatio * tasksNum));
if (workerDeseriaThreadNum > 0 && tasksNum > 0) {
double average = tasksNum / (double) workerDeseriaThreadNum;
for (int i = 0; i < workerDeseriaThreadNum; i++) {
int startRunTaskIndex = Utils.getInt(Math.rint(average * i));
deserializeThreads.add(new AsyncLoopThread(new WorkerDeserializeRunnable(shutdownTasks, stormConf, workerTopologyContext, startRunTaskIndex, i)));
}
}
return deserializeThreads;
}
use of com.alibaba.jstorm.callback.AsyncLoopThread in project jstorm by alibaba.
the class TaskShutdownDameon method shutdown.
@Override
public void shutdown() {
if (isClosing.compareAndSet(false, true)) {
LOG.info("Begin to shut down task " + topology_id + ":" + task_id);
TopologyContext userContext = task.getUserContext();
for (ITaskHook iTaskHook : userContext.getHooks()) iTaskHook.cleanup();
closeComponent(task_obj);
taskHeartbeatTrigger.updateExecutorStatus(TaskStatus.SHUTDOWN);
// To be assure send the shutdown information TM
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
// all thread will check the taskStatus
// once it has been set SHUTDOWN, it will quit
taskStatus.setStatus(TaskStatus.SHUTDOWN);
for (AsyncLoopThread thr : all_threads) {
LOG.info("Begin to shutdown " + thr.getThread().getName());
thr.cleanup();
JStormUtils.sleepMs(10);
thr.interrupt();
// try {
// //thr.join();
// thr.getThread().stop(new RuntimeException());
// } catch (Throwable e) {
// }
LOG.info("Successfully shutdown " + thr.getThread().getName());
}
try {
zkCluster.disconnect();
} catch (Exception e) {
LOG.error("Failed to disconnect zk for task-" + task_id);
}
LOG.info("Successfully shutdown task " + topology_id + ":" + task_id);
}
}
use of com.alibaba.jstorm.callback.AsyncLoopThread in project jstorm by alibaba.
the class Drpc method initClearThread.
private void initClearThread() {
clearThread = new AsyncLoopThread(new ClearThread(this));
LOG.info("Successfully start clear thread");
}
use of com.alibaba.jstorm.callback.AsyncLoopThread in project jstorm by alibaba.
the class Task method getShutdown.
public TaskShutdownDameon getShutdown(List<AsyncLoopThread> allThreads, RunnableCallback baseExecutor) {
AsyncLoopThread ackerThread = null;
if (baseExecutor instanceof SpoutExecutors) {
ackerThread = ((SpoutExecutors) baseExecutor).getAckerRunnableThread();
if (ackerThread != null) {
allThreads.add(ackerThread);
}
}
List<AsyncLoopThread> recvThreads = taskReceiver.getDeserializeThread();
for (AsyncLoopThread recvThread : recvThreads) {
allThreads.add(recvThread);
}
List<AsyncLoopThread> serializeThreads = taskTransfer.getSerializeThreads();
allThreads.addAll(serializeThreads);
TaskHeartbeatTrigger taskHeartbeatTrigger = ((BaseExecutors) baseExecutor).getTaskHbTrigger();
TaskShutdownDameon shutdown = new TaskShutdownDameon(taskStatus, topologyId, taskId, allThreads, zkCluster, taskObj, this, taskHeartbeatTrigger);
return shutdown;
}
Aggregations