I am using component factory to create a multiple unique instances which in-turn uses services which is servicefactories to create multiple instance.
My structure looks like
TInterface - interface/service
TInterfaceInline - which implements TInterface also consists of @Reference for another service.
Tinterfaceimpl1 - extends TInterfaceInline which is a servicefactory with filter property.
TConsumer - component factory which consumes the TInterfaceInline
by getting it in @Reference.
TConsumer
@Component(name = "TConsumer", factory = "TConsumer")
@Service
public class TConsumer implements IConsumer {
// @Reference(bind = "bindInterface1", unbind = "unbindInterface1", target =
// "(className=Interface)")
// private Tinterface interface1;
@Reference(referenceInterface = ParentProfile.class, bind = "bindInterface11", unbind = "unbindInterface11", target = "(className=interface1)", policy = ReferencePolicy.STATIC, cardinality = ReferenceCardinality.MANDATORY_UNARY)
private ParentProfile interface11;
@Activate
public void activate(BundleContext aBundleContext) {
System.out.println("Object = " + interface11);
}
protected void bindInterface11(ParentProfile interface11) {
this.interface11 = interface11;
System.out.println("ref object11 created");
}
protected void unbindInterface11(ParentProfile interface11) {
interface11 = null;
}
TinterfaceImpl
@Component(name = "TInterfaceImol")
@Service(serviceFactory = true,value=ParentProfile.class)
@Properties(value = { @Property(name = "className", value = "interface1") })
public class Tinterfaceimpl1 extends TinterfaceInline {
public Tinterfaceimpl1() {
System.out.println("Generalprofile class : " + this);
}
}
TinterfaceInline
@Component(name = "TinterfaceInline ")
@Service
public class TinterfaceInline implements java.io.Serializable, ParentProfile {
// @Reference(bind = "bindtestin", unbind = "unbindtestin", cardinality =
// ReferenceCardinality.MANDATORY_UNARY, policy = ReferencePolicy.STATIC)
public Testint testin;
protected synchronized void bindtestin(Testint inter) {
this.testin = inter;
System.out.println("Profile Class : binded parameterresolver " + testin);
}
protected synchronized void unbindtestin(Testint inter) {
this.testin = inter;
}
}
ParentClass
@Component(name = "PResolver")
@Service
public class ProfileClass implements Testint {
public ProfileImpl() {
System.out.println("Parameter class impl : which extends ");
}
}
Apart from this remaining things are marker interfaces. If i try to install in karaf , the state of the Tinterfaceimpl1 is REGISTERED. ie) i am using servicefactories and accessing service factories from component factory. Servicefactory class extends a class which implements Interface. What is the reason Tinterfaceimpl1 is REGISTERED.