Thanks Nathan and Javier.

I ended up using lazy init singleton and things seem to be working. But now
how do I know its using single instance of the session? Is there a way we
can know from storm UI or and where else?

--
Kushan Maskey
817.403.7500
Precocity LLC <http://precocity.com>
M. Miller & Associates <http://mmillerassociates.com/>
kushan.mas...@mmillerassociates.com

On Thu, Jun 18, 2015 at 12:48 PM, Javier Gonzalez <jagon...@gmail.com>
wrote:

> We had a similar issue (namely, you can't pass anything non-serializable
> through the Configuration or create it in the constructor).
>
> What we did is pass in the Configuration or constructor a String with the
> path to a properties file. From that configuration file, in the
> bolt.prepare method you bring up whatever you need (such as a connection
> pool) and off you go. We needed to use a library that was configured by
> spring, so we passed in the path to the spring configuration file, created
> a context with it in the prepare method, obtained the external beans, and
> closed the context.
>
> On Wed, Jun 17, 2015 at 5:16 PM, Nathan Leung <ncle...@gmail.com> wrote:
>
>> You cannot pass a connection through the builder, as you have noticed.
>> You can use a lazy initialized singleton or some sort of connection pool.
>> On Jun 17, 2015 5:05 PM, "Kushan Maskey" <
>> kushan.mas...@mmillerassociates.com> wrote:
>>
>>> I am wondering how can I safely create a Singleton database connection
>>> and use it through out the process.
>>>
>>> Here is my scenario.
>>>
>>> I got bunch of bolts that updates Cassandra database. I have reader and
>>> writer classes where each needs a database session to execute queries. We
>>> create session on each of the reader and writer classes. We also use
>>> parallelism hints on the bolts which create that many instances of session
>>> object.
>>>
>>> I have tried creating session on topology and pass the instance through
>>> stormConfig but didnt work with the error message below.
>>>
>>> java.lang.IllegalArgumentException: Topology conf is not
>>> json-serializable
>>>     at
>>> backtype.storm.testing$submit_local_topology.invoke(testing.clj:251)
>>> ~[storm-core-0.9.2-incubating.jar:0.9.2-incubating]
>>>     at
>>> backtype.storm.LocalCluster$_submitTopology.invoke(LocalCluster.clj:38)
>>> ~[storm-core-0.9.2-incubating.jar:0.9.2-incubating]
>>>     at backtype.storm.LocalCluster.submitTopology(Unknown Source)
>>> ~[storm-core-0.9.2-incubating.jar:0.9.2-incubating]
>>>
>>> Any code sample will be helpful.
>>>
>>> --
>>> Kushan Maskey
>>> 817.403.7500
>>> Precocity LLC <http://precocity.com>
>>> M. Miller & Associates <http://mmillerassociates.com/>
>>> kushan.mas...@mmillerassociates.com
>>>
>>
>
>
> --
> Javier González Nicolini
>

Reply via email to