RE: [picocontainer-dev] bug on pico start

Jörg Schaible <[email protected]>
Newsgroups gmane.comp.java.picocontainer.devel
Message-ID <[email protected]>
Putrycz, Erik wrote:

> Hi Jorg,
> 
> Thanks for your help.
> My problem is more about the lifecycle and order of operations. Somehow I
> think that pico is missing an "init" step in the lifecycle where you can
> have a modular structure for registering components.

You setup the containers normally first. If you have really the need to
register additional ones, use some kind of a ServiceManager that manages
your Pico hierarchy. That one may create additional Pico child containers.

> I have a complex 
> structure for pico components and 3 variants on the registered
> components... one for GUI, another one for db operations and another one
> for my tests. Guice has "modules" for instance that allow that. I was
> trying to do some of that in the start method but with the concurrency
> issues this is not working. Ideally, I'd see a lifecycle with - init ->
> registers components - start - stop - dispose
> 
> Am I the only one who has these requirements?

No, but others solve it differently :)


Example in Pseudo-Code:

class MainApp implements ServiceManager {
        private Pico system;
        
        MainApp (){
                system = new DPC();
                system.registerInstance(this);
                // register core components
                List registeringServices = 
                        system.getComponentInstancesOfType(RegisteringService.class);
                for (Iterator iter = list.iterator(): iter.hasNext();) {
                        RegisteringService registeringService = iter.next();
                        registeringService.registerAllServices();
                }
        }

        void registerNewService(Class service) {
                system.registerComponentImplementation(service);
        }

        void start() {
                system.start();
                // keep Thread running here (or have such a component)
        }

        static void main() {
                ServiceManager manager = new MainApp();
                manager.start();
        }
}

An implementation of the RegisteringService is dependent on a ServiceManager
that is utilized in its registerAllServices method. Does this make sense?

- Jörg


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