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.
>>
>>
>>

Reply via email to