Discussion:
picocontainer-script and LifecycleStrategy
Troy Kinsella
2008-08-01 00:24:30 UTC
Permalink
Hello,

I'm using a ScriptedContainerBuilder to read in component configuration
from a beanshell script. My parent container has a custom
LifecycleStrategy to pair with a custom Startable interface equivalent.
Upon inspecting the container produced by the ScriptedContainerBuilder,
it has the default StartableLifecycleStrategy. Thus, my start()able
components are not being start()ed.

How can I get my custom LifecycleStrategy into the child container? Or,
if I'm not on the right track, what might I be doing wrong? I've fiddled
with both AUTO and NO LifecycleMode starting the container manually.

Thanks in advance. Excellent work on this great tool.

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

http://xircles.codehaus.org/manage_email
Paul Hammant
2008-08-01 00:26:27 UTC
Permalink
Give us a script that you're working with Troy - or something similar.

Regards,

- Paul
Post by Troy Kinsella
Hello,
I'm using a ScriptedContainerBuilder to read in component
configuration
from a beanshell script. My parent container has a custom
LifecycleStrategy to pair with a custom Startable interface
equivalent.
Upon inspecting the container produced by the
ScriptedContainerBuilder,
it has the default StartableLifecycleStrategy. Thus, my start()able
components are not being start()ed.
How can I get my custom LifecycleStrategy into the child container? Or,
if I'm not on the right track, what might I be doing wrong? I've fiddled
with both AUTO and NO LifecycleMode starting the container manually.
Thanks in advance. Excellent work on this great tool.
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email
Troy Kinsella
2008-08-01 13:11:50 UTC
Permalink
Absolutely, here is my layout:

_test.bsh_:

pico = new org.picocontainer.DefaultPicoContainer(parent);

// add dependencies...

pico.addComponent(org.Thing.class, org.ThingImpl.class, null);

_java:_

// Classes being worked with

interface CustomStartable

class Thing implements CustomStartable

class ThingImpl extends Thing

// Loading the container

ScriptedContainerBuilder builder = new
BeanShellContainerBuilder(readerOfTestDotBsh, ctxClassLoader,
LifecycleMode.AUTO_LIFECYCLE);

ComponentFactory componentFactory = new Caching().wrap(new
ConstructorInjection());
ComponentMonitor componentMonitor = new ConsoleComponentMonitor();
LifecycleStrategy lifecycleStrategy = new
CustomLifecycleStrategy(componentMonitor); // starts/stops CustomStartable

PicoContainer parent = new DefaultPicoContainer(componentFactory,
lifecycleStrategy, null, componentMonitor);
PicoContainer container = builder.buildContainer(parent, "defaultScope",
true);

Thing thing = container.getComponent(Thing.class); // not started

So, parent has a CustomLifecycleStrategy, but container has a
StartableLifecycleStrategy. My custom lifecycle strategy does not get
invoked at any point.

Thanks,

Troy
Post by Paul Hammant
Give us a script that you're working with Troy - or something similar.
Regards,
- Paul
Post by Troy Kinsella
Hello,
I'm using a ScriptedContainerBuilder to read in component configuration
from a beanshell script. My parent container has a custom
LifecycleStrategy to pair with a custom Startable interface equivalent.
Upon inspecting the container produced by the ScriptedContainerBuilder,
it has the default StartableLifecycleStrategy. Thus, my start()able
components are not being start()ed.
How can I get my custom LifecycleStrategy into the child container? Or,
if I'm not on the right track, what might I be doing wrong? I've fiddled
with both AUTO and NO LifecycleMode starting the container manually.
Thanks in advance. Excellent work on this great tool.
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
Paul Hammant
2008-08-01 16:08:02 UTC
Permalink
OK, Troy thanks. I'll use this to make a test case somewhere in - https://svn.codehaus.org/picocontainer/java/2.x/trunk/script/script-bsh/

But perhaps later today if you can wait.

Regards,

- Paul
Post by Troy Kinsella
pico = new org.picocontainer.DefaultPicoContainer(parent);
// add dependencies...
pico.addComponent(org.Thing.class, org.ThingImpl.class, null);
// Classes being worked with
interface CustomStartable
class Thing implements CustomStartable
class ThingImpl extends Thing
// Loading the container
ScriptedContainerBuilder builder = new
BeanShellContainerBuilder(readerOfTestDotBsh, ctxClassLoader,
LifecycleMode.AUTO_LIFECYCLE);
ComponentFactory componentFactory = new Caching().wrap(new
ConstructorInjection());
ComponentMonitor componentMonitor = new ConsoleComponentMonitor();
LifecycleStrategy lifecycleStrategy = new
CustomLifecycleStrategy(componentMonitor); // starts/stops
CustomStartable
PicoContainer parent = new DefaultPicoContainer(componentFactory,
lifecycleStrategy, null, componentMonitor);
PicoContainer container = builder.buildContainer(parent,
"defaultScope", true);
Thing thing = container.getComponent(Thing.class); // not started
So, parent has a CustomLifecycleStrategy, but container has a
StartableLifecycleStrategy. My custom lifecycle strategy does not
get invoked at any point.
Thanks,
Troy
Post by Paul Hammant
Give us a script that you're working with Troy - or something
similar.
Regards,
- Paul
Post by Troy Kinsella
Hello,
I'm using a ScriptedContainerBuilder to read in component
configuration
from a beanshell script. My parent container has a custom
LifecycleStrategy to pair with a custom Startable interface
equivalent.
Upon inspecting the container produced by the
ScriptedContainerBuilder,
it has the default StartableLifecycleStrategy. Thus, my start()able
components are not being start()ed.
How can I get my custom LifecycleStrategy into the child
container? Or,
if I'm not on the right track, what might I be doing wrong? I've fiddled
with both AUTO and NO LifecycleMode starting the container manually.
Thanks in advance. Excellent work on this great tool.
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
Paul Hammant
2008-08-04 16:22:44 UTC
Permalink
OK Troy - take a look at :-

https://svn.codehaus.org/picocontainer/java/2.x/trunk/script/script-bsh/src/test/org/picocontainer/script/bsh/TroysBugTestCase.java

And let me know what you think.

That works for me. The way you had it. the lifecycleStartegy from the
parent had not been passed to the child. Does that make sense ?

- Paul
Post by Troy Kinsella
pico = new org.picocontainer.DefaultPicoContainer(parent);
// add dependencies...
pico.addComponent(org.Thing.class, org.ThingImpl.class, null);
// Classes being worked with
interface CustomStartable
class Thing implements CustomStartable
class ThingImpl extends Thing
// Loading the container
ScriptedContainerBuilder builder = new
BeanShellContainerBuilder(readerOfTestDotBsh, ctxClassLoader,
LifecycleMode.AUTO_LIFECYCLE);
ComponentFactory componentFactory = new Caching().wrap(new
ConstructorInjection());
ComponentMonitor componentMonitor = new ConsoleComponentMonitor();
LifecycleStrategy lifecycleStrategy = new
CustomLifecycleStrategy(componentMonitor); // starts/stops
CustomStartable
PicoContainer parent = new DefaultPicoContainer(componentFactory,
lifecycleStrategy, null, componentMonitor);
PicoContainer container = builder.buildContainer(parent,
"defaultScope", true);
Thing thing = container.getComponent(Thing.class); // not started
So, parent has a CustomLifecycleStrategy, but container has a
StartableLifecycleStrategy. My custom lifecycle strategy does not
get invoked at any point.
Thanks,
Troy
Post by Paul Hammant
Give us a script that you're working with Troy - or something
similar.
Regards,
- Paul
Post by Troy Kinsella
Hello,
I'm using a ScriptedContainerBuilder to read in component
configuration
from a beanshell script. My parent container has a custom
LifecycleStrategy to pair with a custom Startable interface
equivalent.
Upon inspecting the container produced by the
ScriptedContainerBuilder,
it has the default StartableLifecycleStrategy. Thus, my start()able
components are not being start()ed.
How can I get my custom LifecycleStrategy into the child
container? Or,
if I'm not on the right track, what might I be doing wrong? I've fiddled
with both AUTO and NO LifecycleMode starting the container manually.
Thanks in advance. Excellent work on this great tool.
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
Troy Kinsella
2008-08-04 21:25:53 UTC
Permalink
Paul,

Using:

pico = parent.makeChildContainer();

to create the child container worked for me as well.

Thanks very much!
Post by Paul Hammant
OK Troy - take a look at :-
https://svn.codehaus.org/picocontainer/java/2.x/trunk/script/script-bsh/src/test/org/picocontainer/script/bsh/TroysBugTestCase.java
And let me know what you think.
That works for me. The way you had it. the lifecycleStartegy from the
parent had not been passed to the child. Does that make sense ?
- Paul
Post by Troy Kinsella
pico = new org.picocontainer.DefaultPicoContainer(parent);
// add dependencies...
pico.addComponent(org.Thing.class, org.ThingImpl.class, null);
_java:_
// Classes being worked with
interface CustomStartable
class Thing implements CustomStartable
class ThingImpl extends Thing
// Loading the container
ScriptedContainerBuilder builder = new
BeanShellContainerBuilder(readerOfTestDotBsh, ctxClassLoader,
LifecycleMode.AUTO_LIFECYCLE);
ComponentFactory componentFactory = new Caching().wrap(new
ConstructorInjection());
ComponentMonitor componentMonitor = new ConsoleComponentMonitor();
LifecycleStrategy lifecycleStrategy = new
CustomLifecycleStrategy(componentMonitor); // starts/stops
CustomStartable
PicoContainer parent = new DefaultPicoContainer(componentFactory,
lifecycleStrategy, null, componentMonitor);
PicoContainer container = builder.buildContainer(parent,
"defaultScope", true);
Thing thing = container.getComponent(Thing.class); // not started
So, parent has a CustomLifecycleStrategy, but container has a
StartableLifecycleStrategy. My custom lifecycle strategy does not get
invoked at any point.
Thanks,
Troy
Post by Paul Hammant
Give us a script that you're working with Troy - or something similar.
Regards,
- Paul
Post by Troy Kinsella
Hello,
I'm using a ScriptedContainerBuilder to read in component
configuration
from a beanshell script. My parent container has a custom
LifecycleStrategy to pair with a custom Startable interface
equivalent.
Upon inspecting the container produced by the
ScriptedContainerBuilder,
it has the default StartableLifecycleStrategy. Thus, my start()able
components are not being start()ed.
How can I get my custom LifecycleStrategy into the child container? Or,
if I'm not on the right track, what might I be doing wrong? I've fiddled
with both AUTO and NO LifecycleMode starting the container manually.
Thanks in advance. Excellent work on this great tool.
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
Loading...