Search in sources :

Example 1 with ITaskHook

use of org.apache.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");
    }
}
Also used : ITaskHook(org.apache.storm.hooks.ITaskHook) ITaskHookDelegate(org.apache.storm.hooks.ITaskHookDelegate)

Example 2 with ITaskHook

use of org.apache.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");
    }
}
Also used : ITaskHook(org.apache.storm.hooks.ITaskHook) ITaskHookDelegate(org.apache.storm.hooks.ITaskHookDelegate)

Example 3 with ITaskHook

use of org.apache.storm.hooks.ITaskHook in project storm by apache.

the class ExecutorShutdown method shutdown.

@Override
public void shutdown() {
    try {
        LOG.info("Shutting down executor " + executor.getComponentId() + ":" + executor.getExecutorId());
        executor.getReceiveQueue().close();
        for (Utils.SmartThread t : threads) {
            t.interrupt();
        }
        for (Utils.SmartThread t : threads) {
            LOG.debug("Executor " + executor.getComponentId() + ":" + executor.getExecutorId() + " joining thread " + t.getName());
            // Don't wait forever.
            // This is to avoid the deadlock between the executor thread (t) and the shutdown hook (which invokes Worker::shutdown)
            // when it is the executor thread (t) who invokes the shutdown hook. See STORM-3658.
            long waitMs = 100;
            t.join(waitMs);
            if (t.isAlive()) {
                LOG.warn("Thread {} is still alive ({} ms after interruption). Stop waiting for it.", t.getName(), waitMs);
            }
        }
        executor.getStats().cleanupStats();
        for (Task task : taskDatas) {
            if (task == null) {
                continue;
            }
            TopologyContext userContext = task.getUserContext();
            for (ITaskHook hook : userContext.getHooks()) {
                hook.cleanup();
            }
        }
        executor.getStormClusterState().disconnect();
        if (executor.getOpenOrPrepareWasCalled().get()) {
            for (Task task : taskDatas) {
                if (task == null) {
                    continue;
                }
                Object object = task.getTaskObject();
                if (object instanceof ISpout) {
                    ((ISpout) object).close();
                } else if (object instanceof IBolt) {
                    ((IBolt) object).cleanup();
                } else {
                    LOG.error("unknown component object");
                }
            }
        }
        LOG.info("Shut down executor " + executor.getComponentId() + ":" + executor.getExecutorId());
    } catch (Exception e) {
        throw Utils.wrapInRuntime(e);
    }
}
Also used : Task(org.apache.storm.daemon.Task) Utils(org.apache.storm.utils.Utils) ITaskHook(org.apache.storm.hooks.ITaskHook) IBolt(org.apache.storm.task.IBolt) TopologyContext(org.apache.storm.task.TopologyContext) ISpout(org.apache.storm.spout.ISpout)

Aggregations

ITaskHook (org.apache.storm.hooks.ITaskHook)3 ITaskHookDelegate (org.apache.storm.hooks.ITaskHookDelegate)2 Task (org.apache.storm.daemon.Task)1 ISpout (org.apache.storm.spout.ISpout)1 IBolt (org.apache.storm.task.IBolt)1 TopologyContext (org.apache.storm.task.TopologyContext)1 Utils (org.apache.storm.utils.Utils)1