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?
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]
