That would help. Some more details.

@Component(immediate = true)
public class BundleAComponent {

    @Reference
    private Bar bar;

    @Activate
    private void activate(BundleContext context){
        ServiceRegistration sr =
context.registerService(Foo.class.getName(),new FooClient(bar),null);
        ...
    }

    ...
}

So FooClient requires an instance of Bar service. And I wanted to use DS to
access Bar reference. So what I would try is register an inner
ServiceFactory class which returns the Foo instance. Would require some
extra logic but would delay loading of classes untill required.

Thanks for the pointer!!

Chetan Mehrotra


On Sat, Aug 4, 2012 at 10:07 PM, Neil Bartlett <[email protected]> wrote:

> Thanks for the clarifications.
>
> It's generally a bad idea to use non-interfaces for services...
> because if the client knows the specific class, why bother looking up
> a service? Nevertheless there are some edge cases where you might want
> to do this, so I'll assume you're in one of those.
>
> What you should do is register an object that implements
> "ServiceFactory" from the core OSGi API. This object should be
> registered under the classname of Foo but it is not actually a Foo...
> instead it should return instances of Foo from its "getService"
> method.
>
> Regards,
> Neil
>
> On Sat, Aug 4, 2012 at 5:24 PM, Chetan Mehrotra
> <[email protected]> wrote:
> > Thanks Neil for the suggestions.
> >
> >> Not really. The problem is this part: "FooClient is created as
> >> required". When is that exactly?
> >
> > I mean that Component activate method should be invoked only when any
> other
> > bundle class performs a lookup for Foo service
> >
> >> component is not a service then there is no such signal, so DS is
> >> forced to immediately activate the component.
> >
> > Yes that is the problem. Is it possible for component to say that I can
> > provide Foo service without using @Service annotation.
> >
> > The problem is the Foo.class is not an interface hence I cannot proxy it
> > (easily). The Component support used here is more like Factory pattern to
> > create a class instance which cannot be instantiated directly by the
> > container as i need to set some properties on FooClient before
> registering
> > it.
> >
> > So to put it simple - Is it possible to use lazy activation for servies
> are
> > created using a factory class and are not created directly by container?
> >
> > Chetan Mehrotra
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>

Reply via email to