aboutsummaryrefslogtreecommitdiffstats
path: root/feature-pooling-dmaap/src/main/java/org/onap
diff options
context:
space:
mode:
Diffstat (limited to 'feature-pooling-dmaap/src/main/java/org/onap')
-rw-r--r--feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/DmaapManager.java59
-rw-r--r--feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/PoolingFeature.java130
-rw-r--r--feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/PoolingManagerImpl.java131
3 files changed, 132 insertions, 188 deletions
diff --git a/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/DmaapManager.java b/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/DmaapManager.java
index 27b81504..eb258b8c 100644
--- a/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/DmaapManager.java
+++ b/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/DmaapManager.java
@@ -39,11 +39,6 @@ public class DmaapManager {
private static final Logger logger = LoggerFactory.getLogger(DmaapManager.class);
/**
- * Factory used to construct objects.
- */
- private static Factory factory = new Factory();
-
- /**
* Name of the DMaaP topic.
*/
private final String topic;
@@ -93,19 +88,6 @@ public class DmaapManager {
}
}
- protected static Factory getFactory() {
- return factory;
- }
-
- /**
- * Used by junit tests to set the factory used to create various objects used by this class.
- *
- * @param factory the new factory
- */
- protected static void setFactory(Factory factory) {
- DmaapManager.factory = factory;
- }
-
public String getTopic() {
return topic;
}
@@ -117,7 +99,7 @@ public class DmaapManager {
* @throws PoolingFeatureException if the source doesn't exist or is not filterable
*/
private FilterableTopicSource findTopicSource() throws PoolingFeatureException {
- for (TopicSource src : factory.getTopicSources()) {
+ for (TopicSource src : getTopicSources()) {
if (topic.equals(src.getTopic())) {
if (src instanceof FilterableTopicSource) {
return (FilterableTopicSource) src;
@@ -138,7 +120,7 @@ public class DmaapManager {
* @throws PoolingFeatureException if the sink doesn't exist
*/
private TopicSink findTopicSink() throws PoolingFeatureException {
- for (TopicSink sink : factory.getTopicSinks()) {
+ for (TopicSink sink : getTopicSinks()) {
if (topic.equals(sink.getTopic())) {
return sink;
}
@@ -252,29 +234,26 @@ public class DmaapManager {
throw new PoolingFeatureException("cannot send to topic sink " + topic, e);
}
}
+
+ /*
+ * The remaining methods may be overridden by junit tests.
+ */
/**
- * Factory used to construct objects.
+ * Get topic source.
+ *
+ * @return the topic sources
*/
- public static class Factory {
-
- /**
- * Get topic source.
- *
- * @return the topic sources
- */
- public List<TopicSource> getTopicSources() {
- return TopicEndpoint.manager.getTopicSources();
- }
-
- /**
- * Get topic sinks.
- *
- * @return the topic sinks
- */
- public List<TopicSink> getTopicSinks() {
- return TopicEndpoint.manager.getTopicSinks();
- }
+ protected List<TopicSource> getTopicSources() {
+ return TopicEndpoint.manager.getTopicSources();
+ }
+ /**
+ * Get topic sinks.
+ *
+ * @return the topic sinks
+ */
+ protected List<TopicSink> getTopicSinks() {
+ return TopicEndpoint.manager.getTopicSinks();
}
}
diff --git a/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/PoolingFeature.java b/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/PoolingFeature.java
index d45bded7..60a6f293 100644
--- a/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/PoolingFeature.java
+++ b/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/PoolingFeature.java
@@ -57,11 +57,6 @@ public class PoolingFeature implements PolicyEngineFeatureAPI, PolicyControllerF
private static final Logger logger = LoggerFactory.getLogger(PoolingFeature.class);
/**
- * Factory used to create objects.
- */
- private static Factory factory = new Factory();
-
- /**
* ID of this host.
*/
private final String host;
@@ -97,19 +92,6 @@ public class PoolingFeature implements PolicyEngineFeatureAPI, PolicyControllerF
this.host = UUID.randomUUID().toString();
}
- protected static Factory getFactory() {
- return factory;
- }
-
- /**
- * Sets the factory to be used to create objects. Used by junit tests.
- *
- * @param factory the new factory to be used to create objects
- */
- protected static void setFactory(Factory factory) {
- PoolingFeature.factory = factory;
- }
-
public String getHost() {
return host;
}
@@ -131,13 +113,13 @@ public class PoolingFeature implements PolicyEngineFeatureAPI, PolicyControllerF
@Override
public boolean beforeStart(PolicyEngine engine) {
logger.info("initializing {}", PoolingProperties.FEATURE_NAME);
- featProps = factory.getProperties(PoolingProperties.FEATURE_NAME);
+ featProps = getProperties(PoolingProperties.FEATURE_NAME);
// remove any generic pooling topic - always use controller-specific property
featProps.remove(PoolingProperties.POOLING_TOPIC);
- factory.initTopicSources(featProps);
- factory.initTopicSinks(featProps);
+ initTopicSources(featProps);
+ initTopicSinks(featProps);
return false;
}
@@ -173,7 +155,7 @@ public class PoolingFeature implements PolicyEngineFeatureAPI, PolicyControllerF
PoolingProperties props = new PoolingProperties(name, featProps);
logger.info("pooling enabled for {}", name);
- ctlr2pool.computeIfAbsent(name, xxx -> factory.makeManager(host, controller, props, activeLatch));
+ ctlr2pool.computeIfAbsent(name, xxx -> makeManager(host, controller, props, activeLatch));
} catch (PropertyException e) {
logger.error("pooling disabled due to exception for {}", name, e);
@@ -270,7 +252,7 @@ public class PoolingFeature implements PolicyEngineFeatureAPI, PolicyControllerF
PolicyController controller;
try {
- controller = factory.getController(droolsController);
+ controller = getController(droolsController);
} catch (IllegalArgumentException | IllegalStateException e) {
logger.warn("cannot get controller for {} {}", droolsController.getGroupId(),
@@ -393,64 +375,62 @@ public class PoolingFeature implements PolicyEngineFeatureAPI, PolicyControllerF
this.event = event;
}
}
+
+ /*
+ * The remaining methods may be overridden by junit tests.
+ */
/**
- * Used to create objects.
+ * Get properties.
+ *
+ * @param featName feature name
+ * @return the properties for the specified feature
*/
- public static class Factory {
-
- /**
- * Get properties.
- *
- * @param featName feature name
- * @return the properties for the specified feature
- */
- public Properties getProperties(String featName) {
- return SystemPersistence.manager.getProperties(featName);
- }
+ protected Properties getProperties(String featName) {
+ return SystemPersistence.manager.getProperties(featName);
+ }
- /**
- * Makes a pooling manager for a controller.
- *
- * @param host name/uuid of this host
- * @param controller controller
- * @param props properties to use to configure the manager
- * @param activeLatch decremented when the manager goes Active
- * @return a new pooling manager
- */
- public PoolingManagerImpl makeManager(String host, PolicyController controller, PoolingProperties props,
- CountDownLatch activeLatch) {
- return new PoolingManagerImpl(host, controller, props, activeLatch);
- }
+ /**
+ * Makes a pooling manager for a controller.
+ *
+ * @param host name/uuid of this host
+ * @param controller controller
+ * @param props properties to use to configure the manager
+ * @param activeLatch decremented when the manager goes Active
+ * @return a new pooling manager
+ */
+ protected PoolingManagerImpl makeManager(String host, PolicyController controller, PoolingProperties props,
+ CountDownLatch activeLatch) {
+ return new PoolingManagerImpl(host, controller, props, activeLatch);
+ }
- /**
- * Gets the policy controller associated with a drools controller.
- *
- * @param droolsController drools controller
- * @return the policy controller associated with a drools controller
- */
- public PolicyController getController(DroolsController droolsController) {
- return PolicyController.factory.get(droolsController);
- }
+ /**
+ * Gets the policy controller associated with a drools controller.
+ *
+ * @param droolsController drools controller
+ * @return the policy controller associated with a drools controller
+ */
+ protected PolicyController getController(DroolsController droolsController) {
+ return PolicyController.factory.get(droolsController);
+ }
- /**
- * Initializes the topic sources.
- *
- * @param props properties used to configure the topics
- * @return the topic sources
- */
- public List<TopicSource> initTopicSources(Properties props) {
- return TopicEndpoint.manager.addTopicSources(props);
- }
+ /**
+ * Initializes the topic sources.
+ *
+ * @param props properties used to configure the topics
+ * @return the topic sources
+ */
+ protected List<TopicSource> initTopicSources(Properties props) {
+ return TopicEndpoint.manager.addTopicSources(props);
+ }
- /**
- * Initializes the topic sinks.
- *
- * @param props properties used to configure the topics
- * @return the topic sinks
- */
- public List<TopicSink> initTopicSinks(Properties props) {
- return TopicEndpoint.manager.addTopicSinks(props);
- }
+ /**
+ * Initializes the topic sinks.
+ *
+ * @param props properties used to configure the topics
+ * @return the topic sinks
+ */
+ protected List<TopicSink> initTopicSinks(Properties props) {
+ return TopicEndpoint.manager.addTopicSinks(props);
}
}
diff --git a/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/PoolingManagerImpl.java b/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/PoolingManagerImpl.java
index 6b5828c7..4db8fe38 100644
--- a/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/PoolingManagerImpl.java
+++ b/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/PoolingManagerImpl.java
@@ -69,11 +69,6 @@ public class PoolingManagerImpl implements PoolingManager, TopicListener {
public static final int MAX_HOPS = 5;
/**
- * Factory used to create various objects. Can be overridden during junit testing.
- */
- private static Factory factory = new Factory();
-
- /**
* ID of this host.
*/
private final String host;
@@ -170,8 +165,8 @@ public class PoolingManagerImpl implements PoolingManager, TopicListener {
this.listener = (TopicListener) controller;
this.serializer = new Serializer();
this.topic = props.getPoolingTopic();
- this.extractors = factory.makeClassExtractors(makeExtractorProps(controller, props.getSource()));
- this.dmaapMgr = factory.makeDmaapManager(props.getPoolingTopic());
+ this.extractors = makeClassExtractors(makeExtractorProps(controller, props.getSource()));
+ this.dmaapMgr = makeDmaapManager(props.getPoolingTopic());
this.current = new IdleState(this);
logger.info("allocating host {} to controller {} for topic {}", host, controller.getName(), topic);
@@ -186,14 +181,6 @@ public class PoolingManagerImpl implements PoolingManager, TopicListener {
}
}
- protected static Factory getFactory() {
- return factory;
- }
-
- protected static void setFactory(Factory factory) {
- PoolingManagerImpl.factory = factory;
- }
-
/**
* Should only be used by junit tests.
*
@@ -241,7 +228,7 @@ public class PoolingManagerImpl implements PoolingManager, TopicListener {
dmaapMgr.startPublisher();
logger.debug("make scheduler thread for topic {}", getTopic());
- scheduler = factory.makeScheduler();
+ scheduler = makeScheduler();
/*
* Only a handful of timers at any moment, thus we can afford to take the
@@ -603,7 +590,7 @@ public class PoolingManagerImpl implements PoolingManager, TopicListener {
// check if this topic has a decoder
- if (!factory.canDecodeEvent(drools, topic2)) {
+ if (!canDecodeEvent(drools, topic2)) {
logger.warn("{}: DECODING-UNSUPPORTED {}:{}:{}", drools, topic2, drools.getGroupId(),
drools.getArtifactId());
@@ -613,7 +600,7 @@ public class PoolingManagerImpl implements PoolingManager, TopicListener {
// decode
try {
- return factory.decodeEvent(drools, topic2, event);
+ return decodeEventWrapper(drools, topic2, event);
} catch (UnsupportedOperationException | IllegalStateException | IllegalArgumentException e) {
logger.debug("{}: DECODE FAILED: {} <- {} because of {}", drools, topic2, event, e.getMessage(), e);
@@ -777,67 +764,65 @@ public class PoolingManagerImpl implements PoolingManager, TopicListener {
}
}
}
+
+ /*
+ * The remaining methods may be overridden by junit tests.
+ */
/**
- * Factory used to create objects.
+ * Creates object extractors.
+ *
+ * @param props properties used to configure the extractors
+ * @return a new set of extractors
*/
- public static class Factory {
-
- /**
- * Creates object extractors.
- *
- * @param props properties used to configure the extractors
- * @return a new set of extractors
- */
- public ClassExtractors makeClassExtractors(Properties props) {
- return new ClassExtractors(props, PoolingProperties.PROP_EXTRACTOR_PREFIX,
- PoolingProperties.EXTRACTOR_TYPE);
- }
+ protected ClassExtractors makeClassExtractors(Properties props) {
+ return new ClassExtractors(props, PoolingProperties.PROP_EXTRACTOR_PREFIX,
+ PoolingProperties.EXTRACTOR_TYPE);
+ }
- /**
- * Creates a DMaaP manager.
- *
- * @param topic name of the internal DMaaP topic
- * @return a new DMaaP manager
- * @throws PoolingFeatureException if an error occurs
- */
- public DmaapManager makeDmaapManager(String topic) throws PoolingFeatureException {
- return new DmaapManager(topic);
- }
+ /**
+ * Creates a DMaaP manager.
+ *
+ * @param topic name of the internal DMaaP topic
+ * @return a new DMaaP manager
+ * @throws PoolingFeatureException if an error occurs
+ */
+ protected DmaapManager makeDmaapManager(String topic) throws PoolingFeatureException {
+ return new DmaapManager(topic);
+ }
- /**
- * Creates a scheduled thread pool.
- *
- * @return a new scheduled thread pool
- */
- public ScheduledThreadPoolExecutor makeScheduler() {
- return new ScheduledThreadPoolExecutor(1);
- }
+ /**
+ * Creates a scheduled thread pool.
+ *
+ * @return a new scheduled thread pool
+ */
+ protected ScheduledThreadPoolExecutor makeScheduler() {
+ return new ScheduledThreadPoolExecutor(1);
+ }
- /**
- * Determines if the event can be decoded.
- *
- * @param drools drools controller
- * @param topic topic on which the event was received
- * @return {@code true} if the event can be decoded, {@code false} otherwise
- */
- public boolean canDecodeEvent(DroolsController drools, String topic) {
- return EventProtocolCoder.manager.isDecodingSupported(drools.getGroupId(), drools.getArtifactId(), topic);
- }
+ /**
+ * Determines if the event can be decoded.
+ *
+ * @param drools drools controller
+ * @param topic topic on which the event was received
+ * @return {@code true} if the event can be decoded, {@code false} otherwise
+ */
+ protected boolean canDecodeEvent(DroolsController drools, String topic) {
+ return EventProtocolCoder.manager.isDecodingSupported(drools.getGroupId(), drools.getArtifactId(), topic);
+ }
- /**
- * Decodes the event.
- *
- * @param drools drools controller
- * @param topic topic on which the event was received
- * @param event event text to be decoded
- * @return the decoded event
- * @throws IllegalArgumentException illegal argument
- * @throw UnsupportedOperationException unsupported operation
- * @throws IllegalStateException illegal state
- */
- public Object decodeEvent(DroolsController drools, String topic, String event) {
- return EventProtocolCoder.manager.decode(drools.getGroupId(), drools.getArtifactId(), topic, event);
- }
+ /**
+ * Decodes the event.
+ *
+ * @param drools drools controller
+ * @param topic topic on which the event was received
+ * @param event event text to be decoded
+ * @return the decoded event
+ * @throws IllegalArgumentException illegal argument
+ * @throw UnsupportedOperationException unsupported operation
+ * @throws IllegalStateException illegal state
+ */
+ protected Object decodeEventWrapper(DroolsController drools, String topic, String event) {
+ return EventProtocolCoder.manager.decode(drools.getGroupId(), drools.getArtifactId(), topic, event);
}
}