Thanks for the serialization tip, I'll try that. The example is very simple, the actual bolt I've created has got a complicated logic. I want to reuse it with many different IExecutors, so many different IExecutorCreator. Since the executor creation code is in the bolt, I can not mention the concrete implementation of the Creator in there.
On Fri, Nov 14, 2014 at 2:42 PM, Nathan Leung <[email protected]> wrote: > Yes, just put an entry into the configuration map, something like > > "myclass": "com.esotericsoftware.kryo.serializers.FieldSerializer", > > But still, why do you need to instantiate your factory? Why not just > define it as follows: > > public static class DummyExecutorCreator implements > IExecutorCreator > { > String name_; > public DummyExecutorCreator(String name) { this.name_ = name;} > public static IExecutor create(Map map, TopologyContext tc, > OutputCollector oc) { > return new DummyExecutor(); > } > }; > > and then just call > > this.executor_ = DummyExecutorCreator.create(map, tc, oc); > > On Fri, Nov 14, 2014 at 9:37 AM, Arthur Andres <[email protected]> > wrote: > >> Thanks for the suggestion. >> Maybe I haven't used the right wording. >> I give an instance of the factory to the bolt. The bolt stores the >> factory and it needs to be serialized. >> Ideally I want to create different factories, with different parameters >> in order to have different type of bolts. >> So having a static factory does not really help in this case. >> >> But otherwise would you know how to register a serializer for a bolt >> member. >> >> >> On Fri, Nov 14, 2014 at 2:25 PM, Nathan Leung <[email protected]> wrote: >> >>> Factory create methods are usually static, no? You should just store the >>> string in your bolt and the make the factory create method a static call >>> that takes the string as a parameter. >>> On Nov 14, 2014 9:17 AM, "Arthur Andres" <[email protected]> >>> wrote: >>> >>>> Hi, >>>> I've submitted a question on stackoverflow regarding the serialization >>>> of members of bolts. >>>> I wanted to bring it to the attention of the subscribers of this list: >>>> >>>> http://stackoverflow.com/questions/26931220/how-to-simply-set-up-a-serializer-for-storm-bolt-spout-members >>>> >>>> Thanks. >>>> >>>> PS: here's a copy of the question: >>>> I have a bolt that uses a factory interface to create the tools it >>>> uses. It creates those tools when `prepare` is called. The Factory >>>> implementation only has basic members (strings, integers) that should be >>>> serializable by default. >>>> >>>> When I run my topology I get a `NotSerializableException`, coming from >>>> the factory implementation. I was wondering how I could register a >>>> serializer for the factory. >>>> >>>> here's an example: >>>> >>>> public class Demo extends BaseRichBolt { >>>> >>>> public static interface IExecutor >>>> { >>>> public void execute( Tuple tuple ); >>>> } >>>> >>>> public static interface IExecutorCreator >>>> { >>>> public IExecutor create( Map map, TopologyContext tc, >>>> OutputCollector oc ); >>>> }; >>>> >>>> public static class DummyExecutor implements IExecutor >>>> { >>>> public void execute( Tuple tuple ) {} >>>> }; >>>> >>>> public static class DummyExecutorCreator implements >>>> IExecutorCreator >>>> { >>>> String name_; >>>> public DummyExecutorCreator(String name) { this.name_ = >>>> name;} >>>> public IExecutor create(Map map, TopologyContext tc, >>>> OutputCollector oc) { >>>> return new DummyExecutor(); >>>> } >>>> }; >>>> >>>> public void declareOutputFields(OutputFieldsDeclarer ofd) { >>>> >>>> } >>>> >>>> private IExecutor executor_; >>>> private IExecutorCreator creator_; >>>> >>>> public Demo(IExecutorCreator creator) >>>> { >>>> this.creator_ = creator; >>>> } >>>> >>>> public void prepare(Map map, TopologyContext tc, >>>> OutputCollector oc) { >>>> this.executor_ = this.creator_.create(map, tc, oc); >>>> } >>>> >>>> public void execute(Tuple tuple) { >>>> this.executor_.execute(tuple); >>>> } >>>> >>>> } >>>> And I get this error when I try to run it in a topology: >>>> `java.io.NotSerializableException: Demo$DummyExecutorCreator` >>>> >>>> As a side note I'm starting to wonder, why don't Storm have you to >>>> register factories instead of Bolts and Spouts. since in the end they get >>>> serialized and copied across the different threads, it'd be probably better >>>> to just give storm a mean to generate those bolts and separate the >>>> concerns. >>>> >>>> >>>> >> >
