diff options
Diffstat (limited to 'policy-management/src/main/java/org/onap/policy/drools/system/IndexedPolicyControllerFactory.java')
-rw-r--r-- | policy-management/src/main/java/org/onap/policy/drools/system/IndexedPolicyControllerFactory.java | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/policy-management/src/main/java/org/onap/policy/drools/system/IndexedPolicyControllerFactory.java b/policy-management/src/main/java/org/onap/policy/drools/system/IndexedPolicyControllerFactory.java index 6956a45e..c03535b1 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/system/IndexedPolicyControllerFactory.java +++ b/policy-management/src/main/java/org/onap/policy/drools/system/IndexedPolicyControllerFactory.java @@ -24,6 +24,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Properties; import org.onap.policy.common.gson.annotation.GsonJsonIgnore; import org.onap.policy.drools.controller.DroolsController; @@ -44,13 +45,13 @@ class IndexedPolicyControllerFactory implements PolicyControllerFactory { /** * Policy Controller Name Index. */ - private final HashMap<String, PolicyController> policyControllers = + private final Map<String, PolicyController> policyControllers = new HashMap<>(); /** * Group/Artifact Ids Index. */ - private final HashMap<String, PolicyController> coordinates2Controller = + private final Map<String, PolicyController> coordinates2Controller = new HashMap<>(); /** @@ -380,7 +381,35 @@ class IndexedPolicyControllerFactory implements PolicyControllerFactory { // these methods can be overridden by junit tests protected PolicyController newPolicyController(String name, Properties properties) { - return new AggregatedPolicyController(name, properties); + PolicyController controller = null; + for (PolicyControllerFeatureApi feature: getProviders()) { + try { + controller = feature.beforeInstance(name, properties); + if (controller != null) { + logger.info("feature {} ({}) beforeInstance() has intercepted controller {}", + feature.getName(), feature.getSequenceNumber(), name); + break; + } + } catch (RuntimeException r) { + logger.error("feature {} ({}) beforeInstance() of controller {} failed", + feature.getName(), feature.getSequenceNumber(), name, r); + } + } + + if (controller == null) { + controller = new AggregatedPolicyController(name, properties); + } + + for (PolicyControllerFeatureApi feature: getProviders()) { + try { + feature.afterInstance(controller, properties); + } catch (RuntimeException r) { + logger.error("feature {} ({}) afterInstance() of controller {} failed ", + feature.getName(), feature.getSequenceNumber(), name, r); + } + } + + return controller; } protected List<PolicyControllerFeatureApi> getProviders() { |