David García
2010-01-23 01:44:23 UTC
I'm trying to use Provider Injection to create and configure a
startable component, but for some reason my component does not get
started after calling start() on the container.
Any ideas on how should I configure my container to support it?
Here is my sample code:
ComponentMonitor componentMonitor = new LifecycleComponentMonitor();
LifecycleStrategy lifecycleStrategy = new
ReflectionLifecycleStrategy(componentMonitor);
MutablePicoContainer pico = new DefaultPicoContainer(new
ThreadCaching(), lifecycleStrategy, null);
pico.addComponent(Configuration.class, ConfigurationImpl.class);
pico.addAdapter(new ProviderAdapter(new ComponentProvider()));
pico.start();
public class ComponentProvider implements Provider {
public Component provide(Configuration config) {
return new Component(config.getHost(), config.getPort());
}
}
public interface Component {
public void start();
public void stop();
public void doSomething();
}
public class ComponentImpl {
public Component(String host, int port) {
//some stuff
}
public void start() {
//this never gets executed!!!
}
}
I cannot modify Component or ComponentImpl, I'm trying to use the
Provider to crate ComponentImpl instances using data from
Configuration class.
When in some other place i do:
pico.getComponent(Component.class);
the instance is created, but it's not started.
What am I missing??
Thanks.
David
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email
startable component, but for some reason my component does not get
started after calling start() on the container.
Any ideas on how should I configure my container to support it?
Here is my sample code:
ComponentMonitor componentMonitor = new LifecycleComponentMonitor();
LifecycleStrategy lifecycleStrategy = new
ReflectionLifecycleStrategy(componentMonitor);
MutablePicoContainer pico = new DefaultPicoContainer(new
ThreadCaching(), lifecycleStrategy, null);
pico.addComponent(Configuration.class, ConfigurationImpl.class);
pico.addAdapter(new ProviderAdapter(new ComponentProvider()));
pico.start();
public class ComponentProvider implements Provider {
public Component provide(Configuration config) {
return new Component(config.getHost(), config.getPort());
}
}
public interface Component {
public void start();
public void stop();
public void doSomething();
}
public class ComponentImpl {
public Component(String host, int port) {
//some stuff
}
public void start() {
//this never gets executed!!!
}
}
I cannot modify Component or ComponentImpl, I'm trying to use the
Provider to crate ComponentImpl instances using data from
Configuration class.
When in some other place i do:
pico.getComponent(Component.class);
the instance is created, but it's not started.
What am I missing??
Thanks.
David
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email