Berin Loritsch wrote:
Filip Defoort wrote:

Hi,

I just started to play around with Avalon, and have the following question:
I would need to use a set of components of the same type simultaneously,
without knowing up-front how many there are.


Just curious, what are you working on?

I haven't completely read all your suggestions yet, but here's already a further description of what I'm working on: I'm working on a system that aggregates information from various sources.. There's different types of information (e.g. hierarchy info, metadata, annotations,...), but all of those types of information can be provided by multiple components at the same time, which need to be aggregated by the app and presented to the user (e.g. if I would ask for notes with a given query string, those notes could come from several components at the same time; they are presented in a single list to the end-user; if I would ask for the children of a node, there's no central server that manages all the possible children, but a set of providers that each can give me a couple of children which I then sort and present).

Hope this makes it a little more clear -- feel free to tell me if not!

Thanks for your quick reply and suggestions!

- Filip


To make it a little more clear, consider following:
<providers id="p">
     <provider id="a"/>
     <provider id="b" />
</providers>

I know I could do a selector.select("a"), but I don't know how many
of these providers there are, nor what they're called..


Yep, a selector is the wrong tool for this.  In Phoenix, you can
access the components as an array, or a map, or a list.  Unfortunately,
you can't expect that same behavior anywhere else.

I would like to say something like:

Component[] providers = selector.select("p");
for (int i=0;....) {
   providers[i].doSomething()
}

Could anybody give me some pointers on how to accomplish this ??
If this is not directly possible in avalon/excalibur -- any pointers
on what to extend to make it possible ?


One method that will work regardless of which Avalon container you
use is to provide your own manager.

In your example above, you have described a need for hierarchical
containers.  Thankfully your implementation doesn't have to be
that difficult to assemble.  In fact you can reuse some of the
Fortress internals (like the ComponentFactory) to manage the instances.

That said, you would have something along the lines of a ProviderManager
which would allow you to gain all Providers via a simple access method.
It might even let you specify which one exactly.  An example interface
would be below:

interface ProviderManager
{
    String ROLE = ProviderManager.class.getName();

Provider[] getAllProviders();

Provider findProvider(String hint);

    release( Provider provider );
    release( Provider[] provider );
}

** Note: If none of your providers are pooled, then they do not need
   to be released.  That makes the client code a bit easier to write.

The ProviderManager would create and manage all the individual
Providers that your system uses.  WHen it is shut down, it in turn
destroys all the providers it has created.


I have found that sometimes what we think we need to do isn't really what we need. IOW, without a better description of how you intend to use the providers, it is hard to provide a description of how to get the results you want without having to write the ProviderManager.


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]




--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to