Search in sources :

Example 1 with Closeable

use of org.kie.internal.runtime.Closeable in project jbpm by kiegroup.

the class CaseConfigurationDeploymentListener method getEventListenerFromDescriptor.

protected List<CaseEventListener> getEventListenerFromDescriptor(InternalRuntimeManager runtimeManager) {
    List<CaseEventListener> listeners = new ArrayList<CaseEventListener>();
    DeploymentDescriptor descriptor = runtimeManager.getDeploymentDescriptor();
    if (descriptor != null) {
        Map<String, Object> params = getParametersMap(runtimeManager);
        for (ObjectModel model : descriptor.getEventListeners()) {
            ObjectModelResolver resolver = ObjectModelResolverProvider.get(model.getResolver());
            if (resolver == null) {
                logger.warn("Unable to find ObjectModelResolver for {}", model.getResolver());
                continue;
            }
            try {
                Object listenerInstance = resolver.getInstance(model, runtimeManager.getEnvironment().getClassLoader(), params);
                if (listenerInstance != null && CaseEventListener.class.isAssignableFrom(listenerInstance.getClass())) {
                    listeners.add((CaseEventListener) listenerInstance);
                } else {
                    // close/cleanup instance as it is not going to be used at the moment, except these that are cacheable
                    if (listenerInstance instanceof Closeable && !(listenerInstance instanceof Cacheable)) {
                        ((Closeable) listenerInstance).close();
                    }
                }
            } catch (Exception e) {
                logger.debug("Unable to build listener {}", model);
            }
        }
    }
    return listeners;
}
Also used : ObjectModel(org.kie.internal.runtime.conf.ObjectModel) Cacheable(org.kie.internal.runtime.Cacheable) DeploymentDescriptor(org.kie.internal.runtime.conf.DeploymentDescriptor) Closeable(org.kie.internal.runtime.Closeable) ArrayList(java.util.ArrayList) ObjectModelResolver(org.kie.internal.runtime.conf.ObjectModelResolver) CaseEventListener(org.jbpm.casemgmt.api.event.CaseEventListener) NotifyParentCaseEventListener(org.jbpm.casemgmt.impl.wih.NotifyParentCaseEventListener)

Example 2 with Closeable

use of org.kie.internal.runtime.Closeable in project jbpm by kiegroup.

the class DefaultRegisterableItemsFactory method getEventListenerFromDescriptor.

@SuppressWarnings("unchecked")
protected <T> List<T> getEventListenerFromDescriptor(RuntimeEngine runtime, Class<T> type) {
    List<T> listeners = new ArrayList<T>();
    DeploymentDescriptor descriptor = getRuntimeManager().getDeploymentDescriptor();
    if (descriptor != null) {
        Map<String, Object> params = getParametersMap(runtime);
        for (ObjectModel model : descriptor.getEventListeners()) {
            Object listenerInstance = getInstanceFromModel(model, getRuntimeManager().getEnvironment().getClassLoader(), params);
            if (listenerInstance != null && type.isAssignableFrom(listenerInstance.getClass())) {
                listeners.add((T) listenerInstance);
            } else {
                // close/cleanup instance as it is not going to be used at the moment, except these that are cacheable
                if (listenerInstance instanceof Closeable && !(listenerInstance instanceof Cacheable)) {
                    ((Closeable) listenerInstance).close();
                }
            }
        }
    }
    return listeners;
}
Also used : ObjectModel(org.kie.internal.runtime.conf.ObjectModel) NamedObjectModel(org.kie.internal.runtime.conf.NamedObjectModel) Cacheable(org.kie.internal.runtime.Cacheable) DeploymentDescriptor(org.kie.internal.runtime.conf.DeploymentDescriptor) Closeable(org.kie.internal.runtime.Closeable) ArrayList(java.util.ArrayList)

Aggregations

ArrayList (java.util.ArrayList)2 Cacheable (org.kie.internal.runtime.Cacheable)2 Closeable (org.kie.internal.runtime.Closeable)2 DeploymentDescriptor (org.kie.internal.runtime.conf.DeploymentDescriptor)2 ObjectModel (org.kie.internal.runtime.conf.ObjectModel)2 CaseEventListener (org.jbpm.casemgmt.api.event.CaseEventListener)1 NotifyParentCaseEventListener (org.jbpm.casemgmt.impl.wih.NotifyParentCaseEventListener)1 NamedObjectModel (org.kie.internal.runtime.conf.NamedObjectModel)1 ObjectModelResolver (org.kie.internal.runtime.conf.ObjectModelResolver)1