code: public static <T> T retrieveService(Class<T> clazz, Registry registry) {
          if(registry == null) {
              throw new IllegalArgumentException("Registry cannot be null.");
          }
  
          Set<T> servicesFromRegistry = registry.findByType(clazz);
          if (servicesFromRegistry.size() == 1) {
              T service = servicesFromRegistry.iterator().next();
              LOG.info("Found Kura " + clazz.getCanonicalName() + " in the registry. Kura component will use that instance.");
              return service;
          } else if (servicesFromRegistry.size() > 1) {
              throw new IllegalStateException("Too many " + clazz.getCanonicalName() + " services found in a registry: "
                      + servicesFromRegistry.size());
          } else {
              throw new IllegalArgumentException(
                      "No " + clazz.getCanonicalName() + " service instance found in a registry.");
          }
      }
docs: Operations