warn(bundle, "Error while creating extension", t);
}
}
private void destroyExtension(final Bundle bundle) {
FutureTask future;
synchronized (extensions) {
debug(bundle, "Starting destruction process");
future = destroying.get(bundle);
if (future == null) {
final Extension extension = extensions.remove(bundle);
if (extension != null) {
debug(bundle, "Scheduling extension destruction");
future = new FutureTask<Void>(new Runnable() {
public void run() {
debug(bundle, "Destroying extension");
try {
extension.destroy();
} catch (Exception e) {
warn(bundle, "Error while destroying extension", e);
} finally {
debug(bundle, "Finished destroying extension");
synchronized (extensions) {
destroying.remove(bundle);
}
}
}
}, null);
destroying.put(bundle, future);
} else {
debug(bundle, "Not an extended bundle or destruction of extension already finished");
}
} else {
debug(bundle, "Destruction already scheduled");
}
}
if (future != null) {
try {
debug(bundle, "Waiting for extension destruction");
future.run();
future.get();
} catch (Throwable t) {
warn(bundle, "Error while destroying extension", t);
}
}
}