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();
}
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();
}
Aggregations