Skip to main content
Singaiah_Chintalapudi
Level 7
Apr 26, 2016 7:13 PM UTC
Solved

Using Same OSGI Service at Multiple Times

I want to use the same OSGI service to read config values from run modes instead of developing multiple OSGI services. For example, we can click on "+" button to configure multiple DB's in felix console. Is there a way in AEM to do that?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
leeaslingAccepted solution
Level 8
Apr 26, 2016 11:37 PM UTC
@Component(metatype = true, label = "Configuration Factory", description = "Configuration Factory", configurationFactory = true) @Service public class TestConfigurationFactory { @Property(label = "Property 1", propertyPrivate = false, description = "Property 1") private static final String PROPERTY_1 = "property.one"; @Property(label = "Property 2", propertyPrivate = false, description = "Property 2") private static final String PROPERTY_2 = "property.two"; private String property1; private String property2; @Activate protected void activate(ComponentContext context) throws RepositoryException { this.property1 = PropertiesUtil.toStringArray(context.getProperties().get(PROPERTY_1)); this.property2 = PropertiesUtil.toStringArray(context.getProperties().get(PROPERTY_2)); } }

13 replies

manoj_devapath
Level 5
Apr 27, 2016 12:08 AM UTC

noksc wrote...

leeasling wrote...

I'm a little lost as to what exactly you're looking for, but you cannot have an array OSGI configuration property with multiple fields.  You can implement an array of properties by using the property definition like this

  1. @Property(label = "Multi Property", unbounded = PropertyUnbounded.ARRAY, propertyPrivate = false, description = "A property that allows multiple values")
  2. private static final String RECIPIENT_PROPERTY = "property.multiple";

If you want to have multiple values for a single item then consider using a semi-colon or a pipe delimiter, then when you read the configuration you can separate the values.

The other concerning thing is that you mention authors authoring these values in the felix console.  Nobody other than the administrator should have access to the felix console.  I would consider a different method of managing these values.

 

Okay. In a simple words, we can add multiple factory configurations to configure multiple databases in Felix console (Please see attached screen shot). In the same way, can I configure my OSGI service to configure multiple factory configurations?

 

Do you want that property as editable each time. is that what you are looking for?

Translate
edubey
Level 10
Apr 27, 2016 2:05 AM UTC

Take a look at these two well explained articles on osgi config and how you read them

OSGi Configuration Management: http://adobeaemclub.com/osgi-configuration-management-aem/

Reading OSGi Configuration properties: http://adobeaemclub.com/reading-osgi-configuration-properties/

Thanks

Translate
kautuk_sahni
Level 9
Apr 27, 2016 11:06 AM UTC

Hi

Hi

Please have a look at this community article:-

Link:- http://www.wemblog.com/2012/10/how-to-work-with-configurations-in-cq.html

//You want to create configuration which can be edited at run time using OSGI console. 

 

Another reference link:- http://www.tothenew.com/blog/creating-osgi-factory-configurations-in-aem/

I hope this is what exactly your are trying to achieve. 

 

Thanks and Regards

Kautuk Sahni

Translate
Kautuk Sahni