throw new IOException("no matching factory found (" + parent + ")");
}
@Override
public void destroy(final URI id) throws Exception {
IsolationEnvironment env = getEnvironment(id);
final Semaphore s = new Semaphore(0);
ServiceListener l = new ServiceListener() {
@Override
public void serviceChanged(ServiceEvent event) {
if (event.getType() != ServiceEvent.UNREGISTERING) {
return;
}
ServiceReference ref = event.getServiceReference();
String[] objClasses = (String[]) ref.getProperty("objectClass");
boolean contains = Arrays.binarySearch(objClasses,
IsolationEnvironment.class.getName()) >= 0;
if (contains && ref.getProperty("environment.id").equals(id)) {
s.release();
}
}
};
context.addServiceListener(l);
try {
env.destroy();
s.acquire();
} finally {
context.removeServiceListener(l);
}
}