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;
}
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;
}
Aggregations