You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@karaf.apache.org by xav <xa...@eaton.com> on 2017/03/16 17:26:56 UTC
Set dynamically a property hosted in a /etc/config file
Hi all,
I try to set dynamically a property associated at a bundle.
Explanation:
in /etc I have a configuration file for my x.y.z.MyBundle
(x.y.z.MyBundle-default.cfg)
inside it there are some properties (key/value)
The goal is outside this MyBundle (an another) I would like update some
properties of it.
I succeeded with this code
ConfigRepository configRepository;
Configuration[] configs =
configRepository.getConfigAdmin().listConfigurations("(service.factoryPid=x.y.z.MyBundle)");
Dictionary props = configs[0].getProperties();
props.put("myKey", 20);
configs[0].update(props);
It's works perfectly, but the issue, is I don't know, how I can retrieve the
factoryPid for an bundle
in fact I have the bundle object or the bundleContext, but????
I use Ipojo too
Thx for any help.
Regards
--
View this message in context: http://karaf.922171.n3.nabble.com/Set-dynamically-a-property-hosted-in-a-etc-config-file-tp4049866.html
Sent from the Karaf - User mailing list archive at Nabble.com.
Re: Set dynamically a property hosted in a /etc/config file
Posted by xav <xa...@eaton.com>.
Hi all,
I put a solution for anybody, and for challenge it.
I used bundle.getRegisteredServices(); to having all services registered by
my bundle, and I keep the service.factoryPid key to having the value. here
the code:
String returnValue = "";
ServiceReference<?>[] refs = bundle.getRegisteredServices();
if (refs != null) {
boolean isFound = false;
int size = refs.length;
for (int i = 0; i < size && !isFound; i++) {
String[] keys = refs[i].getPropertyKeys();
for (String key : keys) {
if (!key.equalsIgnoreCase(Constants.OBJECTCLASS)) {
if ("service.factoryPid".equalsIgnoreCase(key)) {
returnValue = refs[i].getProperty(key).toString();
isFound = true;
break;
}
}
}
}
}
regards
--
View this message in context: http://karaf.922171.n3.nabble.com/Set-dynamically-a-property-hosted-in-a-etc-config-file-tp4049866p4049949.html
Sent from the Karaf - User mailing list archive at Nabble.com.