use of org.qi4j.api.activation.ActivationException in project qi4j-sdk by Qi4j.
the class ActivationDelegate method activate.
@SuppressWarnings("unchecked")
public void activate(ActivatorsInstance targetActivators, Iterable<? extends Activation> children, Runnable callback) throws ActivationException {
if (this.targetActivators != null) {
throw new IllegalStateException("Activation.activate() called multiple times " + "or without calling passivate() first!");
}
try {
// Before Activation Events
if (fireEvents) {
fireEvent(new ActivationEvent(target, ACTIVATING));
}
// Before Activation for Activators
targetActivators.beforeActivation(target instanceof ServiceReference ? new PassiveServiceReference((ServiceReference) target) : target);
// Activation
for (Activation child : children) {
if (!activeChildren.contains(child)) {
child.activate();
}
activeChildren.addFirst(child);
}
// Internal Activation Callback
if (callback != null) {
callback.run();
}
// After Activation
targetActivators.afterActivation(target);
// After Activation Events
if (fireEvents) {
fireEvent(new ActivationEvent(target, ACTIVATED));
}
// Activated
this.targetActivators = targetActivators;
} catch (Exception e) {
// Passivate actives
try {
passivate();
} catch (PassivationException e1) {
ActivationException activationEx = new ActivationException("Unable to Activate application.", e);
activationEx.addSuppressed(e1);
throw activationEx;
}
if (e instanceof ActivationException) {
throw ((ActivationException) e);
}
throw new ActivationException("Unable to Activate application.", e);
}
}
Aggregations