RE: [picocontainer-dev] bug on pico start

"Putrycz, Erik" <[email protected]>
Newsgroups gmane.comp.java.picocontainer.devel
Message-ID <[email protected]>
Thanks Paul, I just redid the patch to be cleaner I unfortulately did
some formatting on that previous patch.  
I'm basically doing lots of IoC violations... My code is very close to
what is in the testcase.
 
In my app I just added a bunch of configuration classes. At the start of
the application, I need to initialize the configuration classes (check
if directories exist...). I have componentized the configuration into
modules so in the start (pico.start)) I retrieve all the configuration
modules by doing pico.getComponents(ConfigurationModule.class). And that
barfs a concurrency exception. 

I know propagating the container is outside of schoolbooks of IoC but it
would be nice if pico could accommodate that as well.

Erik

-----Original Message-----
From: Paul Hammant [mailto:[email protected]] 
Sent: August 2, 2007 11:11
To: dev-qxt/[email protected]
Subject: Re: [picocontainer-dev] bug on pico start

Erik,

I've been thru the patch and manually applied the bits that were changed
/ new :

     public static class StartableClazz implements Startable {
         private MutablePicoContainer _pico;
         public void start() {
             List<SimpleTouchable> cps = _pico
                 .getComponents(SimpleTouchable.class);
             assertNotNull(cps);
         }
         public void stop() {
         }
     }

     public void testListComponentsOnStart() {
         DefaultPicoContainer dpc = new DefaultPicoContainer();
         dpc.addComponent(SimpleTouchable.class);
         StartableClazz cl = new StartableClazz();
         cl._pico = dpc;
         dpc.addComponent(cl);
         dpc.start();
     }

The test class is handed a ref to the container that is about to contain
it.  No wonder it barfs with java.util.ConcurrentModificationException.
Its a basic violation of Inversion of Control.

Better would be :

     public static class StartableClazz implements Startable {
         private SimpleTouchable simpleTouchable;
         public StartableClazz(SimpleTouchable st) {
             this. simpleTouchable = st;
         }
         public void start() {
             // do what you need with simpleTouchable here.
         }
         public void stop() {
         }
     }

You're mostly likely trying to shw us something from your own codebase,
but using our (supid) test classes. Can you tell us more about your need
? :-)

- Paul

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email


---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.