Search in sources :

Example 1 with IStatefulComponent

use of com.twitter.heron.api.topology.IStatefulComponent in project incubator-heron by apache.

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 spout is stateful
    if (spout instanceof IStatefulComponent) {
        this.instanceState = state;
        ((IStatefulComponent<Serializable, Serializable>) spout).initState(instanceState);
    }
    spout.open(topologyContext.getTopologyConfig(), topologyContext, new SpoutOutputCollector(collector));
    // Invoke user-defined prepare task hook
    topologyContext.invokeHookPrepare();
    // Init the CustomStreamGrouping
    helper.prepareForCustomStreamGrouping();
}
Also used : TopologyContextImpl(com.twitter.heron.common.utils.topology.TopologyContextImpl) SpoutOutputCollector(com.twitter.heron.api.spout.SpoutOutputCollector) IStatefulComponent(com.twitter.heron.api.topology.IStatefulComponent)

Example 2 with IStatefulComponent

use of com.twitter.heron.api.topology.IStatefulComponent in project incubator-heron by apache.

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 bolt is stateful
    if (bolt instanceof IStatefulComponent) {
        this.instanceState = state;
        ((IStatefulComponent<Serializable, Serializable>) bolt).initState(instanceState);
    }
    // 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(com.twitter.heron.api.bolt.OutputCollector) TopologyContextImpl(com.twitter.heron.common.utils.topology.TopologyContextImpl) IStatefulComponent(com.twitter.heron.api.topology.IStatefulComponent)

Aggregations

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