The persistent map comes from clojure.  Clojure is a functional language where 
all data types are immutable.  My suggestion would be to keep doing what you 
are doing.

open(..., Map conf, ...) {    conf = new HashMap(conf);    ...
}

I know it can be a pain, but it also avoids situations like with Hadoop, where 
configs are modifiable and shared. I have had to fix race conditions because 
one part of the code is setting a config that it thinks no one else is using 
right now but another part of the code on a different thread is reading that 
same config, and sometimes it reads the old one, and other times it reads the 
new one.  I really would rather have had an UnsupportedOperationException come 
out early on instead of trying to debug what was happening.
You could also create a few abstract parent classes that all of your bolts and 
spouts derive from.
... open(..., Map conf, ...) {    modOpen(...,conf instanceof HashMap ? 
(HashMap)conf : new HashMap(conf), ...);
}
 ... abstract modOpen(..., HashMap conf, ...);

- Bobby
 


     On Thursday, April 23, 2015 8:10 AM, Nathan Leung <[email protected]> 
wrote:
   

 Instead of writing the map you can just write a variable in the abstract
class.
On Apr 23, 2015 7:45 AM, "Matthias J. Sax" <[email protected]>
wrote:

> I understand that.
>
> In my case, I use a class hierarchy with abstract spouts/bolts and
> multiple concrete spouts/bolts. The abstract class uses some default
> values (if not provided in the given config) similar to the derived
> classes. However, some derived classes overwrite the default values for
> the abstract class, ie, if no value is given in the config, some derived
> classes set the values and other do not. Additionally, open()/prepare()
> of the abstract class is called, too, and set the default value if the
> value was neither provided by the user, not by the derived class.
>
> Does it make sense how I explained it?
>
>
> -Matthias
>
>
>
>
> On 04/23/2015 01:08 PM, Nathan Leung wrote:
> > Config should be set when the topology is created before it's sent to the
> > nimbus. If you write an option to the map there is no mechanism to
> > propagate the change to the rest of the instances of storm components.
> > On Apr 23, 2015 6:02 AM, "Matthias J. Sax" <
> [email protected]>
> > wrote:
> >
> >> Hi,
> >>
> >> in the Spout/Bolt open()/prepare() method, a Map containing the current
> >> configuration is given. This Map is of type
> >> clojure.lang.PersistentHashMap and calling .put(...) raises an
> >> UnsupportedOperationException.
> >>
> >> I was wondering, why a persistent map is used? I could image, that
> >> system defined values should not be modified. But adding new key/value
> >> pairs is not allowed either (and would be very helpful in my case).
> >>
> >> Right now, I simply copy all values into a new HashMap object and add my
> >> own values to this new HashMap. But this is an annoying workaround I
> >> have to do each time...
> >>
> >> Would it make sense, the change the type of the system provided Map (or
> >> modify it's behavior to all for adding new key/value pairs)?
> >>
> >>
> >> -Matthias
> >>
> >>
> >>
> >>
> >>
> >
>
>


  

Reply via email to