use of backtype.storm.hooks.ITaskHook in project incubator-heron by apache.
the class TopologyContext method addTaskHook.
/*
public void setExecutorData(String name, Object data) {
_executorData.put(name, data);
}
public Object getExecutorData(String name) {
return _executorData.get(name);
}
*/
public void addTaskHook(ITaskHook newHook) {
Collection<com.twitter.heron.api.hooks.ITaskHook> hooks = delegate.getHooks();
if (hooks == null) {
ITaskHookDelegate delegateHook = new ITaskHookDelegate();
delegateHook.addHook(newHook);
delegate.addTaskHook(delegateHook);
} else {
for (com.twitter.heron.api.hooks.ITaskHook hook : hooks) {
if (hook instanceof ITaskHookDelegate) {
ITaskHookDelegate delegateHook = (ITaskHookDelegate) hook;
delegateHook.addHook(newHook);
return;
}
}
throw new RuntimeException("StormCompat taskHooks not setup properly");
}
}
use of backtype.storm.hooks.ITaskHook in project jstorm by alibaba.
the class TopologyContext method applyHooks.
public void applyHooks(String methodName, Object object) throws Exception {
for (ITaskHook taskHook : _hooks) {
Class clazz = taskHook.getClass();
Method method = clazz.getDeclaredMethod(methodName, object.getClass());
method.invoke(taskHook, object);
}
}
use of backtype.storm.hooks.ITaskHook in project heron by twitter.
the class TopologyContext method addTaskHook.
/*
public void setExecutorData(String name, Object data) {
_executorData.put(name, data);
}
public Object getExecutorData(String name) {
return _executorData.get(name);
}
*/
public void addTaskHook(ITaskHook newHook) {
Collection<org.apache.heron.api.hooks.ITaskHook> hooks = delegate.getHooks();
if (hooks == null) {
ITaskHookDelegate delegateHook = new ITaskHookDelegate();
delegateHook.addHook(newHook);
delegate.addTaskHook(delegateHook);
} else {
for (org.apache.heron.api.hooks.ITaskHook hook : hooks) {
if (hook instanceof ITaskHookDelegate) {
ITaskHookDelegate delegateHook = (ITaskHookDelegate) hook;
delegateHook.addHook(newHook);
return;
}
}
throw new RuntimeException("StormCompat taskHooks not setup properly");
}
}
use of backtype.storm.hooks.ITaskHook 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 " + topologyId + ":" + taskId);
TopologyContext userContext = task.getUserContext();
for (ITaskHook iTaskHook : userContext.getHooks()) iTaskHook.cleanup();
closeComponent(taskObj);
taskHeartbeatTrigger.updateExecutorStatus(TaskStatus.SHUTDOWN);
// wait 1 sec for executor thread to shutdown to make sure to send shutdown info to TM
try {
Thread.sleep(1000);
} catch (InterruptedException ignored) {
}
// all thread will check the taskStatus
// once it has been set to SHUTDOWN, it will quit
taskStatus.setStatus(TaskStatus.SHUTDOWN);
for (AsyncLoopThread thr : allThreads) {
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());
}
taskHeartbeatTrigger.unregister();
LOG.info("Successfully shutdown task heartbeat trigger for task:{}", taskId);
try {
zkCluster.disconnect();
} catch (Exception e) {
LOG.error("Failed to disconnect zk for task-" + taskId);
}
LOG.info("Successfully shutdown task " + topologyId + ":" + taskId);
}
}
Aggregations