Created
October 26, 2016 11:14
-
-
Save tonit/8a4c7b118a5ac282313f49f509f9990f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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