Search in sources :

Example 1 with IStatefulComponent

use of org.apache.heron.api.topology.IStatefulComponent in project heron by twitter.

the class SpoutInstance method init.

@SuppressWarnings("unchecked")
@Override
public void init(State<Serializable, Serializable> state) {
    TopologyContextImpl topologyContext = helper.getTopologyContext();
    // Initialize the GlobalMetrics
    GlobalMetrics.init(topologyContext, systemConfig.getHeronMetricsExportInterval());
    spoutMetrics.registerMetrics(topologyContext);
    // Initialize the instanceState if the topology is stateful and spout is a stateful component
    if (isTopologyStateful && spout instanceof IStatefulComponent) {
        this.instanceState = state;
        ((IStatefulComponent<Serializable, Serializable>) spout).initState(instanceState);
        if (spillState) {
            if (FileUtils.isDirectoryExists(spillStateLocation)) {
                FileUtils.cleanDir(spillStateLocation);
            } else {
                FileUtils.createDirectory(spillStateLocation);
            }
        }
    }
    spout.open(topologyContext.getTopologyConfig(), topologyContext, new SpoutOutputCollector(collector));
    // Invoke user-defined prepare task hook
    topologyContext.invokeHookPrepare();
    // Init the CustomStreamGrouping
    helper.prepareForCustomStreamGrouping();
}
Also used : TopologyContextImpl(org.apache.heron.common.utils.topology.TopologyContextImpl) SpoutOutputCollector(org.apache.heron.api.spout.SpoutOutputCollector) IStatefulComponent(org.apache.heron.api.topology.IStatefulComponent)

Example 2 with IStatefulComponent

use of org.apache.heron.api.topology.IStatefulComponent in project heron by twitter.

the class BoltInstance method init.

@SuppressWarnings("unchecked")
@Override
public void init(State<Serializable, Serializable> state) {
    TopologyContextImpl topologyContext = helper.getTopologyContext();
    // Initialize the GlobalMetrics
    GlobalMetrics.init(topologyContext, systemConfig.getHeronMetricsExportInterval());
    boltMetrics.registerMetrics(topologyContext);
    // Initialize the instanceState if the topology is stateful and bolt is a stateful component
    if (isTopologyStateful && bolt instanceof IStatefulComponent) {
        this.instanceState = state;
        ((IStatefulComponent<Serializable, Serializable>) bolt).initState(instanceState);
        if (spillState) {
            if (FileUtils.isDirectoryExists(spillStateLocation)) {
                FileUtils.cleanDir(spillStateLocation);
            } else {
                FileUtils.createDirectory(spillStateLocation);
            }
        }
    }
    // Delegate
    bolt.prepare(topologyContext.getTopologyConfig(), topologyContext, new OutputCollector(collector));
    // Invoke user-defined prepare task hook
    topologyContext.invokeHookPrepare();
    // Init the CustomStreamGrouping
    helper.prepareForCustomStreamGrouping();
}
Also used : OutputCollector(org.apache.heron.api.bolt.OutputCollector) TopologyContextImpl(org.apache.heron.common.utils.topology.TopologyContextImpl) IStatefulComponent(org.apache.heron.api.topology.IStatefulComponent)

Aggregations

IStatefulComponent (org.apache.heron.api.topology.IStatefulComponent)2 TopologyContextImpl (org.apache.heron.common.utils.topology.TopologyContextImpl)2 OutputCollector (org.apache.heron.api.bolt.OutputCollector)1 SpoutOutputCollector (org.apache.heron.api.spout.SpoutOutputCollector)1