Skip to content

Instantly share code, notes, and snippets.

@tonit
Created October 26, 2016 11:14
Show Gist options
  • Save tonit/8a4c7b118a5ac282313f49f509f9990f to your computer and use it in GitHub Desktop.
Save tonit/8a4c7b118a5ac282313f49f509f9990f to your computer and use it in GitHub Desktop.
@Designate( //
ocd = Configuration.class)
@Component( //
name = Connection.PID, service = { Other.class }, //
immediate = true, //
configurationPolicy = ConfigurationPolicy.REQUIRE)
public class ConnectionDefinition implements Other {
@ObjectClassDefinition(name = "My Config")
public @interface Configuration {
@AttributeDefinition(name = "some config")
long x();
}
}
@Component( //
service = { Updater.class }, //
immediate = true) //
public class UpdaterImpl implements Updater {
@Reference
ConfigurationAdmin configurationAdmin;
@Override
public void updateConfig(Params..) throws PortalException {
// here we get the java.lang.IllegalStateException: Configuration Admin service has been unregistered
final org.osgi.service.cm.Configuration configuration = configurationAdmin.getConfiguration(Connection.PID,"?");
final Dictionary<String, Object> properties = configuration.getProperties() != null ? configuration.getProperties() : new Hashtable<>();
// fill properties with overwritten values
configuration.update(properties);
}
@Component( //
service = { Updater.class }, //
immediate = true) //
public class UpdaterImpl implements Updater {
@Reference
ConfigurationAdmin configurationAdmin;
private Configuration configuration;
@Override
public void updateConfig(Params..) throws PortalException {
if (configuration == null) {
configuration = configurationAdmin.getConfiguration(Connection.PID,"?");
}
final Dictionary<String, Object> properties = configuration.getProperties() != null ? configuration.getProperties() : new Hashtable<>();
// fill properties with overwritten values
configuration.update(properties);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment