use of org.apache.felix.dm.ConfigurationDependency in project felix by apache.
the class DependencyBuilder method createConfigurationDependency.
private Dependency createConfigurationDependency(DependencyManager dm, Bundle b, String pid, String callback, String confProxyType, boolean propagate, boolean required) throws ClassNotFoundException {
if (pid == null) {
throw new IllegalArgumentException("pid attribute not provided in ConfigurationDependency declaration");
}
ConfigurationDependency cd = dm.createConfigurationDependency();
cd.setPid(pid);
if (confProxyType != null) {
Class<?> confProxyTypeClass = b.loadClass(confProxyType);
cd.setCallback(callback, confProxyTypeClass);
} else {
cd.setCallback(callback);
}
cd.setPropagate(propagate);
cd.setRequired(required);
return cd;
}
use of org.apache.felix.dm.ConfigurationDependency in project felix by apache.
the class DiagnosticsTest method testConfigurationDependencyMissing.
public void testConfigurationDependencyMissing() throws Exception {
DependencyManager dm = getDM();
ConfigurationDependency configurationDependency1 = dm.createConfigurationDependency().setPid("missing.configuration.pid");
Component component1 = dm.createComponent().setImplementation(Object.class).add(configurationDependency1);
m_dm.add(component1);
DependencyGraph graph = DependencyGraph.getGraph(ComponentState.UNREGISTERED, DependencyState.REQUIRED_UNAVAILABLE);
assertEquals(1, graph.getAllComponents().size());
assertEquals(1, graph.getAllDependencies().size());
List<MissingDependency> missingServiceDependencies = graph.getMissingDependencies("service");
assertTrue(missingServiceDependencies.isEmpty());
List<MissingDependency> missingConfigDependencies = graph.getMissingDependencies("configuration");
assertEquals(1, missingConfigDependencies.size());
MissingDependency missingConfigDependency = missingConfigDependencies.get(0);
assertEquals("missing.configuration.pid", missingConfigDependency.getName());
}
use of org.apache.felix.dm.ConfigurationDependency in project felix by apache.
the class ServiceRaceTest method doTest.
void doTest(int loop) throws Throwable {
debug("loop#%d -------------------------", loop);
final Ensure step = new Ensure(false);
// Create one client component, which depends on many service dependencies
final Component client = m_dm.createComponent();
final Client clientImpl = new Client(step);
client.setImplementation(clientImpl);
// Create client service dependencies
final ServiceDependency[] dependencies = new ServiceDependency[DEPENDENCIES];
for (int i = 0; i < DEPENDENCIES; i++) {
final String filter = "(id=loop" + loop + "." + i + ")";
dependencies[i] = m_dm.createServiceDependency().setService(Dep.class, filter).setRequired(true).setCallbacks("add", "remove");
client.add(dependencies[i]);
}
String pid = "pid." + loop;
final ConfigurationDependency confDependency = m_dm.createConfigurationDependency().setPid(pid);
client.add(confDependency);
// Create Configuration (concurrently).
final Configuration conf = m_cm.getConfiguration(pid, null);
final Hashtable props = new Hashtable();
props.put("foo", "bar");
schedule(new Runnable() {
public void run() {
try {
conf.update(props);
} catch (IOException e) {
error("update failed", e);
}
}
});
// Activate the client service dependencies concurrently.
List<Component> deps = new ArrayList();
for (int i = 0; i < DEPENDENCIES; i++) {
Hashtable h = new Hashtable();
h.put("id", "loop" + loop + "." + i);
final Component s = m_dm.createComponent().setInterface(Dep.class.getName(), h).setImplementation(new DepImpl());
deps.add(s);
schedule(new Runnable() {
public void run() {
m_dm.add(s);
}
});
}
// Start the client (concurrently)
schedule(new Runnable() {
public void run() {
m_dm.add(client);
}
});
// Ensure that client has been started.
int expectedStep = 1 + /* conf */
DEPENDENCIES + 1;
step.waitForStep(expectedStep, STEP_WAIT);
Assert.assertEquals(DEPENDENCIES, clientImpl.getDependencies());
Assert.assertNotNull(clientImpl.getConfiguration());
// Stop all dependencies concurrently.
for (Component dep : deps) {
final Component dependency = dep;
schedule(new Runnable() {
public void run() {
m_dm.remove(dependency);
}
});
}
// Stop client concurrently.
schedule(new Runnable() {
public void run() {
m_dm.remove(client);
}
});
// Remove configuration (asynchronously)
final Ensure stepConfDeleted = new Ensure(false);
schedule(new Runnable() {
public void run() {
try {
conf.delete();
stepConfDeleted.step(1);
} catch (IOException e) {
warn("error while unconfiguring", e);
}
}
});
// Ensure that client has been stopped, then destroyed, then unbound from all dependencies
// stop/destroy
expectedStep += 2;
// removed all dependencies
expectedStep += DEPENDENCIES;
step.waitForStep(expectedStep, STEP_WAIT);
// Make sure configuration is removed
stepConfDeleted.waitForStep(1, STEP_WAIT);
step.ensure();
Assert.assertEquals(0, clientImpl.getDependencies());
m_threadPool.awaitQuiescence(5000, TimeUnit.MILLISECONDS);
if (super.errorsLogged()) {
throw new IllegalStateException("Race test interrupted (some error occured, see previous logs)");
}
debug("finished one test loop");
if ((loop + 1) % 100 == 0) {
long duration = System.currentTimeMillis() - m_timeStamp;
warn("Performed 100 tests (total=%d) in %d ms.", (loop + 1), duration);
m_timeStamp = System.currentTimeMillis();
}
}
use of org.apache.felix.dm.ConfigurationDependency in project felix by apache.
the class ConfigurationDependencyBuilderImpl method build.
@Override
public ConfigurationDependency build() {
String pid = m_pid == null ? (m_configType != null ? m_configType.getName() : null) : m_pid;
if (pid == null) {
throw new IllegalStateException("Pid not specified");
}
ConfigurationDependency dep = m_component.getDependencyManager().createConfigurationDependency();
Objects.nonNull(m_pid);
dep.setPid(pid);
dep.setPropagate(m_propagate);
dep.setRequired(m_required);
if (m_updateMethodName != null) {
dep.setCallback(m_updateCallbackInstance, m_updateMethodName, m_configType);
} else if (m_refs.size() > 0) {
// setup an internal callback object. When config is updated, we have to call each registered
// method references.
// Notice that we need the component to be instantiated in case there is a mref on one of the component instances (unbound method ref), or is used
// called "needsInstance(true)".
dep.setCallback(new Object() {
@SuppressWarnings("unused")
void updated(Component comp, Dictionary<String, Object> props) {
m_refs.forEach(mref -> mref.accept(null, comp, props));
}
}, "updated", m_hasComponentCallbackRefs);
}
return dep;
}
use of org.apache.felix.dm.ConfigurationDependency in project felix by apache.
the class DependencyBuilder method build.
public Dependency build(Bundle b, DependencyManager dm) throws Exception {
Dependency dp = null;
DependencyType type;
try {
type = DependencyType.valueOf(m_metaData.getString(Params.type));
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("no \"type\" parameter found from metaData: " + m_metaData);
}
switch(type) {
case ServiceDependency:
dp = createServiceDependency(b, dm);
break;
case ConfigurationDependency:
dp = createConfigurationDependency(b, dm);
break;
case BundleDependency:
dp = createBundleDependency(dm);
break;
case ResourceDependency:
dp = createResourceDependency(dm);
break;
default:
throw new IllegalArgumentException("Can't build service dependency: " + type);
}
return dp;
}
Aggregations