You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avalon.apache.org by Jason van Zyl <ja...@zenplex.com> on 2002/09/19 22:12:04 UTC

Configuring components dynamically

Hi,

I'm sure people have done this before but I'm not sure what the standard
way to configure a component at run time is.

I have Jetty/Turbine/Velocity component combination that I am using to
create web views for an application model. I'm past the initial testing
and now I'm ready for some real world setups. The web views are packaged
up in JARs which contain some configuration information and JAR of
templates which make up the view. Things are fine with one view, my
test, but I want to be able to deploy N web views and be able to deploy
new ones at run time. Each web view needs to have its own Velocity
engine, which is housed inside my Velocity component, so I need to
retrieve a Velocity component from the ServiceManager but I want to hand
it a configuration and have the Velocity component be configured on the
fly: 

VelocityComponent vc = getServiceManager().
    get(VelocityComonent.ROLE, configuration);


Each web view will have different configurations may have varying
Velocity properties so I need to configure each velocity Component
differently for each web view.

I also use a scheduler component from within a messaging component and I
would like the messaging component to be able to retrieve a scheduler
component with a configuration as well.

How do you guys typically deal with this sort of dynamic configuration
and retrieval of components?

-- 
jvz.

Jason van Zyl
jason@zenplex.com
http://tambora.zenplex.org

In short, man creates for himself a new religion of a rational
and technical order to justify his work and to be justified in it.
  
  -- Jacques Ellul, The Technological Society


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Configuring components dynamically

Posted by Jason van Zyl <ja...@zenplex.com>.
On Fri, 2002-09-20 at 07:34, Leo Simons wrote:
> On Thu, 2002-09-19 at 22:12, Jason van Zyl wrote:
> > Hi,
> > 
> > I'm sure people have done this before but I'm not sure what the standard
> > way to configure a component at run time is.
> > 
> > I have Jetty/Turbine/Velocity component combination that I am using to
> > create web views for an application model.
> <snip/>
> > 
> > VelocityComponent vc = getServiceManager().
> >     get(VelocityComonent.ROLE, configuration);
> 
> Any chance I can get a look at that VelocityComponent? I can't open
> source ours and would like an excuse to ditch it in favour of something
> that might be open source (I know, big assumption...)...

Here's the baby container and all the components along with a maven
build:
http://tambora.zenplex.org/cgi-bin/cvsweb.cgi/plexus/

The container is nothing special as I've been pouring over all the
Avalon code looking stuff to use and looking for pointers. But I have 3
months to work on it and improve it.

Here's the heavily altered Turbine code that I'm using for application views:
http://tambora.zenplex.org/cgi-bin/cvsweb.cgi/turbine-3/

I will be renaming this Summit (a place to get a good view) and moving
it into the plexus directory, and completely avalonizing it.

Nothing special there but gander all you like.

> cheers,
> 
> Leo
> 
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
-- 
jvz.

Jason van Zyl
jason@zenplex.com
http://tambora.zenplex.org

In short, man creates for himself a new religion of a rational
and technical order to justify his work and to be justified in it.
  
  -- Jacques Ellul, The Technological Society


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Configuring components dynamically

Posted by Leo Simons <le...@apache.org>.
On Thu, 2002-09-19 at 22:12, Jason van Zyl wrote:
> Hi,
> 
> I'm sure people have done this before but I'm not sure what the standard
> way to configure a component at run time is.
> 
> I have Jetty/Turbine/Velocity component combination that I am using to
> create web views for an application model.
<snip/>
> 
> VelocityComponent vc = getServiceManager().
>     get(VelocityComonent.ROLE, configuration);

Any chance I can get a look at that VelocityComponent? I can't open
source ours and would like an excuse to ditch it in favour of something
that might be open source (I know, big assumption...)...

cheers,

Leo



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Configuring components dynamically

Posted by Jason van Zyl <ja...@zenplex.com>.
On Fri, 2002-09-20 at 05:59, Peter Donald wrote:
> On Fri, 20 Sep 2002 10:34, Jason van Zyl wrote:
> > Or are you saying that for the above scenerio I implement a factory that
> > would do essentially what a container is doing:
> >
> >     ContainerUtil.enableLogging(component, log);
> >     ContainerUtil.contextualize(component, context);
> >     ContainerUtil.service(component, this);
> >     ContainerUtil.configure(component, cd.getConfiguration());
> >     ContainerUtil.initialize(component);
> >     ContainerUtil.start(component);
> >
> > Except use a Configuration that I supply?
> 
> I think that is what he was implying.
> 
> > Would the following signature be useful for this sort of thing
> > generally:
> >
> > ServiceManger.lookup(String role, Configuration configuration)
> >
> > I imagine that something akin to this must be used all the time, no?
> 
> We have debated it and generally came to the conclusion that there is three 
> "solutions". Say we wanted the component Foo - because Velocity is too long 
> to type in an example ;).
> 
> Solution one:
>  The component in the SM is a FooFactory that we can pass parameters/config to 
> to create Foo. Useful if Foo is private to each component.
> 
> ie
> 
> void service( ServiceManager sm )
> {
>   final FooFactory factory = (FooFactory)sm.lookup( FooFactory.ROLE );
>   m_foo = factory.createFoo( myParams );
> }
> 
> Solution two:
>  The component in the SM is a FooManager. The Foos that FooManager manages are 
> defined in the configuration of FooManager. Useful if Foo needs to be shared 
> between multiple components. 
> 
> ie
> 
> void service( ServiceManager sm )
> {
>   final FooManager factory = (FooManager)sm.lookup( FooManager.ROLE );
>   m_foo = factory.getFoo( "my-foo" );
> }
> 
> Solution three:
>  There are several different instances of Foo in the container. ie Foo1, Foo2, 
> Foo3. Each component that needs a Foo has the assembler map the most 
> appropriate Foo into their SM namespace.
> 
> ie
> 
> void service( ServiceManager sm )
> {
>   m_foo = (Foo)sm.lookup( Foo.ROLE );
> }
> 
> Onlt Solution One provides a "dynamic" solution where the Foo iscreated 
> according to specified parameters. All the others require that the assembler 
> configure all the Foo instances in the application and either 
> * map them to correct component
> * place them in a FooManager
> 
> That make sense?

Yup, totally. Thanks for the explanations. I'll a couple things  whirl
this weekend.
 
> -- 
> Cheers,
> 
> Peter Donald
> *-----------------------------------------------------*
> * "Faced with the choice between changing one's mind, *
> * and proving that there is no need to do so - almost *
> * everyone gets busy on the proof."                   *
> *              - John Kenneth Galbraith               *
> *-----------------------------------------------------* 
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
-- 
jvz.

Jason van Zyl
jason@zenplex.com
http://tambora.zenplex.org

In short, man creates for himself a new religion of a rational
and technical order to justify his work and to be justified in it.
  
  -- Jacques Ellul, The Technological Society


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Configuring components dynamically

Posted by Peter Donald <pe...@apache.org>.
On Fri, 20 Sep 2002 10:34, Jason van Zyl wrote:
> Or are you saying that for the above scenerio I implement a factory that
> would do essentially what a container is doing:
>
>     ContainerUtil.enableLogging(component, log);
>     ContainerUtil.contextualize(component, context);
>     ContainerUtil.service(component, this);
>     ContainerUtil.configure(component, cd.getConfiguration());
>     ContainerUtil.initialize(component);
>     ContainerUtil.start(component);
>
> Except use a Configuration that I supply?

I think that is what he was implying.

> Would the following signature be useful for this sort of thing
> generally:
>
> ServiceManger.lookup(String role, Configuration configuration)
>
> I imagine that something akin to this must be used all the time, no?

We have debated it and generally came to the conclusion that there is three 
"solutions". Say we wanted the component Foo - because Velocity is too long 
to type in an example ;).

Solution one:
 The component in the SM is a FooFactory that we can pass parameters/config to 
to create Foo. Useful if Foo is private to each component.

ie

void service( ServiceManager sm )
{
  final FooFactory factory = (FooFactory)sm.lookup( FooFactory.ROLE );
  m_foo = factory.createFoo( myParams );
}

Solution two:
 The component in the SM is a FooManager. The Foos that FooManager manages are 
defined in the configuration of FooManager. Useful if Foo needs to be shared 
between multiple components. 

ie

void service( ServiceManager sm )
{
  final FooManager factory = (FooManager)sm.lookup( FooManager.ROLE );
  m_foo = factory.getFoo( "my-foo" );
}

Solution three:
 There are several different instances of Foo in the container. ie Foo1, Foo2, 
Foo3. Each component that needs a Foo has the assembler map the most 
appropriate Foo into their SM namespace.

ie

void service( ServiceManager sm )
{
  m_foo = (Foo)sm.lookup( Foo.ROLE );
}

Onlt Solution One provides a "dynamic" solution where the Foo iscreated 
according to specified parameters. All the others require that the assembler 
configure all the Foo instances in the application and either 
* map them to correct component
* place them in a FooManager

That make sense?

-- 
Cheers,

Peter Donald
*-----------------------------------------------------*
* "Faced with the choice between changing one's mind, *
* and proving that there is no need to do so - almost *
* everyone gets busy on the proof."                   *
*              - John Kenneth Galbraith               *
*-----------------------------------------------------* 


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Configuring components dynamically

Posted by Jason van Zyl <ja...@zenplex.com>.
On Thu, 2002-09-19 at 16:31, Leo Sutic wrote:
> > From: Jason van Zyl [mailto:jason@zenplex.com] 
> > 
> > How do you guys typically deal with this sort of dynamic 
> > configuration and retrieval of components?
> 
> Instead of getting a VelocityComponent, have a VelocityComponentFactory:
> 
> interface VelocityComponentFactory {
>   public VelocityComponent get (Configuration config);
> }
> 
> and use that instead.

Would this sort of mechanism work in conjunction with any of the
existing containers?

I assume at some level I still must ultimately retrieve the
component/service from a ServiceManager and would somehow have to signal
a change in the standard lifecycle processing in order to use a
Configuration on the fly, yes? Typically the configuration comes from
some sort of XML file doesn't it? If there are any examples of dynamic
configuration of components in the avalon repos anywhere point me to
them! :-)

Or are you saying that for the above scenerio I implement a factory that
would do essentially what a container is doing:

    ContainerUtil.enableLogging(component, log);
    ContainerUtil.contextualize(component, context);
    ContainerUtil.service(component, this);
    ContainerUtil.configure(component, cd.getConfiguration());
    ContainerUtil.initialize(component);
    ContainerUtil.start(component);

Except use a Configuration that I supply?

Would the following signature be useful for this sort of thing
generally:

ServiceManger.lookup(String role, Configuration configuration)

I imagine that something akin to this must be used all the time, no?

> /LS
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
-- 
jvz.

Jason van Zyl
jason@zenplex.com
http://tambora.zenplex.org

In short, man creates for himself a new religion of a rational
and technical order to justify his work and to be justified in it.
  
  -- Jacques Ellul, The Technological Society


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Configuring components dynamically

Posted by Leo Sutic <le...@inspireinfrastructure.com>.
> From: Jason van Zyl [mailto:jason@zenplex.com] 
> 
> How do you guys typically deal with this sort of dynamic 
> configuration and retrieval of components?

Instead of getting a VelocityComponent, have a VelocityComponentFactory:

interface VelocityComponentFactory {
  public VelocityComponent get (Configuration config);
}

and use that instead.

/LS


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>