> From: Peter Donald [mailto:[EMAIL PROTECTED]]
>
> Hi,
>
> I have just added support for complex dependencies in Phoenix
> so that they can
> either be an array of services or a map of services. To
> declare an array you
> just postfix it with "[]" and to declare a map you postfix it
> with "#" in
> xinfo file. And then you can just access it via something like
>
> void service( ServiceManager sm )
> {
> //An array of services
> MyService[] services1 =
> (MyService[])sm.lookup( MyService[].class.getName() );
>
> //Same as above
> MyService[] services2 =
> (MyService[])sm.lookup( MyService.ROLE + "[]" );
>
> //A unmodifiable Map of services
> Map services3 =
> (Map)sm.lookup( MyService.ROLE + "#" );
> }
>
> It seems to work well. However I don't really like the idea
> of postfixing the
> service with "#" to indicate a map.
Hmmm... :-# ... :-{} ... :-<> ...
# is fine. Besides having the best smiley, # is called "hash",
and associates to HashMap for me.
> I have thought about
> using "{}" instead
> or maybe "<>" - Any preferences?
>
> Any other comments?
If this type of lookup behavior is part of framework, then maybe the
correct solution is to add methods to the ServiceManager interface.
MyService.ROLE + "[]" --> ServiceManager.lookupAll (String role);
MyService.ROLE + "#" --> ServiceManager.lookupMap (String role);
Ignoring backwards compatibility here. But say that lookupAll can be
defined
as
new Object[] { lookup (role - "[]") };
That is, for containers not supporting this naming scheme, the [] is
ignored.
Same for map - a singleton map is returned with the component mapped to
the
null key.
---------------------- Alt 2
I think that the use of the postfix magic character(s), # and [], in the
lookup() call *must* go, since they imply that the returned type (map or
array or object) isn't part of the role, but can be determined at
runtime.
Let the role string, when used in the lookup() call, remain an opaque
string.
I should be able to do:
MyService[] services2 =
(MyService[])sm.lookup( "incoming-queues" );
MyService[] services3 =
(MyService[])sm.lookup( "outgoing-queues" );
To return to your example:
<dependencies>
<dependency>
<service name="org.apache.MyService[]"/>
</dependency>
</dependencies>
+1 - this means that I have a dependency on an array of MyService.
void service( ServiceManager sm )
{
Service[] services = (Service[])sm.lookup( Service[].class.getName()
);
//use returned services here
}
NO. The [] should not be in the lookup. What if I use
Service.class.getName() + "#"
here instead? Do I get a map? Suddenly, you have dependency information
creeping back into the code and away from the xinfo.
<block class="org.apache.MyComponent" name="myComp">
<provide name="service1" role="org.apache.MyService[]"/> <provide
name="service2" role="org.apache.MyService[]"/> <provide
name="service3" role="org.apache.MyService[]"/> </block>
+1 - Fine, cool.
/LS
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>