You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by "David G." <da...@gmail.com> on 2012/01/16 05:08:46 UTC

Few questions around Services under felix

Couple of questions 

1) Im moving over to use the Java 5 annotations for my scr notations. I noticed that there doesn't appear to be the equivalent to valueRef in this updated syntax. What is the best practice around initializing properties? 

Previously i would have ...

@scr.property .. valueRef="com.mine.svc.FOO"  nameRef="com.mine.svc.FOO_NAME"

private static string FOO = "default foo value";
private static final string FOO_NAME = "config.foo";

activate() { 
FOO = OsgiUtil.getString(properties.get(FOO_NAME), FOO);
} 

2) I have ServiceA that all users (admins) to create multiple multiple configurations for a service (configurationFactory=true)

What is the best way to allow allow ServiceB to be configured to use ServiceA, using a specific configuration. I would like to allow the Felix admin to configure ServiceB and allow them to select/specify which configuration for ServiceA should be used. 

Ultimately i will extend this to allow ServiceB to have multiple configurations, and each configuration could use a ServiceA with a specific configuration.

3) Where on earth are the javadocs online for Felix's APIs? I can't find anything on the Felix site :( 

Thoughts?

Thanks




-- 
David Gonzalez
Sent with Sparrow (http://www.sparrowmailapp.com/?sig)


Re: Few questions around Services under felix

Posted by Felix Meschberger <fm...@adobe.com>.
Hi,

Am 17.01.2012 um 00:06 schrieb David G.:

> Felix,
> 
> One quick follow up,
> 
> Im using your suggestion for leveraging a field value to provide the default value
> 
> class FooImpl implements Foo {
> @Propert(value=Foo.FOO) 
> private static final String FOO_NAME = "config.foo";
> private static final String FOO = "default-value";
> }
> 
> The compiler is requiring that "FOO" be static and final. Is this going to pro
> 
> Being final causes issues when in activate I try to read and then write a user-specififed value:
> activate() {
>        FOO = OsgiUtil.toString(properties.get(FOO_NAME), FOO);
> }

Yes, this does not work.

What we generally do is just ad an instance field to which we assign the actual value. This does not come at a really higher price in terms of memory (at most 8bytes for the FOO reference but I am not even sure about that since its private).

> 
> 
> It was nice using the javadoc notation because i only needed 2 fields for each property (name and value (and value doubled as default value)). If possible, i would like to avoid creating a 3rd file FOO_DEFAULT and using it in the notations and as the second param in OsgiUtil.toString(..)
> 
> Im thinking ill just use 3 Fields per property in my class..
> FOO, FOO_NAME, FOO_DEFAULT

Thats what we do. Generally I name them like PROP_FOO, FOO_DEFAULT and foo (being an instance field it is lower case).

> Also, your suggestion for creating a property that sets the reference's target attribute works wonders.

Glad to hear.

> 
> And lastly, and most importantly, was Apache Felix named after you, or is your involvement just a happy coincidence?

Oh well, this question pops up every now and then .... ;-)

No, the name of the project is not related to my name in any way. Initially the project was called Oscar (after its origins). But there have been some (legal IIUIC) issues around that name and it had to be changed. So they came up with Felix. I joined the project only after it has already been renamed.

As such its just a lucky coincidence.

Regards
Felix
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: Few questions around Services under felix

Posted by "David G." <da...@gmail.com>.
Felix,

One quick follow up,

Im using your suggestion for leveraging a field value to provide the default value

class FooImpl implements Foo {
@Propert(value=Foo.FOO) 
private static final String FOO_NAME = "config.foo";
private static final String FOO = "default-value";
}

The compiler is requiring that "FOO" be static and final. Is this going to pro

Being final causes issues when in activate I try to read and then write a user-specififed value:
activate() {
        FOO = OsgiUtil.toString(properties.get(FOO_NAME), FOO);
}


It was nice using the javadoc notation because i only needed 2 fields for each property (name and value (and value doubled as default value)). If possible, i would like to avoid creating a 3rd file FOO_DEFAULT and using it in the notations and as the second param in OsgiUtil.toString(..)

Im thinking ill just use 3 Fields per property in my class..
FOO, FOO_NAME, FOO_DEFAULT

-- 

Also, your suggestion for creating a property that sets the reference's target attribute works wonders.

And lastly, and most importantly, was Apache Felix named after you, or is your involvement just a happy coincidence?

-- 
David Gonzalez
Sent with Sparrow (http://www.sparrowmailapp.com/?sig)


On Monday, January 16, 2012 at 2:21 AM, Felix Meschberger wrote:

> Hi,
> 
> Am 16.01.2012 um 05:08 schrieb David G.:
> 
> > Couple of questions 
> > 
> > 1) Im moving over to use the Java 5 annotations for my scr notations. I noticed that there doesn't appear to be the equivalent to valueRef in this updated syntax. What is the best practice around initializing properties? 
> > 
> > Previously i would have ...
> > 
> > @scr.property .. valueRef="com.mine.svc.FOO" nameRef="com.mine.svc.FOO_NAME"
> > 
> > private static string FOO = "default foo value";
> > private static final string FOO_NAME = "config.foo";
> > 
> 
> 
> Now you can use the name constant as the value:
> 
> @Property(value=FOO)
> private static final String FOO_NAME = "config.foo";
> 
> and if you add the property on the class level do:
> 
> @Property(name=MyClass.FOO_NAME, value=MyClass.FOO)
> 
> > 
> > activate() { 
> > FOO = OsgiUtil.getString(properties.get(FOO_NAME), FOO);
> > } 
> > 
> > 2) I have ServiceA that all users (admins) to create multiple multiple configurations for a service (configurationFactory=true)
> > 
> > What is the best way to allow allow ServiceB to be configured to use ServiceA, using a specific configuration. I would like to allow the Felix admin to configure ServiceB and allow them to select/specify which configuration for ServiceA should be used. 
> > 
> > Ultimately i will extend this to allow ServiceB to have multiple configurations, and each configuration could use a ServiceA with a specific configuration.
> 
> If you register ServiceA with a specific service registration property (say "prop.intentB=bla"), you can set a reference target (assuming you are using Declarative services) as in
> 
> @Reference(name="ServiceA", referenceInterface=ServiceA.class, target="(prop.intentB=bla)")
> 
> you can even make this configurable by adding a property:
> 
> @Property(name="ServiceA.target", value="(prop.intentB=bla)")
> 
> The "drawback" is, that the value of the property must be a valid OSGi filter. The name of the property is derived from the name of the @Reference with the ".target" suffix.
> 
> See the Declarative Services specification on reference targets for full details.
> 
> > 
> > 3) Where on earth are the javadocs online for Felix's APIs? I can't find anything on the Felix site :( 
> 
> There is no such thing as a singl Felix API JavaDoc. If you refer to the documentation of the Declarative Services annotation from the Maven SCR Plugin, you might want to refer to http://felix.apache.org/site/scr-annotations.html (or http://felix.apache.org/site/apache-felix-maven-scr-plugin.html).
> 
> Hope this helps.
> 
> Regards
> Felix
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org (mailto:users-unsubscribe@felix.apache.org)
> For additional commands, e-mail: users-help@felix.apache.org (mailto:users-help@felix.apache.org)
> 
> 



Re: Few questions around Services under felix

Posted by David Gonzalez <da...@gmail.com>.
Thanks Felix,

Many thanks Felix - that's makes much more sense now.

On Jan 16, 2012, at 2:22 AM, Felix Meschberger <fm...@adobe.com> wrote:

> Hi,
>
> Am 16.01.2012 um 05:08 schrieb David G.:
>
>> Couple of questions
>>
>> 1) Im moving over to use the Java 5 annotations for my scr notations. I noticed that there doesn't appear to be the equivalent to valueRef in this updated syntax. What is the best practice around initializing properties?
>>
>> Previously i would have ...
>>
>> @scr.property .. valueRef="com.mine.svc.FOO"  nameRef="com.mine.svc.FOO_NAME"
>>
>> private static string FOO = "default foo value";
>> private static final string FOO_NAME = "config.foo";
>
> Now you can use the name constant as the value:
>
> @Property(value=FOO)
> private static final String FOO_NAME = "config.foo";
>
> and if you add the property on the class level do:
>
> @Property(name=MyClass.FOO_NAME, value=MyClass.FOO)
>
>>
>> activate() {
>> FOO = OsgiUtil.getString(properties.get(FOO_NAME), FOO);
>> }
>>
>> 2) I have ServiceA that all users (admins) to create multiple multiple configurations for a service (configurationFactory=true)
>>
>> What is the best way to allow allow ServiceB to be configured to use ServiceA, using a specific configuration. I would like to allow the Felix admin to configure ServiceB and allow them to select/specify which configuration for ServiceA should be used.
>>
>> Ultimately i will extend this to allow ServiceB to have multiple configurations, and each configuration could use a ServiceA with a specific configuration.
>
> If you register ServiceA with a specific service registration property (say "prop.intentB=bla"), you can set a reference target (assuming you are using Declarative services) as in
>
> @Reference(name="ServiceA", referenceInterface=ServiceA.class, target="(prop.intentB=bla)")
>
> you can even make this configurable by adding a property:
>
> @Property(name="ServiceA.target", value="(prop.intentB=bla)")
>
> The "drawback" is, that the value of the property must be a valid OSGi filter. The name of the property is derived from the name of the @Reference with the ".target" suffix.
>
> See the Declarative Services specification on reference targets for full details.
>
>>
>> 3) Where on earth are the javadocs online for Felix's APIs? I can't find anything on the Felix site :(
>
> There is no such thing as a singl Felix API JavaDoc. If you refer to the documentation of the Declarative Services annotation from the Maven SCR Plugin, you might want to refer to http://felix.apache.org/site/scr-annotations.html (or http://felix.apache.org/site/apache-felix-maven-scr-plugin.html).
>
> Hope this helps.
>
> Regards
> Felix
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: Few questions around Services under felix

Posted by Felix Meschberger <fm...@adobe.com>.
Hi,

Am 16.01.2012 um 05:08 schrieb David G.:

> Couple of questions 
> 
> 1) Im moving over to use the Java 5 annotations for my scr notations. I noticed that there doesn't appear to be the equivalent to valueRef in this updated syntax. What is the best practice around initializing properties? 
> 
> Previously i would have ...
> 
> @scr.property .. valueRef="com.mine.svc.FOO"  nameRef="com.mine.svc.FOO_NAME"
> 
> private static string FOO = "default foo value";
> private static final string FOO_NAME = "config.foo";

Now you can use the name constant as the value:

@Property(value=FOO)
private static final String FOO_NAME = "config.foo";

and if you add the property on the class level do:

@Property(name=MyClass.FOO_NAME, value=MyClass.FOO)

> 
> activate() { 
> FOO = OsgiUtil.getString(properties.get(FOO_NAME), FOO);
> } 
> 
> 2) I have ServiceA that all users (admins) to create multiple multiple configurations for a service (configurationFactory=true)
> 
> What is the best way to allow allow ServiceB to be configured to use ServiceA, using a specific configuration. I would like to allow the Felix admin to configure ServiceB and allow them to select/specify which configuration for ServiceA should be used. 
> 
> Ultimately i will extend this to allow ServiceB to have multiple configurations, and each configuration could use a ServiceA with a specific configuration.

If you register ServiceA with a specific service registration property (say "prop.intentB=bla"), you can set a reference target (assuming you are using Declarative services) as in

@Reference(name="ServiceA", referenceInterface=ServiceA.class, target="(prop.intentB=bla)")

you can even make this configurable by adding a property:

@Property(name="ServiceA.target", value="(prop.intentB=bla)")

The "drawback" is, that the value of the property must be a valid OSGi filter. The name of the property is derived from the name of the @Reference with the ".target" suffix.

See the Declarative Services specification on reference targets for full details.

> 
> 3) Where on earth are the javadocs online for Felix's APIs? I can't find anything on the Felix site :( 

There is no such thing as a singl Felix API JavaDoc. If you refer to the documentation of the Declarative Services annotation from the Maven SCR Plugin, you might want to refer to http://felix.apache.org/site/scr-annotations.html (or http://felix.apache.org/site/apache-felix-maven-scr-plugin.html).

Hope this helps.

Regards
Felix
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org