Search in sources :

Example 1 with AnnotationMetaData

use of org.mule.runtime.core.privileged.util.annotation.AnnotationMetaData in project mule by mulesoft.

the class MuleContextDisposePhase method applyLifecycle.

@Override
public void applyLifecycle(Object o) throws LifecycleException {
    if (o == null) {
        return;
    }
    if (ignoreType(o.getClass())) {
        return;
    }
    // retain default Lifecycle behaviour
    try {
        super.applyLifecycle(o);
    } catch (Exception e) {
        if (logger.isWarnEnabled()) {
            logger.warn("Failed to dispose object " + o, e);
        }
    }
    List<AnnotationMetaData> annos = AnnotationUtils.getMethodAnnotations(o.getClass(), PreDestroy.class);
    if (annos.size() == 0) {
        return;
    }
    // Note that the registry has a processor that validates that there is at most one {@link PostConstruct} annotation
    // per object and that the method conforms to a lifecycle method
    AnnotationMetaData anno = annos.get(0);
    try {
        ((Method) anno.getMember()).invoke(o);
    } catch (Exception e) {
        throw new LifecycleException(CoreMessages.failedToInvokeLifecycle((anno == null ? "null" : anno.getMember().getName()), o), e, this);
    }
}
Also used : LifecycleException(org.mule.runtime.api.lifecycle.LifecycleException) Method(java.lang.reflect.Method) AnnotationMetaData(org.mule.runtime.core.privileged.util.annotation.AnnotationMetaData) LifecycleException(org.mule.runtime.api.lifecycle.LifecycleException)

Example 2 with AnnotationMetaData

use of org.mule.runtime.core.privileged.util.annotation.AnnotationMetaData in project mule by mulesoft.

the class MuleContextInitialisePhase method applyLifecycle.

@Override
public void applyLifecycle(Object o) throws LifecycleException {
    // retain default Lifecycle behaviour
    super.applyLifecycle(o);
    if (o == null) {
        return;
    }
    if (ignoreType(o.getClass())) {
        return;
    }
    // Lets check for {@link PostConstruct} annotations on methods of this object and invoke
    List<AnnotationMetaData> annos = AnnotationUtils.getMethodAnnotations(o.getClass(), PostConstruct.class);
    // per object and that the method conforms to a lifecycle method
    if (annos.size() == 1) {
        AnnotationMetaData anno = annos.get(0);
        try {
            ((Method) anno.getMember()).invoke(o);
        } catch (Exception e) {
            throw new LifecycleException(CoreMessages.failedToInvokeLifecycle(anno.getMember().getName(), o), e, this);
        }
    }
}
Also used : LifecycleException(org.mule.runtime.api.lifecycle.LifecycleException) Method(java.lang.reflect.Method) AnnotationMetaData(org.mule.runtime.core.privileged.util.annotation.AnnotationMetaData) LifecycleException(org.mule.runtime.api.lifecycle.LifecycleException)

Aggregations

Method (java.lang.reflect.Method)2 LifecycleException (org.mule.runtime.api.lifecycle.LifecycleException)2 AnnotationMetaData (org.mule.runtime.core.privileged.util.annotation.AnnotationMetaData)2