The bolt base classes have a prepare method:
https://storm.incubator.apache.org/apidocs/backtype/storm/topology/base/BaseBasicBolt.html
and the spout base classes have a similar activate method:
https://storm.incubator.apache.org/apidocs/backtype/storm/topology/base/BaseRichSpout.html
Is that
Yes.. if i used prepare or open on spouts or bolts it would work, but
unfortunately it would be a bit brittle. I'd have to include a spout or
bolt just for initializing my invariant code... i'd rather do that when the
topology is activated on the worker.. so this seems like a good use of an
You don't have to include a specific bolt for init code. It's not difficult
to push your init code into a separate class and call it from your bolts,
lock on that class, run init, and then allow other instances to skip over
it.
Without changing bolt/spout code, I've taken to including a task hook
This looks promising. thanks.
hope you don't mind one more question -- if i create my own
implementation of ITaskHook and add it do the config as you illustrated in
prev. msg..will the prepare() method of my implementation be called
exactly once shortly after StormTopology is deserialized
No, it will be called per bolt instance. That's why init code needs to be
guarded behind a double-check lock to guarantee it only executes once per
JVM.
e.g.
private static volatile boolean initialized = false;
...
if (!initialized) {
synchronized(MyInitCode.class) {
if
Hi there -
I would like to set up some state that spouts and bolts share, and I'd like
to prepare this state when the StormTopology gets 'activated' on a worker.
it would be great if the StormTopology had something like a prepare or open
method to indicate when it is starting. I looked but i