You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by Daniel Bimschas <bi...@itm.uni-luebeck.de> on 2010/02/06 14:17:01 UTC

Best practice to configure service (factories) with complex objects

Hi list!

I've posted this question on osgi-dev@mail.osgi.org, too, but as this list is more active by far I thought I would also give it a try :-).

I'm writing an application that uses Configuration Admin to be configured at runtime. Now, for one of my DS components I have a more complex configuration requirement. Assume e.g. I want to configure the component to create a set of TCP connections. Using XML configuration I would use something like this snippet:

 <connections>
   <connection>
     <host>somehost.com</host>
     <port>1234</port>
   </connection>
   <connection>
     <host>someotherhost.com</host>
     <port>4321</port>
   </connection>
 </connections>

My question now is if there's an elegant way to map such a set of complex configuration objects to Configuration Admins properties file format? Maybe I don't see the wood for the trees but I can't think of a nice way (so that I could also use the Metatype Service specification), except this suboptimal one:

 connection.host = {somehost.com,someotherhost.com}
 connection.port = {1234,4321}

where each entry of the string array of the property 'connection.host' key must have an according entry 'connection.port' with the same index. However, that solution will make editing the configuration files very error prone and unintuitive.

I can think of another alternative, which is using a component factory that creates one instance of my service per connection configuration. But I have other use cases for which this approach would not be feasible.

If there's no elegant way my next question is the following: are there any activities towards an XML based counterpart to Configuration Admin Service and Metatype Service?


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


Re: Best practice to configure service (factories) with complex objects

Posted by Carsten Ziegeler <cz...@apache.org>.
Daniel Bimschas wrote:
> Hi list!
> 
> I've posted this question on osgi-dev@mail.osgi.org, too, but as this list is more active by far I thought I would also give it a try :-).
> 
> I'm writing an application that uses Configuration Admin to be configured at runtime. Now, for one of my DS components I have a more complex configuration requirement. Assume e.g. I want to configure the component to create a set of TCP connections. Using XML configuration I would use something like this snippet:
> 
>  <connections>
>    <connection>
>      <host>somehost.com</host>
>      <port>1234</port>
>    </connection>
>    <connection>
>      <host>someotherhost.com</host>
>      <port>4321</port>
>    </connection>
>  </connections>
> 
> My question now is if there's an elegant way to map such a set of complex configuration objects to Configuration Admins properties file format? Maybe I don't see the wood for the trees but I can't think of a nice way (so that I could also use the Metatype Service specification), except this suboptimal one:
> 
>  connection.host = {somehost.com,someotherhost.com}
>  connection.port = {1234,4321}
> 
> where each entry of the string array of the property 'connection.host' key must have an according entry 'connection.port' with the same index. However, that solution will make editing the configuration files very error prone and unintuitive.
> 
> I can think of another alternative, which is using a component factory that creates one instance of my service per connection configuration. But I have other use cases for which this approach would not be feasible.
> 
We usually solve such problems by using this mentioned alternative: a
component factory for connections and some kind of manager service that
holds all connections.
I think there are usually two different problems involved: a) a list of
configurations (like in your connections example) and b) a structured
configuration for a single component. While you can solve a) with the
factory approach, b) is more difficult. For b) we sometimes use special
string constructs like if you want to a configuration like:
<server>
  <name/>
  <port/>
</server>
we have a single config property "server" with a value like "name|port".

HTH
Carsten
-- 
Carsten Ziegeler
cziegeler@apache.org

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


Re: Best practice to configure service (factories) with complex objects

Posted by Daniel Bimschas <bi...@itm.uni-luebeck.de>.
Tim,

thank you for your answer. I did something like that, too. But with that kind of solution I can't use MetaType Service as it only allows to declare a fixed set of allowed keys (please somebody correct me on that if I'm wrong here!).

Also the host:port thing is fine for host and port scenario but you don't want to be editing such a string if you have a list with lets say ten properties per object (key = prop1:prop2:prop3:prop4:....). It's like manually writing CSV files which somewhat sucks.

Regarding my XML-related question I would like to use the power of validation against a schema.

Cheers,
Daniel

Am 06.02.2010 um 16:52 schrieb Tim Moloney:

> Daniel Bimschas wrote:
>> I'm writing an application that uses Configuration Admin to be configured at runtime. Now, for one of my DS components I have a more complex configuration requirement. Assume e.g. I want to configure the component to create a set of TCP connections. Using XML configuration I would use something like this snippet:
>> 
>> <connections>
>>   <connection>
>>     <host>somehost.com</host>
>>     <port>1234</port>
>>   </connection>
>>   <connection>
>>     <host>someotherhost.com</host>
>>     <port>4321</port>
>>   </connection>
>> </connections>
>> 
>> My question now is if there's an elegant way to map such a set of complex configuration objects to Configuration Admins properties file format? Maybe I don't see the wood for the trees but I can't think of a nice way (so that I could also use the Metatype Service specification), except this suboptimal one:
>> 
>> connection.host = {somehost.com,someotherhost.com}
>> connection.port = {1234,4321}
>> 
>> where each entry of the string array of the property 'connection.host' key must have an according entry 'connection.port' with the same index. However, that solution will make editing the configuration files very error prone and unintuitive.
> 
> I've solved the same problem in the past, although I don't know if what I've done is a best practice.
> 
> I configure my apps as follows:
> 
> connection.name1 = somehost.com:1234
> connection.name2 = someotherhost.com:4321
> 
> All the connections are prefixed by "connection." (or something similar) so it is easy to find them and do string manipulation.  Each connection also has a name that you may find useful in your application (use as a key into maps, put in error messages, etc.).  The "somehost.com:1234" is similar in syntax to what is used in HTTP and scp so you don't have to learn a new syntax.  It also keeps your hostname and port together to reduce editing mistakes as you pointed out above.  If your connection can be made with different protocols, then you can use a URL for the value (e.g., "http://somehost.com:1234/", ftp://someotherhost.com:4321/", etc.).
> 
> Tim
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
> 

-- 
M.Sc. Daniel Bimschas
Institute of Telematics, University of Lübeck
http://www.itm.uni-luebeck.de/users/bimschas
Ratzeburger Allee 160, 23538 Lübeck, Germany
Phone: +49 451 500 5389


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


Re: Best practice to configure service (factories) with complex objects

Posted by Tim Moloney <t....@verizon.net>.
Daniel Bimschas wrote:
> I'm writing an application that uses Configuration Admin to be configured at runtime. Now, for one of my DS components I have a more complex configuration requirement. Assume e.g. I want to configure the component to create a set of TCP connections. Using XML configuration I would use something like this snippet:
>
>  <connections>
>    <connection>
>      <host>somehost.com</host>
>      <port>1234</port>
>    </connection>
>    <connection>
>      <host>someotherhost.com</host>
>      <port>4321</port>
>    </connection>
>  </connections>
>
> My question now is if there's an elegant way to map such a set of complex configuration objects to Configuration Admins properties file format? Maybe I don't see the wood for the trees but I can't think of a nice way (so that I could also use the Metatype Service specification), except this suboptimal one:
>
>  connection.host = {somehost.com,someotherhost.com}
>  connection.port = {1234,4321}
>
> where each entry of the string array of the property 'connection.host' key must have an according entry 'connection.port' with the same index. However, that solution will make editing the configuration files very error prone and unintuitive.

I've solved the same problem in the past, although I don't know if what 
I've done is a best practice.

I configure my apps as follows:

  connection.name1 = somehost.com:1234
  connection.name2 = someotherhost.com:4321

All the connections are prefixed by "connection." (or something similar) 
so it is easy to find them and do string manipulation.  Each connection 
also has a name that you may find useful in your application (use as a 
key into maps, put in error messages, etc.).  The "somehost.com:1234" is 
similar in syntax to what is used in HTTP and scp so you don't have to 
learn a new syntax.  It also keeps your hostname and port together to 
reduce editing mistakes as you pointed out above.  If your connection 
can be made with different protocols, then you can use a URL for the 
value (e.g., "http://somehost.com:1234/", 
ftp://someotherhost.com:4321/", etc.).

Tim


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


Re: Best practice to configure service (factories) with complex objects

Posted by Geert Schuring <ge...@schuring.eu>.
Hi Daniel,

Allow me to answer both your questions at once: I have not found an elegant 
way to map collections of complex objects to property files, which is why I 
created a custom service that stores jaxb annotated objects for me in a 
persistend datastore. My services store and retrieve these objects during 
instance creation and finalization. I found it to be the best way to solve 
the problem.

Now that I think of it, we can also use the Config Admin to store marshalled 
objects in properties...

Anyway, in my opinion this matter is important enough to extend the Metatype 
service with a "marshalled objects" type.

Geert Schuring.

--------------------------------------------------
From: "Daniel Bimschas" <bi...@itm.uni-luebeck.de>
Sent: Saturday, February 06, 2010 2:17 PM
To: <us...@felix.apache.org>
Subject: Best practice to configure service (factories) with complex objects

> Hi list!
>
> I've posted this question on osgi-dev@mail.osgi.org, too, but as this list 
> is more active by far I thought I would also give it a try :-).
>
> I'm writing an application that uses Configuration Admin to be configured 
> at runtime. Now, for one of my DS components I have a more complex 
> configuration requirement. Assume e.g. I want to configure the component 
> to create a set of TCP connections. Using XML configuration I would use 
> something like this snippet:
>
> <connections>
>   <connection>
>     <host>somehost.com</host>
>     <port>1234</port>
>   </connection>
>   <connection>
>     <host>someotherhost.com</host>
>     <port>4321</port>
>   </connection>
> </connections>
>
> My question now is if there's an elegant way to map such a set of complex 
> configuration objects to Configuration Admins properties file format? 
> Maybe I don't see the wood for the trees but I can't think of a nice way 
> (so that I could also use the Metatype Service specification), except this 
> suboptimal one:
>
> connection.host = {somehost.com,someotherhost.com}
> connection.port = {1234,4321}
>
> where each entry of the string array of the property 'connection.host' key 
> must have an according entry 'connection.port' with the same index. 
> However, that solution will make editing the configuration files very 
> error prone and unintuitive.
>
> I can think of another alternative, which is using a component factory 
> that creates one instance of my service per connection configuration. But 
> I have other use cases for which this approach would not be feasible.
>
> If there's no elegant way my next question is the following: are there any 
> activities towards an XML based counterpart to Configuration Admin Service 
> and Metatype Service?
>
>
> Kind regards,
> Daniel Bimschas
> ---------------------------------------------------------------------
> 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