Skip to content

Instantly share code, notes, and snippets.

@shsteimer
Last active January 4, 2016 07:49
Show Gist options
  • Save shsteimer/8591063 to your computer and use it in GitHub Desktop.
Save shsteimer/8591063 to your computer and use it in GitHub Desktop.
@Component(configurationFactory = true,
policy = ConfigurationPolicy.REQUIRE, metatype = true, immediate = true)
@Service()
public class MyFactoryConfigServiceClass {
//define config properties here as usual
@Property(name = "some.prop.name", label = "My Property", value = "")
private String myProperty
/**
* Activate the configuration.
*
* @param ctx
* the component context object
*/
@Activate
protected void activate(final ComponentContext ctx) {
log.info("activating instance of {}", this.getClass().getName());
Dictionary<?, ?> props = ctx.getProperties();
//init property values using PropertiesUtil
myProperty = PropertiesUtil.toString(props.get("some.prop.name"),"");
}
}
@Component()
@Service()
public class MyFactoryConsumer {
@Reference(referenceInterface = MyFactoryConfigServiceClass.class, cardinality = ReferenceCardinality.OPTIONAL_MULTIPLE,
policy = ReferencePolicy.DYNAMIC)
private List<MyFactoryConfigServiceClass> configs;
protected synchronized void bindMyFactoryConfigServiceClass(final MyFactoryConfigServiceClass config) {
if (configs == null) {
configs = new ArrayList<MyFactoryConfigServiceClass>();
}
configs.add(config);
}
protected synchronized void unbindMyFactoryConfigServiceClass(final MyFactoryConfigServiceClass config) {
configs.remove(config);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment