You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@karaf.apache.org by Steinar Bang <sb...@dod.no> on 2018/03/09 18:18:59 UTC

What feature is needed to make DS work?

What karaf feature is needed to make Declarative Services work?

I thought it was the "scr" feature, but that wasn't enough.

Thanks!


- Steinar


Re: What feature is needed to make DS work?

Posted by Steinar Bang <sb...@dod.no>.
>>>>> Steinar Bang <sb...@dod.no>:
>>>>> David Jencks <da...@gmail.com>:

>> One point some ds beginners miss is that if your component provides a
>> service by default it is delayed and won’t be instantiated until the
>> service is used.

> Ahh!  That explains why the first component isn't instantiated until the
> second bundle is loaded, and why the second component shows up only as
> SATISFIED:

Another thing this explains: why the pax exam integration test worked,
while actually running the app in karaf didn't work.  Using @Inject in
the pax exam integration test registers an interest for the service
provided by OSGi bundle number two.

>> This laziness is great but can be confusing. Specify immediate=true if
>> you want to see all the components instantiated as soon as all their
>> dependencies are satisfied.

> Thanks! I will try this.

Specifying immediate=true made everything work, thanks!
 https://github.com/steinarb/ukelonn/blob/c14dfbb9a1e0f59a0ac407ec9d82281e29f67097/ukelonn.bundle/src/main/java/no/priv/bang/ukelonn/impl/UkelonnServiceProvider.java



Re: What feature is needed to make DS work?

Posted by Steinar Bang <sb...@dod.no>.
>>>>> David Jencks <da...@gmail.com>:

> One point some ds beginners miss is that if your component provides a
> service by default it is delayed and won’t be instantiated until the
> service is used.

Ahh!  That explains why the first component isn't instantiated until the
second bundle is loaded, and why the second component shows up only as
SATISFIED:
 karaf@root()> scr:components
 ID | State     | Component Name
 ---+-----------+------------------------------------------------------------
 1  | ACTIVE    | org.ops4j.pax.web.service.internal.WhiteboardDtoService
 2  | ACTIVE    | no.priv.bang.ukelonn.bundle.db.test.UkelonnDatabaseProvider
 3  | ACTIVE    | org.ops4j.pax.web.deployer.internal.WarDeployer
 4  | SATISFIED | no.priv.bang.ukelonn.impl.UkelonnServiceProvider
 karaf@root()>

> This laziness is great but can be confusing. Specify immediate=true if
> you want to see all the components instantiated as soon as all their
> dependencies are satisfied.

Thanks! I will try this.

My prior attempts at DS has been servlets for the Pax Web Whiteboard
Extender, and there, of course, the components have been automatically
instantiated and used...

For the curious: here's the bundle activator I'm replacing (my own home
brewed "mini dependency injection" system from a couple of years back):
 https://github.com/sbang/jsr330activator#jsr330activator---an-osgi-bundleactivator-implementing-whiteboard-based-dependency-injection

Why I'm phasing it out:
 https://github.com/sbang/jsr330activator#is-the-jsr330activator-necessary-after-declarative-services-arrived


Re: What feature is needed to make DS work?

Posted by David Jencks <da...@gmail.com>.
One point some ds beginners miss is that if your component provides a service by default it is delayed and won’t be instantiated until the service is used. This laziness is great but can be confusing. Specify immediate=true if you want to see all the components instantiated as soon as all their dependencies are satisfied.

Hope this helps
David Jencks 

Sent from my iPhone

On Mar 9, 2018, at 1:41 PM, Steinar Bang <sb...@dod.no> wrote:

>>>>>> Christian Schneider <ch...@die-schneider.net>:
> 
>> You only need the scr feature.
>> Then you can use the scr:* commands to look into your components.
> 
>> How do you see that it does not work?
> 
> I'm putting breakpoints in different injection points and they aren't
> called or they are strangely called.
> 
> I haven't pushed my current DS work yet, but what I'm trying to do is
> replace my current bundle activator based solution with DS.
> 
> What I see in the debugger is that the first component shows up in
> capabilities but doesn't get any injections.
> 
> Then I load the bundle with the next component, and the first component
> suddenly gets its injections (a LogService and a DataSourceFactory).
> 
> But the second component, that triggered the entire thing, doesn't get
> any injections (it was supposed to get a LogService and a service from
> the component in the first bundle.  Ie. the component that just saw
> getting its injections, in the debugger).
> 
> The second bundle is a war bundle, not a jar bundle.  Is that a problem?
> 
> I'll try the scr commands and see what they can tell me.
> 
>> Maybe you use the wrong annotations or the wrong version of the bundle
>> plugin.
> 
> import org.osgi.service.component.annotations.Component;
> import org.osgi.service.component.annotations.Reference;
> 
> <plugin>
>    <groupId>org.apache.felix</groupId>
>    <artifactId>maven-bundle-plugin</artifactId>
>    <version>2.5.3</version>
> </plugin>
> 

Re: What feature is needed to make DS work?

Posted by Steinar Bang <sb...@dod.no>.
>>>>> Christian Schneider <ch...@die-schneider.net>:

> You only need the scr feature.
> Then you can use the scr:* commands to look into your components.

> How do you see that it does not work?

I'm putting breakpoints in different injection points and they aren't
called or they are strangely called.

I haven't pushed my current DS work yet, but what I'm trying to do is
replace my current bundle activator based solution with DS.

What I see in the debugger is that the first component shows up in
capabilities but doesn't get any injections.

Then I load the bundle with the next component, and the first component
suddenly gets its injections (a LogService and a DataSourceFactory).

But the second component, that triggered the entire thing, doesn't get
any injections (it was supposed to get a LogService and a service from
the component in the first bundle.  Ie. the component that just saw
getting its injections, in the debugger).

The second bundle is a war bundle, not a jar bundle.  Is that a problem?

I'll try the scr commands and see what they can tell me.

> Maybe you use the wrong annotations or the wrong version of the bundle
> plugin.

import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;

<plugin>
    <groupId>org.apache.felix</groupId>
    <artifactId>maven-bundle-plugin</artifactId>
    <version>2.5.3</version>
</plugin>


Re: What feature is needed to make DS work?

Posted by Christian Schneider <ch...@die-schneider.net>.
You only need the scr feature.

Then you can use the scr:* commands to look into your components.

How do you see that it does not work?

Maybe you use the wrong annotations or the wrong version of the bundle
plugin.

Christian

2018-03-09 19:18 GMT+01:00 Steinar Bang <sb...@dod.no>:

> What karaf feature is needed to make Declarative Services work?
>
> I thought it was the "scr" feature, but that wasn't enough.
>
> Thanks!
>
>
> - Steinar
>
>


-- 
-- 
Christian Schneider
http://www.liquid-reality.de

Computer Scientist
http://www.adobe.com