Search in sources :

Example 1 with Activation

use of org.qi4j.api.activation.Activation 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);
    }
}
Also used : ActivationException(org.qi4j.api.activation.ActivationException) PassivationException(org.qi4j.api.activation.PassivationException) ActivationEvent(org.qi4j.api.activation.ActivationEvent) Activation(org.qi4j.api.activation.Activation) ActivationException(org.qi4j.api.activation.ActivationException) PassivationException(org.qi4j.api.activation.PassivationException) ServiceReference(org.qi4j.api.service.ServiceReference)

Aggregations

Activation (org.qi4j.api.activation.Activation)1 ActivationEvent (org.qi4j.api.activation.ActivationEvent)1 ActivationException (org.qi4j.api.activation.ActivationException)1 PassivationException (org.qi4j.api.activation.PassivationException)1 ServiceReference (org.qi4j.api.service.ServiceReference)1