Java Code Examples for org.osgi.service.cm.Configuration#delete()

The following examples show how to use org.osgi.service.cm.Configuration#delete() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConfigDispatcher.java    From openhab-core with Eclipse Public License 2.0 6 votes vote down vote up
private void processOrphanExclusivePIDs() {
    for (String orphanPID : exclusivePIDMap.getOrphanPIDs()) {
        try {
            Configuration configuration = null;
            if (orphanPID.contains(ConfigConstants.SERVICE_CONTEXT_MARKER)) {
                configuration = getConfigurationWithContext(orphanPID);
            } else {
                configuration = configAdmin.getConfiguration(orphanPID, null);
            }
            if (configuration != null) {
                configuration.delete();
            }
            logger.debug("Deleting configuration for orphan pid {}", orphanPID);
        } catch (IOException | InvalidSyntaxException e) {
            logger.error("Error deleting configuration for orphan pid {}.", orphanPID);
        }
    }
}
 
Example 2
Source File: DeployedCMData.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void uninstall()
    throws BundleException
{
  final ConfigurationAdmin ca = DirDeployerImpl.caTracker.getService();
  if (pids != null && ca != null) {
    for (final String pid : pids) {
      try {
        final Configuration cfg = ca.getConfiguration(pid, null);
        cfg.delete();
        installedCfgs.remove(pid);
        deleteFilePidToCmPidEntry(pid);
      } catch (final IOException e) {
        DirDeployerImpl.log("Failed to uninstall configuration with pid '"
                            + pid + "': " + e.getMessage(), e);
      }
    }
    saveState();
    pids = null;
  }
}
 
Example 3
Source File: DeployedCMData.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void uninstall()
    throws BundleException
{
  final ConfigurationAdmin ca = DirDeployerImpl.caTracker.getService();
  if (pids != null && ca != null) {
    for (final String pid : pids) {
      try {
        final Configuration cfg = ca.getConfiguration(pid, null);
        cfg.delete();
        installedCfgs.remove(pid);
        deleteFilePidToCmPidEntry(pid);
      } catch (final IOException e) {
        DirDeployerImpl.log("Failed to uninstall configuration with pid '"
                            + pid + "': " + e.getMessage(), e);
      }
    }
    saveState();
    pids = null;
  }
}
 
Example 4
Source File: Examples.java    From osgi.enroute.examples with Apache License 2.0 6 votes vote down vote up
/**
 * Create a configuration that kicks of a component with a Cron schedule
 * CronScheduleComponent
 * 
 * @throws IOException
 */

@Tooltip(description = "Create a configuration for the the ConfiguredCronScheduleComponent component. The service will stay registered until you cancel it.", deflt = "message=foo\n0/5 * * * * ?", type = "text")
public CancellablePromise<?> cronComponent(int id, String cronExpression)
		throws IOException {
	Configuration config = cm
			.getConfiguration(ConfiguredCronScheduleComponent.PID);
	Hashtable<String, Object> d = new Hashtable<String, Object>() {
		private static final long serialVersionUID = 1L;
		{
			put(CronJob.CRON, cronExpression);
			put("id", id);
		}
	};
	config.update(d);

	return new Closer<Object>(() -> config.delete());
}
 
Example 5
Source File: ConfigDispatcher.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
private void processOrphanExclusivePIDs() {
    for (String orphanPID : exclusivePIDMap.getOrphanPIDs()) {
        try {
            Configuration configuration = null;
            if (orphanPID.contains(ConfigConstants.SERVICE_CONTEXT_MARKER)) {
                configuration = getConfigurationWithContext(orphanPID);
            } else {
                configuration = configAdmin.getConfiguration(orphanPID, null);
            }
            if (configuration != null) {
                configuration.delete();
            }
            logger.debug("Deleting configuration for orphan pid {}", orphanPID);
        } catch (IOException | InvalidSyntaxException e) {
            logger.error("Error deleting configuration for orphan pid {}.", orphanPID);
        }
    }
}
 
Example 6
Source File: CreationIT.java    From wisdom with Apache License 2.0 6 votes vote down vote up
protected void cleanupConfigurationAdmin() throws IOException, InvalidSyntaxException {
    Configuration[] configurations = admin.listConfigurations(null);
    if (configurations != null) {
        for (Configuration conf : configurations) {
            if (!conf.getPid().contains("instantiated.at.boot")) {
                conf.delete();
            }
        }
    }

    await().atMost(1, TimeUnit.MINUTES).until(new Callable<Boolean>() {
        @Override
        public Boolean call() throws Exception {
            return osgi.getServiceObject(MyComponent.class) == null;
        }
    });
}
 
Example 7
Source File: InstanceGrapeIT.java    From wisdom with Apache License 2.0 6 votes vote down vote up
protected void cleanupConfigurationAdmin() throws IOException, InvalidSyntaxException {
    Configuration[] configurations = admin.listConfigurations(null);
    if (configurations != null) {
        for (Configuration conf : configurations) {
            if (!conf.getPid().contains("instantiated.at.boot")) {
                conf.delete();
            }
        }
    }
    // Wait until instances are deleted
    await().atMost(1, TimeUnit.MINUTES).until(new Callable<Boolean>() {
        @Override
        public Boolean call() throws Exception {
            return osgi.getServiceObject(C1.class) == null
                    && osgi.getServiceObject(C2.class) == null
                    && osgi.getServiceObject(C3.class) == null;

        }
    });
}
 
Example 8
Source File: TargetPanel.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Deletes the currently selected configuration.
 *
 * @throws IOException
 */
void deleteSelectedConfiguration()
    throws IOException
{
  final Configuration cfg = getSelectedConfiguration();
  if (cfg != null) {
    cfg.delete();
    // UI will be updated from the ConfgurationListener callback.
  } else {
    JCMService.showError(this, "Can not delete non-existing configuration.", null);
  }
}
 
Example 9
Source File: ComponentTestSuite.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void deleteConfig(ConfigurationAdmin ca, String location) throws IOException, InvalidSyntaxException {
  Configuration [] cs = ca.listConfigurations("(" + ConfigurationAdmin.SERVICE_BUNDLELOCATION + "=" + location + ")");
  if (cs != null) {
    for (Configuration c : cs) {
      c.delete();
    }
  }
}
 
Example 10
Source File: ServiceManager.java    From packagedrone with Eclipse Public License 1.0 5 votes vote down vote up
public void delete ( final String pid ) throws IOException
{
    final Configuration cfg = this.configAdmin.getConfiguration ( pid );
    if ( cfg != null )
    {
        cfg.delete ();
    }
}
 
Example 11
Source File: CreationIT.java    From wisdom with Apache License 2.0 5 votes vote down vote up
@Test
public void testDynamicInstantiationAndDeletion() throws IOException, InterruptedException {
    assertThat(osgi.getServiceObject(MyComponent.class)).isNull();

    final Configuration configuration = admin.getConfiguration("org.wisdom.conf");
    Properties properties = new Properties();
    properties.put("user", "wisdom");
    configuration.update(properties);

    await().atMost(1, TimeUnit.MINUTES).until(new Callable<Boolean>() {
        @Override
        public Boolean call() throws Exception {
            return osgi.getServiceObject(MyComponent.class) != null;
        }
    });

    MyComponent service = osgi.getServiceObject(MyComponent.class);
    assertThat(service).isNotNull();
    assertThat(service.hello()).contains("wisdom");

    // Deleting the configuration

    configuration.delete();

    await().atMost(1, TimeUnit.MINUTES).until(new Callable<Boolean>() {
        @Override
        public Boolean call() throws Exception {
            return osgi.getServiceObject(MyComponent.class) == null;
        }
    });

    assertThat(osgi.getServiceObject(MyComponent.class)).isNull();
}
 
Example 12
Source File: CreationIT.java    From wisdom with Apache License 2.0 5 votes vote down vote up
@Test
public void testDynamicInstantiationAndDeletionUsingConfigurationFactory()
        throws IOException, InterruptedException {
    assertThat(osgi.getServiceObject(MyComponent.class)).isNull();

    final Configuration configuration = admin.createFactoryConfiguration("org.wisdom.conf");
    Properties properties = new Properties();
    properties.put("user", "wisdom");
    configuration.update(properties);

    await().atMost(1, TimeUnit.MINUTES).until(new Callable<Boolean>() {
        @Override
        public Boolean call() throws Exception {
            return osgi.getServiceObject(MyComponent.class) != null;
        }
    });

    MyComponent service = osgi.getServiceObject(MyComponent.class);
    assertThat(service).isNotNull();
    assertThat(service.hello()).contains("wisdom");

    // Deleting the configuration

    configuration.delete();

    await().atMost(1, TimeUnit.MINUTES).until(new Callable<Boolean>() {
        @Override
        public Boolean call() throws Exception {
            return osgi.getServiceObject(MyComponent.class) == null;
        }
    });

    assertThat(osgi.getServiceObject(MyComponent.class)).isNull();
}
 
Example 13
Source File: InstanceGrapeIT.java    From wisdom with Apache License 2.0 4 votes vote down vote up
@Test
public void testDynamicInstantiationAndDeletion() throws IOException, InterruptedException {
    final Configuration configuration = admin.getConfiguration("org.wisdom.grape");
    Properties properties = new Properties();
    properties.put("user", "wisdom");
    properties.put("message", "hello");
    configuration.update(properties);

    await().atMost(1, TimeUnit.MINUTES).until(new Callable<Boolean>() {
        @Override
        public Boolean call() throws Exception {
            return
                    osgi.getServiceObject(C1.class) != null
                            && osgi.getServiceObject(C2.class) != null
                            && osgi.getServiceObject(C3.class) != null;
        }
    });

    final C1 c1 = osgi.getServiceObject(C1.class);
    final C2 c2 = osgi.getServiceObject(C2.class);
    final C3 c3 = osgi.getServiceObject(C3.class);

    assertThat(c1).isNotNull();
    assertThat(c2).isNotNull();
    assertThat(c3).isNotNull();

    assertThat(c1.hello()).contains("wisdom");
    assertThat(c2.hello()).contains("wisdom");
    assertThat(c3.hello()).contains("hello");

    // Deleting the configuration

    configuration.delete();

    await().atMost(1, TimeUnit.MINUTES).until(new Callable<Boolean>() {
        @Override
        public Boolean call() throws Exception {
            return osgi.getServiceObject(C1.class) == null
                    && osgi.getServiceObject(C2.class) == null
                    && osgi.getServiceObject(C3.class) == null;
        }
    });

    assertThat(osgi.getServiceObject(C1.class)).isNull();
    assertThat(osgi.getServiceObject(C2.class)).isNull();
    assertThat(osgi.getServiceObject(C3.class)).isNull();
}
 
Example 14
Source File: InstanceGrapeIT.java    From wisdom with Apache License 2.0 4 votes vote down vote up
@Test
public void testDynamicInstantiationAndDeletionUsingConfigurationFactory() throws IOException,
        InterruptedException {
    final Configuration configuration = admin.createFactoryConfiguration("org.wisdom.grape");
    Properties properties = new Properties();
    properties.put("user", "wisdom");
    properties.put("message", "hello");
    configuration.update(properties);

    await().atMost(1, TimeUnit.MINUTES).until(new Callable<Boolean>() {
        @Override
        public Boolean call() throws Exception {
            return
                    osgi.getServiceObject(C1.class) != null
                            && osgi.getServiceObject(C2.class) != null
                            && osgi.getServiceObject(C3.class) != null;
        }
    });

    final C1 c1 = osgi.getServiceObject(C1.class);
    final C2 c2 = osgi.getServiceObject(C2.class);
    final C3 c3 = osgi.getServiceObject(C3.class);

    assertThat(c1).isNotNull();
    assertThat(c2).isNotNull();
    assertThat(c3).isNotNull();

    assertThat(c1.hello()).contains("wisdom");
    assertThat(c2.hello()).contains("wisdom");
    assertThat(c3.hello()).contains("hello");

    // Deleting the configuration

    configuration.delete();

    await().atMost(1, TimeUnit.MINUTES).until(new Callable<Boolean>() {
        @Override
        public Boolean call() throws Exception {
            return osgi.getServiceObject(C1.class) == null
                    && osgi.getServiceObject(C2.class) == null
                    && osgi.getServiceObject(C3.class) == null;
        }
    });

    assertThat(osgi.getServiceObject(C1.class)).isNull();
    assertThat(osgi.getServiceObject(C2.class)).isNull();
    assertThat(osgi.getServiceObject(C3.class)).isNull();
}