aboutsummaryrefslogtreecommitdiffstats
path: root/policy-management/src/main/java/org/onap/policy/drools/controller/IndexedDroolsControllerFactory.java
diff options
context:
space:
mode:
Diffstat (limited to 'policy-management/src/main/java/org/onap/policy/drools/controller/IndexedDroolsControllerFactory.java')
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/controller/IndexedDroolsControllerFactory.java47
1 files changed, 27 insertions, 20 deletions
diff --git a/policy-management/src/main/java/org/onap/policy/drools/controller/IndexedDroolsControllerFactory.java b/policy-management/src/main/java/org/onap/policy/drools/controller/IndexedDroolsControllerFactory.java
index e8234a46..d2196680 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/controller/IndexedDroolsControllerFactory.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/controller/IndexedDroolsControllerFactory.java
@@ -31,6 +31,7 @@ import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
import org.onap.policy.common.endpoints.event.comm.TopicSink;
import org.onap.policy.common.endpoints.event.comm.TopicSource;
import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
+import org.onap.policy.common.utils.services.FeatureApiUtils;
import org.onap.policy.drools.controller.internal.MavenDroolsController;
import org.onap.policy.drools.controller.internal.NullDroolsController;
import org.onap.policy.drools.features.DroolsControllerFeatureApi;
@@ -152,24 +153,8 @@ class IndexedDroolsControllerFactory implements DroolsControllerFactory {
/* new drools controller */
- DroolsController controller = null;
- for (DroolsControllerFeatureApi feature: getProviders()) {
- try {
- controller = feature.beforeInstance(properties,
- newGroupId, newArtifactId, newVersion,
+ DroolsController controller = applyBeforeInstance(properties, newGroupId, newArtifactId, newVersion,
decoderConfigurations, encoderConfigurations);
- if (controller != null) {
- logger.info("feature {} ({}) beforeInstance() has intercepted drools controller {}:{}:{}",
- feature.getName(), feature.getSequenceNumber(),
- newGroupId, newArtifactId, newVersion);
- break;
- }
- } catch (RuntimeException r) {
- logger.error("feature {} ({}) beforeInstance() of drools controller {}:{}:{} failed",
- feature.getName(), feature.getSequenceNumber(),
- newGroupId, newArtifactId, newVersion, r);
- }
- }
if (controller == null) {
controller = new MavenDroolsController(newGroupId, newArtifactId, newVersion, decoderConfigurations,
@@ -180,16 +165,38 @@ class IndexedDroolsControllerFactory implements DroolsControllerFactory {
droolsControllers.put(controllerId, controller);
}
+ final DroolsController controllerFinal = controller;
+
+ FeatureApiUtils.apply(getProviders(),
+ feature -> feature.afterInstance(controllerFinal, properties),
+ (feature, ex) -> logger.error("feature {} ({}) afterInstance() of drools controller {}:{}:{} failed",
+ feature.getName(), feature.getSequenceNumber(),
+ newGroupId, newArtifactId, newVersion, ex));
+
+ return controller;
+ }
+
+ private DroolsController applyBeforeInstance(Properties properties, String newGroupId, String newArtifactId,
+ String newVersion, List<TopicCoderFilterConfiguration> decoderConfigurations,
+ List<TopicCoderFilterConfiguration> encoderConfigurations) {
+ DroolsController controller = null;
for (DroolsControllerFeatureApi feature: getProviders()) {
try {
- feature.afterInstance(controller, properties);
+ controller = feature.beforeInstance(properties,
+ newGroupId, newArtifactId, newVersion,
+ decoderConfigurations, encoderConfigurations);
+ if (controller != null) {
+ logger.info("feature {} ({}) beforeInstance() has intercepted drools controller {}:{}:{}",
+ feature.getName(), feature.getSequenceNumber(),
+ newGroupId, newArtifactId, newVersion);
+ break;
+ }
} catch (RuntimeException r) {
- logger.error("feature {} ({}) afterInstance() of drools controller {}:{}:{} failed",
+ logger.error("feature {} ({}) beforeInstance() of drools controller {}:{}:{} failed",
feature.getName(), feature.getSequenceNumber(),
newGroupId, newArtifactId, newVersion, r);
}
}
-
return controller;
}