i'm using multiple instances of osgi components/services. These osgi components are configured with configuration policy = required and instantiated and deleted by adding or deleting configurations via ConfigurationAdmin. Furthermore I use "sets" of service instances and each set is configured via its configuration to only use service instances from the same set as reference (ref.target=(id="123")).
The Problem: At some point a set should be deleted. But when deleting the configuration objects from one set via ConfigAdmin some of the services of a different set deactivate too. They reactivate instantly but they lose all service references and are unusable.
I can't figure out why they are deactivating.
EDIT
A service is typically defined like this:
@Component(policy = ConfigurationPolicy.REQUIRE)
@Service
public class AServiceImpl implements AService {
@Reference(target = "(service.pid=*)")
BService bService;
...
}
BServiceImpl also uses config policy required.
The target is set in the annotation because of this doc snippet from felix scr:
A service target filter to select specific services to be made available. In order to be able to overwrite the value of this value by a configuration property, this parameter must be declared. If the parameter is not declared, the respective declaration attribute will not be generated
When a new service "set" is instantiated these steps are performed for every service of the set:
for each service
Configuration serviceConfiguration = configurationAdmin.createFactoryConfiguration(serviceInterfaceName, null);
for each reference of each service
Properties serviceProperties.put(ref + ".target", "(" + PID + "=" + pid + ")");
...
serviceConfiguration.update(dict);
I logged the config property pid of the references in bindXXX() methods and the filter seems to work. I always get references with equal pid.
I will add a running example on github asap.
EDIT2
I've added an example which demonstrates the behaviour. I create two "sets" of services, call a service function and delete the service sets after the function finished. Service set two reactivates when deleting service set one.
Code example https://github.com/andineupert/osgi-configadmin-example.git
I finally realized it was caused by an old equinox implementation of declarative services. I switched to org.apache.felix.scr 2.0.4 and now its working perfectly.