Beispiel #1
0
    @SuppressWarnings("unchecked")
    public <V> V findConfigurationInstanceFor(ServiceComposite serviceComposite, UnitOfWork uow)
        throws InstantiationException {
      ServiceDescriptor serviceModel = api.serviceDescriptorFor(serviceComposite);

      String identity = serviceComposite.identity().get();
      V configuration;
      try {
        configuration = uow.get(serviceModel.<V>configurationType(), identity);
        uow.pause();
      } catch (NoSuchEntityException | EntityTypeNotFoundException e) {
        return (V) initializeConfigurationInstance(serviceComposite, uow, serviceModel, identity);
      }
      return configuration;
    }
 public String restart() {
   Iterable<?> services = module.findServices(first(serviceDescriptor.types()));
   ServiceReference<?> serviceRef =
       (ServiceReference) first(filter(withId(serviceDescriptor.identity()), services));
   if (serviceRef != null) {
     try {
       ((Activation) serviceRef).passivate();
       ((Activation) serviceRef).activate();
       return "Restarted service";
     } catch (Exception e) {
       return "Could not restart service:" + e.getMessage();
     }
   } else {
     return "Could not find service";
   }
 }
 public String getType() {
   Class<?> first = first(serviceDescriptor.types());
   if (first == null) {
     return null;
   }
   return first.getName();
 }
Beispiel #4
0
    @SuppressWarnings("unchecked")
    private <V> V initializeConfigurationInstance(
        ServiceComposite serviceComposite,
        UnitOfWork uow,
        ServiceDescriptor serviceModel,
        String identity)
        throws InstantiationException {
      Module module = api.moduleOf(serviceComposite);
      Usecase usecase = UsecaseBuilder.newUsecase("Configuration:" + me.identity().get());
      UnitOfWork buildUow = module.newUnitOfWork(usecase);

      EntityBuilder<V> configBuilder =
          buildUow.newEntityBuilder(serviceModel.<V>configurationType(), identity);

      // Check for defaults
      String s = identity + ".properties";
      Class<?> type = first(api.serviceDescriptorFor(serviceComposite).types());
      // Load defaults from classpath root if available
      if (type.getResource(s) == null && type.getResource("/" + s) != null) {
        s = "/" + s;
      }
      InputStream asStream = type.getResourceAsStream(s);
      if (asStream != null) {
        try {
          PropertyMapper.map(asStream, (Composite) configBuilder.instance());
        } catch (IOException e1) {
          InstantiationException exception =
              new InstantiationException("Could not read underlying Properties file.");
          exception.initCause(e1);
          throw exception;
        }
      }

      try {
        configBuilder.newInstance();
        buildUow.complete();

        // Try again
        return (V) findConfigurationInstanceFor(serviceComposite, uow);
      } catch (Exception e1) {
        InstantiationException ex =
            new InstantiationException(
                "Could not instantiate configuration, and no Properties file was found ("
                    + s
                    + ")");
        ex.initCause(e1);
        throw ex;
      }
    }
 public boolean isAvailable() {
   Class<?> mainType = first(serviceDescriptor.types());
   ServiceReference<?> first =
       first(filter(withId(serviceDescriptor.identity()), module.findServices(mainType)));
   return first != null && first.isAvailable();
 }
 public String getVisibility() {
   return serviceDescriptor.visibility().name();
 }
 public String getId() {
   return serviceDescriptor.identity();
 }