You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@karaf.apache.org by Kamil Paśko <ka...@antologic.com> on 2019/08/29 15:48:23 UTC

Inconsistency between ConfigurationPolicy.REQUIRE and ReferenceCardinality.MANDATORY?

Dear Karaf users,

I have a DS Component:
@Component(
    immediate = true,
    scope = ServiceScope.BUNDLE,
    configurationPolicy = ConfigurationPolicy.OPTIONAL,
    configurationPid = MyComponent.CONFIGURATION_PID
)
public class MyComponent  {
  static final String CONFIGURATION_PID = "7895a3c9bac628248";

  @Activate
  public MyComponent (final BundleContext bundleContext, final Map<String, Object> config,
                                     @Reference(cardinality = ReferenceCardinality.MANDATORY) final AuthenticationService authenticationService) {
    If(authenticationService.authenticate(CONFIGURATION) == false)  {
       thrown new RuntimeException(„not authenticated”)
    }
}

  @Deactivate
  public void deactivate() {
    //cleanup
  }
}
And this Component is the only component in the „myBundle”.

Now:
1) Because AuthenticationService is mandatory – if I start myBundle (containing only MyComponent) when AuthenticationService is not available – then myBundle has status waiting (which is perfectly fine)
2) When MyComponent is active and myBundle is also active and I stop AuthenticationService – then myBundle has status waiting (which is perfectly fine as well)
3) When AuthenticationService is available, but authenticationService.authenticate method fails, then exception is thrown and myBundle has status waiting (which is perfectly fine as well)
4) But when AuthenticationService is available and authenticationService.authenticate may be true but „7895a3c9bac628248.cfg” file is missing, then MyComponent is not activated but myBundle has status active! Why and how to make it „waiting”?

Kind regards,
Kamil