diff options
12 files changed, 106 insertions, 101 deletions
diff --git a/api-state-management/src/main/java/org/onap/policy/drools/statemanagement/StateManagementFeatureAPI.java b/api-state-management/src/main/java/org/onap/policy/drools/statemanagement/StateManagementFeatureAPI.java index a6d808ca..3ea54eba 100644 --- a/api-state-management/src/main/java/org/onap/policy/drools/statemanagement/StateManagementFeatureAPI.java +++ b/api-state-management/src/main/java/org/onap/policy/drools/statemanagement/StateManagementFeatureAPI.java @@ -69,8 +69,8 @@ public interface StateManagementFeatureAPI extends OrderedService, Lockable * 'FeatureAPI.impl.getList()' returns an ordered list of objects * implementing the 'FeatureAPI' interface. */ - static public OrderedServiceImpl<StateManagementFeatureAPI> impl = - new OrderedServiceImpl<StateManagementFeatureAPI>(StateManagementFeatureAPI.class); + public static OrderedServiceImpl<StateManagementFeatureAPI> impl = + new OrderedServiceImpl<>(StateManagementFeatureAPI.class); /** * This method is called to add an Observer to receive notifications of state changes diff --git a/feature-test-transaction/src/main/java/org/onap/policy/drools/testtransaction/TestTransaction.java b/feature-test-transaction/src/main/java/org/onap/policy/drools/testtransaction/TestTransaction.java index a23f2a46..5e209faa 100644 --- a/feature-test-transaction/src/main/java/org/onap/policy/drools/testtransaction/TestTransaction.java +++ b/feature-test-transaction/src/main/java/org/onap/policy/drools/testtransaction/TestTransaction.java @@ -64,7 +64,7 @@ public interface TestTransaction { */ class TTImpl implements TestTransaction { - final protected Map<String, TTControllerTask> controllers = new HashMap<>(); + protected final Map<String, TTControllerTask> controllers = new HashMap<>(); @Override public synchronized void register(PolicyController controller) { @@ -158,34 +158,7 @@ class TTControllerTask implements Runnable { while (this.controller.isAlive() && !this.controller.isLocked() && drools.isBrained() && this.alive) { - for (final String session : sessions) { - final List<Object> facts = this.controller.getDrools().factQuery(session, - TestTransaction.TT_FPC, TestTransaction.TT_COUNTER, false); - if (facts == null || facts.size() != 1) { - /* - * unexpected something wrong here, can't expect to recover note this exception is - * caught right below at the exit of run() - */ - logger.error( - "Controller: {}, with rules artifact: (group) {}, (artifact) {}, (version) {} - FPC query failed after EventObject insertion! ", - this.controller.getName(), this.controller.getDrools().getGroupId(), - this.controller.getDrools().getArtifactId(), - this.controller.getDrools().getVersion()); - break; - } - logger.debug("Facts: {}", facts); - - final long fpc = (Long) facts.get(0); - if (fpc != fpcs.get(session)) - logger.info("Controller: {} , session {} - Forward progress successful: {} -> {}", - this.controller.getName(), session, fpcs.get(session), fpc); - else - logger.error("Controller: {}, session {} - Forward progress failure: {}", - this.controller.getName(), session, fpc); - - fpcs.put(session, fpc); - drools.getContainer().insert(session, new EventObject(TestTransaction.TT_UUID)); - } + injectTxIntoSessions(sessions, fpcs, drools); if (!this.alive) return; @@ -208,7 +181,41 @@ class TTControllerTask implements Runnable { this.alive = false; } } + + private void injectTxIntoSessions(List<String> sessions, HashMap<String, Long> fpcs, DroolsController drools) { + for (final String session : sessions) { + final List<Object> facts = this.controller.getDrools().factQuery(session, + TestTransaction.TT_FPC, TestTransaction.TT_COUNTER, false); + if (facts == null || facts.size() != 1) { + /* + * unexpected something wrong here, can't expect to recover note this exception is + * caught right below at the exit of run() + */ + logger.error( + "Controller: {}, with rules artifact: (group) {}, (artifact) {}, (version) {} - FPC query failed after EventObject insertion! ", + this.controller.getName(), this.controller.getDrools().getGroupId(), + this.controller.getDrools().getArtifactId(), + this.controller.getDrools().getVersion()); + break; + } + logger.debug("Facts: {}", facts); + + final long fpc = (Long) facts.get(0); + if (fpc != fpcs.get(session)) + logger.info("Controller: {} , session {} - Forward progress successful: {} -> {}", + this.controller.getName(), session, fpcs.get(session), fpc); + else + logger.error("Controller: {}, session {} - Forward progress failure: {}", + this.controller.getName(), session, fpc); + + fpcs.put(session, fpc); + drools.getContainer().insert(session, new EventObject(TestTransaction.TT_UUID)); + } + + } + + @Override public String toString() { final StringBuilder builder = new StringBuilder(); diff --git a/feature-test-transaction/src/main/java/org/onap/policy/drools/testtransaction/TestTransactionFeature.java b/feature-test-transaction/src/main/java/org/onap/policy/drools/testtransaction/TestTransactionFeature.java index 72c54969..e78668ab 100644 --- a/feature-test-transaction/src/main/java/org/onap/policy/drools/testtransaction/TestTransactionFeature.java +++ b/feature-test-transaction/src/main/java/org/onap/policy/drools/testtransaction/TestTransactionFeature.java @@ -33,7 +33,7 @@ public class TestTransactionFeature implements PolicyControllerFeatureAPI { // get an instance of logger private static final Logger logger = LoggerFactory.getLogger(TestTransactionFeature.class); - + @Override public boolean afterStart(PolicyController controller){ @@ -49,7 +49,7 @@ public class TestTransactionFeature implements PolicyControllerFeatureAPI { @Override public boolean afterLock(PolicyController controller) { - logger.info("CONTROLLER " + controller.getName() + " LOCKED"); + logger.info("controller {} locked", controller.getName()); TestTransaction.manager.unregister(controller); return false; @@ -57,7 +57,7 @@ public class TestTransactionFeature implements PolicyControllerFeatureAPI { @Override public boolean afterUnlock(PolicyController controller) { - logger.info("CONTROLLER " + controller.getName() + " UNLOCKED"); + logger.info("controller {} unlocked", controller.getName()); if (controller.isAlive() && !controller.isLocked() && @@ -69,7 +69,7 @@ public class TestTransactionFeature implements PolicyControllerFeatureAPI { @Override public boolean beforeStop(PolicyController controller) { - logger.info("CONTROLLER " + controller.getName() + " ABOUT TO STOP"); + logger.info("controller {} stopping", controller.getName()); TestTransaction.manager.unregister(controller); diff --git a/policy-core/src/main/java/org/onap/policy/drools/core/PolicyContainer.java b/policy-core/src/main/java/org/onap/policy/drools/core/PolicyContainer.java index 2da53468..7dc53ce2 100644 --- a/policy-core/src/main/java/org/onap/policy/drools/core/PolicyContainer.java +++ b/policy-core/src/main/java/org/onap/policy/drools/core/PolicyContainer.java @@ -47,10 +47,10 @@ public class PolicyContainer implements Startable // get an instance of logger private static Logger logger = LoggerFactory.getLogger(PolicyContainer.class); // 'KieServices' singleton - static private KieServices kieServices = KieServices.Factory.get(); + private static KieServices kieServices = KieServices.Factory.get(); // set of all 'PolicyContainer' instances - static private HashSet<PolicyContainer> containers = + private static HashSet<PolicyContainer> containers = new HashSet<>(); // maps feature objects to per-PolicyContainer data @@ -74,6 +74,8 @@ public class PolicyContainer implements Startable // indicates whether the scanner has been started // (it can block for a long time) private boolean scannerStarted = false; + + private static final String ERROR_STRING = "ERROR: Feature API: "; /** * uses 'groupId', 'artifactId' and 'version', and fetches the associated @@ -288,7 +290,7 @@ public class PolicyContainer implements Startable } catch (Exception e) { - logger.error("ERROR: Feature API: " + logger.error(ERROR_STRING + feature.getClass().getName(), e); } } @@ -316,7 +318,7 @@ public class PolicyContainer implements Startable } catch (Exception e) { - logger.error("ERROR: Feature API: " + logger.error(ERROR_STRING + feature.getClass().getName(), e); } } @@ -412,7 +414,7 @@ public class PolicyContainer implements Startable } catch (Exception e) { - logger.error("ERROR: Feature API: " + logger.error(ERROR_STRING + feature.getClass().getName(), e); } } @@ -518,7 +520,7 @@ public class PolicyContainer implements Startable public synchronized void startScanner(ReleaseId releaseId) { String version = releaseId.getVersion(); - if (scannerStarted == false && scanner == null && version != null + if (!scannerStarted && scanner == null && version != null && ("LATEST".equals(version) || "RELEASE".equals(version) || version.endsWith("-SNAPSHOT"))) { @@ -661,7 +663,7 @@ public class PolicyContainer implements Startable } catch (Exception e) { - logger.error("ERROR: Feature API: " + logger.error(ERROR_STRING + feature.getClass().getName(), e); } } @@ -739,7 +741,7 @@ public class PolicyContainer implements Startable } catch (Exception e) { - logger.error("ERROR: Feature API: " + logger.error(ERROR_STRING + feature.getClass().getName(), e); } } @@ -758,7 +760,7 @@ public class PolicyContainer implements Startable /** * This method is called when the host goes from the 'standby->active' state. */ - static public void activate() + public static void activate() { // start all of the 'PolicyContainer' instances for (PolicyContainer container : containers) @@ -777,7 +779,7 @@ public class PolicyContainer implements Startable /** * This method is called when the host goes from the 'active->standby' state. */ - static public void deactivate() + public static void deactivate() { // deactivate all of the 'PolicyContainer' instances for (PolicyContainer container : containers) @@ -805,7 +807,7 @@ public class PolicyContainer implements Startable * * @param args standard 'main' arguments, which are currently ignored */ - public static void globalInit(String args[]) + public static void globalInit(String[] args) { String configDir = "config"; logger.info("PolicyContainer.main: configDir=" + configDir); @@ -820,7 +822,7 @@ public class PolicyContainer implements Startable } catch (Exception e) { - logger.error("ERROR: Feature API: " + logger.error(ERROR_STRING + feature.getClass().getName(), e); } } diff --git a/policy-core/src/main/java/org/onap/policy/drools/core/PolicySession.java b/policy-core/src/main/java/org/onap/policy/drools/core/PolicySession.java index 2a949c0b..984ff47f 100644 --- a/policy-core/src/main/java/org/onap/policy/drools/core/PolicySession.java +++ b/policy-core/src/main/java/org/onap/policy/drools/core/PolicySession.java @@ -71,7 +71,7 @@ public class PolicySession private ThreadModel threadModel = null; // supports 'getCurrentSession()' method - static private ThreadLocal<PolicySession> policySession = + private static ThreadLocal<PolicySession> policySession = new ThreadLocal<>(); /** @@ -453,7 +453,7 @@ public class PolicySession * 'KieContainer.updateToVersion(...)' has been called (meaning the * full name of this session has changed). */ - default public void updated() {} + public default void updated() {} } /* ============================================================ */ @@ -488,7 +488,7 @@ public class PolicySession */ private String getThreadName() { - return("Session " + session.getFullName()); + return "Session " + session.getFullName(); } /***************************/ diff --git a/policy-core/src/main/java/org/onap/policy/drools/core/PolicySessionFeatureAPI.java b/policy-core/src/main/java/org/onap/policy/drools/core/PolicySessionFeatureAPI.java index 39377ab7..867325cd 100644 --- a/policy-core/src/main/java/org/onap/policy/drools/core/PolicySessionFeatureAPI.java +++ b/policy-core/src/main/java/org/onap/policy/drools/core/PolicySessionFeatureAPI.java @@ -38,7 +38,7 @@ public interface PolicySessionFeatureAPI extends OrderedService * 'FeatureAPI.impl.getList()' returns an ordered list of objects * implementing the 'FeatureAPI' interface. */ - static public OrderedServiceImpl<PolicySessionFeatureAPI> impl = + public static OrderedServiceImpl<PolicySessionFeatureAPI> impl = new OrderedServiceImpl<>(PolicySessionFeatureAPI.class); /** @@ -48,7 +48,7 @@ public interface PolicySessionFeatureAPI extends OrderedService * @param args standard 'main' arguments, which are currently ignored * @param configDir the relative directory containing configuration files */ - default public void globalInit(String args[], String configDir) {} + public default void globalInit(String[] args, String configDir) {} /** * This method is used to create a 'KieSession' as part of a @@ -65,7 +65,7 @@ public interface PolicySessionFeatureAPI extends OrderedService * (this depends on the capabilities and state of the object implementing * this interface) */ - default public KieSession activatePolicySession + public default KieSession activatePolicySession (PolicyContainer policyContainer, String name, String kieBaseName) { return null; @@ -77,13 +77,13 @@ public interface PolicySessionFeatureAPI extends OrderedService * * @param policySession the new 'PolicySession' instance */ - default public void newPolicySession(PolicySession policySession) {} + public default void newPolicySession(PolicySession policySession) {} /** * This method is called to select the 'ThreadModel' instance associated * with a 'PolicySession' instance. */ - default public PolicySession.ThreadModel selectThreadModel + public default PolicySession.ThreadModel selectThreadModel (PolicySession session) { return null; @@ -95,7 +95,7 @@ public interface PolicySessionFeatureAPI extends OrderedService * @param policySession the 'PolicySession' object that wrapped the * 'KieSession' */ - default public void disposeKieSession(PolicySession policySession) {} + public default void disposeKieSession(PolicySession policySession) {} /** * This method is called after 'KieSession.destroy()' is called @@ -103,5 +103,5 @@ public interface PolicySessionFeatureAPI extends OrderedService * @param policySession the 'PolicySession' object that wrapped the * 'KieSession' */ - default public void destroyKieSession(PolicySession policySession) {} + public default void destroyKieSession(PolicySession policySession) {} } diff --git a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/BusPublisher.java b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/BusPublisher.java index 10bc8325..ad5a9179 100644 --- a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/BusPublisher.java +++ b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/BusPublisher.java @@ -139,10 +139,7 @@ public interface BusPublisher { @Override public String toString() { StringBuilder builder = new StringBuilder(); - builder.append("CambriaPublisherWrapper ["). - append("publisher.getPendingMessageCount()="). - append(publisher.getPendingMessageCount()). - append("]"); + builder.append("CambriaPublisherWrapper []"); return builder.toString(); } @@ -289,7 +286,6 @@ public interface BusPublisher { append(", publisher.getHost()=").append(publisher.getHost()). append(", publisher.getProtocolFlag()=").append(publisher.getProtocolFlag()). append(", publisher.getUsername()=").append(publisher.getUsername()). - append(", publisher.getPendingMessageCount()=").append(publisher.getPendingMessageCount()). append("]"); return builder.toString(); } diff --git a/policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngine.java b/policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngine.java index d60e817a..583deacc 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngine.java +++ b/policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngine.java @@ -357,12 +357,12 @@ class PolicyEngineManager implements PolicyEngine { /** * Is the Policy Engine running? */ - protected boolean alive = false; + protected volatile boolean alive = false; /** * Is the engine locked? */ - protected boolean locked = false; + protected volatile boolean locked = false; /** * Properties used to initialize the engine @@ -1018,7 +1018,7 @@ class PolicyEngineManager implements PolicyEngine { } @Override - public synchronized boolean isAlive() { + public boolean isAlive() { return this.alive; } @@ -1117,7 +1117,7 @@ class PolicyEngineManager implements PolicyEngine { } @Override - public synchronized boolean isLocked() { + public boolean isLocked() { return this.locked; } diff --git a/policy-utils/src/main/java/org/onap/policy/drools/utils/OrderedServiceImpl.java b/policy-utils/src/main/java/org/onap/policy/drools/utils/OrderedServiceImpl.java index ee70a4b5..99c4566a 100644 --- a/policy-utils/src/main/java/org/onap/policy/drools/utils/OrderedServiceImpl.java +++ b/policy-utils/src/main/java/org/onap/policy/drools/utils/OrderedServiceImpl.java @@ -43,7 +43,12 @@ public class OrderedServiceImpl<T extends OrderedService> private List<T> implementers = null; // 'ServiceLoader' that is used to discover and create the services - private ServiceLoader<T> serviceLoader = null; //ServiceLoader.load(T.class); + private ServiceLoader<T> serviceLoader = null; + + // use this to ensure that we only use one unique instance of each class + @SuppressWarnings("rawtypes") + private static HashMap<Class,OrderedService> classToSingleton = + new HashMap<>(); /** * Constructor - create the 'ServiceLoader' instance @@ -114,7 +119,7 @@ public class OrderedServiceImpl<T extends OrderedService> rval = o1.getClass().getName().compareTo (o2.getClass().getName()); } - return(rval); + return rval; } }); @@ -124,11 +129,6 @@ public class OrderedServiceImpl<T extends OrderedService> return implementers; } - // use this to ensure that we only use one unique instance of each class - @SuppressWarnings("rawtypes") - static private HashMap<Class,OrderedService> classToSingleton = - new HashMap<>(); - /** * If a service implements multiple APIs managed by 'ServiceLoader', a * separate instance is created for each API. This method ensures that @@ -140,7 +140,7 @@ public class OrderedServiceImpl<T extends OrderedService> * the object of this class that was initially created is returned * instead. */ - static private synchronized OrderedService + private static synchronized OrderedService getSingleton(OrderedService service) { // see if we already have an instance of this class diff --git a/policy-utils/src/main/java/org/onap/policy/drools/utils/PropertyUtil.java b/policy-utils/src/main/java/org/onap/policy/drools/utils/PropertyUtil.java index d69ea339..4e00a6db 100644 --- a/policy-utils/src/main/java/org/onap/policy/drools/utils/PropertyUtil.java +++ b/policy-utils/src/main/java/org/onap/policy/drools/utils/PropertyUtil.java @@ -31,12 +31,25 @@ import java.util.Set; import java.util.Timer; import java.util.TimerTask; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + /** * This class provides utilities to read properties from a properties * file, and optionally get notifications of future changes */ public class PropertyUtil { + + // timer thread used for polling for property file changes + private static Timer timer = null; + + // this table maps canonical file into a 'ListenerRegistration' instance + private static HashMap<File, ListenerRegistration> registrations = + new HashMap<>(); + + private static final Logger logger = LoggerFactory.getLogger(PropertyUtil.class.getName()); + /** * Read in a properties file * @param file the properties file @@ -45,7 +58,7 @@ public class PropertyUtil * does not exist or can't be opened, and 'IOException' if there is * a problem loading the properties file. */ - static public Properties getProperties(File file) throws IOException + public static Properties getProperties(File file) throws IOException { // create an InputStream (may throw a FileNotFoundException) FileInputStream fis = new FileInputStream(file); @@ -73,16 +86,13 @@ public class PropertyUtil * does not exist or can't be opened, and 'IOException' if there is * a problem loading the properties file. */ - static public Properties getProperties(String fileName) throws IOException + public static Properties getProperties(String fileName) throws IOException { return getProperties(new File(fileName)); } /* ============================================================ */ - // timer thread used for polling for property file changes - private static Timer timer = null; - /** * This is the callback interface, used for sending notifications of * changes in the properties file. @@ -99,10 +109,6 @@ public class PropertyUtil void propertiesChanged(Properties properties, Set<String> changedKeys); } - // this table maps canonical file into a 'ListenerRegistration' instance - static private HashMap<File, ListenerRegistration> registrations = - new HashMap<>(); - /** * This is an internal class - one instance of this exists for each * property file that is being monitored. Note that multiple listeners @@ -170,7 +176,7 @@ public class PropertyUtil } catch (Exception e) { - System.err.println(e); + logger.warn("Polling for property changes", e); } } }; @@ -303,29 +309,30 @@ public class PropertyUtil * does not exist or can't be opened, and 'IOException' if there is * a problem loading the properties file. */ - static public Properties getProperties(File file, Listener listener) + public static Properties getProperties(File file, Listener listener) throws IOException { + File propFile = file; if (listener == null) { // no listener specified -- just fetch the properties - return getProperties(file); + return getProperties(propFile); } // Convert the file to a canonical form in order to avoid the situation // where different names refer to the same file. - file = file.getCanonicalFile(); + propFile = propFile.getCanonicalFile(); // See if there is an existing registration. The 'synchronized' block // is needed to handle the case where a new listener is added at about // the same time that another one is being removed. synchronized(registrations) { - ListenerRegistration reg = registrations.get(file); + ListenerRegistration reg = registrations.get(propFile); if (reg == null) { // a new registration is needed - reg = new ListenerRegistration(file); + reg = new ListenerRegistration(propFile); } return reg.addListener(listener); } @@ -347,7 +354,7 @@ public class PropertyUtil * does not exist or can't be opened, and 'IOException' if there is * a problem loading the properties file. */ - static public Properties getProperties(String fileName, Listener listener) + public static Properties getProperties(String fileName, Listener listener) throws IOException { return getProperties(new File(fileName), listener); @@ -359,7 +366,7 @@ public class PropertyUtil * @param notify if not null, this is a callback interface that was used for * notifications of changes */ - static public void stopListening(File file, Listener listener) + public static void stopListening(File file, Listener listener) { if (listener != null) { @@ -377,7 +384,7 @@ public class PropertyUtil * @param notify if not null, this is a callback interface that was used for * notifications of changes */ - static public void stopListening(String fileName, Listener listener) + public static void stopListening(String fileName, Listener listener) { stopListening(new File(fileName), listener); } diff --git a/policy-utils/src/main/java/org/onap/policy/drools/utils/ReflectionUtil.java b/policy-utils/src/main/java/org/onap/policy/drools/utils/ReflectionUtil.java index d300058f..50135e84 100644 --- a/policy-utils/src/main/java/org/onap/policy/drools/utils/ReflectionUtil.java +++ b/policy-utils/src/main/java/org/onap/policy/drools/utils/ReflectionUtil.java @@ -31,7 +31,7 @@ import org.slf4j.LoggerFactory; */ public class ReflectionUtil { - protected final static Logger logger = LoggerFactory.getLogger(ReflectionUtil.class); + protected static final Logger logger = LoggerFactory.getLogger(ReflectionUtil.class); private ReflectionUtil(){ } @@ -55,10 +55,7 @@ public class ReflectionUtil { classLoader + " must be provided"); try { - Class<?> aClass = Class.forName(className, - true, - classLoader); - return aClass; + return Class.forName(className, true, classLoader); } catch (Exception e) { logger.error("class {} fetched in {} does not exist", className, classLoader, e); } @@ -292,10 +292,6 @@ <artifactId>jacoco-maven-plugin</artifactId> </plugin> - <plugin> - <groupId>org.codehaus.mojo</groupId> - <artifactId>sonar-maven-plugin</artifactId> - </plugin> </plugins> <pluginManagement> |