> From: Raymond Auge <[email protected]>

> K, so it can't handled Object (or the anything case)?

DS can handle any type a service is registered under including 
java.lang.Object. But it does require you tell DS the service type (either 
in the interface element if you write the XML or in the service element of 
the Reference annotation which can be inferred from the first argument of 
the annotated bind method) and for the service to be registered under that 
type.

What DS cannot handle is a reference to a service with an unspecified 
name. You seem to want to bind to any service whose name endsWith MBean 
(except for DynamicMBean). And DS is not designed to do that. That is 
better for a ServiceTracker.

> ok! not a problem.

> - Ray
> 
> On Mon, Mar 30, 2015 at 2:11 PM, BJ Hargrave <[email protected]> 
wrote:
> > From: Raymond Auge <[email protected]> 
> > 
> > Does anyone see why this would not be working?
> > 
> > 
> > @Reference( 
> 
> I'll assume this is the OSGi annotation. 
> 
> >     cardinality = ReferenceCardinality.MULTIPLE,
> >     name = "MBean",
> >     policy = ReferencePolicy.DYNAMIC,
> >     policyOption = ReferencePolicyOption.GREEDY,
> >     target = "(&(jmx.objectname=*)(objectClass=*MBean)(!
> > (objectClass=javax.management.DynamicMBean)))"
> > )
> > protected void addMBean(ServiceReference<?> serviceReference) { .. }
> 
> > The XML generated is:
> > 
> > <reference 
> >     name="MBean" 
> >     cardinality="0..n" 
> >     policy="dynamic" 
> >     interface="org.osgi.framework.ServiceReference" 
> 
> The generated XML shows that the assumed serivce type is 
> ServiceReference. You probably need to set the service element in 
> the annotation to set the actual type of the service. This will set 
> the interface XML attribute properly. The interface attribute is the
> objectClass of the referenced service. 
> 
> interface: "Fully qualified name of the class that is used by the 
> component to access the service. The service provided to the 
> component must be type compatible with this class. That is, the 
> component must be able to cast the service object to this class. A 
> service must be registered under this name to be considered for the 
> set of target services. 
> 
> The Reference annotation will use the type of the first argument of the 
anno-
> tated method or the type of the annotated field to determine the 
> service value." 
> 
> >     target="(&amp;(jmx.objectname=*)(objectClass=*MBean)(!
> > (objectClass=javax.management.DynamicMBean)))" 
> 
> Putting objectClass in the target does not override the objectClass 
> stated by the interface attribute and can be in conflict. 
> 
> >     bind="addMBean" 
> >     unbind="removeMBean" 
> >     policy-option="greedy"
> > /> 
> > 
> 
> > Shouldn't this work? 
> 
> DS is not set up for this. It expects you to name a specific service
> type. Not any type whose registered service name ends with something. 
> 
-- 

BJ Hargrave
Senior Technical Staff Member, IBM
OSGi Fellow and CTO of the OSGi Alliance
[email protected]

office: +1 386 848 1781
mobile: +1 386 848 3788
_______________________________________________
OSGi Developer Mail List
[email protected]
https://mail.osgi.org/mailman/listinfo/osgi-dev

Reply via email to