[POLICY-98] Code cleanup for sonar issues. 53/6553/3
authorMagnusen, Drew (dm741q) <dm741q@att.com>
Wed, 2 Aug 2017 18:00:23 +0000 (13:00 -0500)
committerMagnusen, Drew (dm741q) <dm741q@att.com>
Fri, 4 Aug 2017 13:02:00 +0000 (08:02 -0500)
Modified code in ECOMP-Logging to resolve critical/major sonar issues.
Not all issues were resolved as some guidance needs to be provided for
specific cases.

Restored config/policyLogger.properties file. It was modified by a junit
test.

Change-Id: I49fee98b2497d9d503d81bbbacbb1b416e1058a7
Signed-off-by: Magnusen, Drew (dm741q) <dm741q@att.com>
15 files changed:
common-logging/config/policyLogger.properties
common-logging/src/main/java/org/onap/policy/common/logging/ONAPLoggingContext.java
common-logging/src/main/java/org/onap/policy/common/logging/ONAPLoggingUtils.java
common-logging/src/main/java/org/onap/policy/common/logging/eelf/DroolsPDPMDCInfo.java
common-logging/src/main/java/org/onap/policy/common/logging/eelf/ErrorCodeMap.java
common-logging/src/main/java/org/onap/policy/common/logging/eelf/EventData.java
common-logging/src/main/java/org/onap/policy/common/logging/eelf/EventTrackInfo.java
common-logging/src/main/java/org/onap/policy/common/logging/eelf/EventTrackInfoHandler.java
common-logging/src/main/java/org/onap/policy/common/logging/eelf/MDCInfo.java
common-logging/src/main/java/org/onap/policy/common/logging/eelf/PolicyLogger.java
common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/FlexLogger.java
common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/FlexLoggerTester.java
common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/PropertyUtil.java
common-logging/src/main/java/org/onap/policy/common/logging/nsa/impl/SharedContext.java
common-logging/src/main/java/org/onap/policy/common/logging/nsa/impl/Slf4jLoggingContext.java

index 1feed37..8e4e869 100644 (file)
@@ -41,4 +41,4 @@ metricsLogger.level=ON
 # Set level for error file. Set OFF to disable; set ON to enable
 error.level=ON
 # Set level for audit file. Set OFF to disable; set ON to enable
-audit.level=ON
+audit.level=ON
\ No newline at end of file
index bbaf2e0..3932f42 100644 (file)
@@ -20,9 +20,6 @@
 
 package org.onap.policy.common.logging;
 
-//import static org.onap.policy.common.logging.eelf.Configuration.TRANSACTION_BEGIN_TIME_STAMP;
-//import static org.onap.policy.common.logging.eelf.Configuration.TRANSACTION_ELAPSED_TIME;
-//import static org.onap.policy.common.logging.eelf.Configuration.TRANSACTION_END_TIME_STAMP;
 
 import java.text.SimpleDateFormat;
 import java.time.Duration;
@@ -88,7 +85,6 @@ public class ONAPLoggingContext {
     private static LoggingContextFactory.Builder loggingContextBuilder = new LoggingContextFactory.Builder();
 
     protected SharedLoggingContext context = null;
-//    private long transactionStartTime = 0;
     private Instant transactionStartTime;
     private Instant metricStartTime;
     
@@ -132,7 +128,6 @@ public class ONAPLoggingContext {
         * the duration of the transaction.
         */
        public void transactionStarted() {
-//             transactionStartTime = System.currentTimeMillis();
                transactionStartTime = Instant.now();
                setTransactionBeginTimestamp(transactionStartTime);
        }
@@ -154,7 +149,6 @@ public class ONAPLoggingContext {
         * the duration of the metric.
         */
        public void metricStarted() {
-//             transactionStartTime = System.currentTimeMillis();
                metricStartTime = Instant.now();
                setMetricBeginTimestamp(metricStartTime);
        }
@@ -419,32 +413,6 @@ public class ONAPLoggingContext {
                return context.get(CLASSNAME, "");
        }
 
-       /**
-        * Set the value for the data item with key "timer".
-        * An alternative to calling this method directly is to call
-        * <code>transactionStarted()</code> at the start of transaction
-        * processing and <code>transactionEnded()</code> at the end,
-        * which will compute the time difference in milliseconds
-        * and store the result as the "timer" value.
-        * 
-        * @param id
-        */
-//     public void setTimer(Long timer) {
-//             context.put(TIMER, timer);
-//     }
-       
-//     public void setTimer(Long elapsedtime) {
-//             String unit = " milliseconds";
-//             context.put(TRANSACTION_ELAPSED_TIME, elapsedtime + unit);
-//     }
-
-       /**
-        * Get the value for the data item with key "timer"
-        * @return current value, or 0 if not set
-        */
-//     public long getTimer() {
-//             return context.get(TRANSACTION_ELAPSED_TIME, 0);
-//     }
        
        /**
         * Set the value for the data item with key "TransactionBeginTimestamp"
@@ -499,16 +467,8 @@ public class ONAPLoggingContext {
        
        public void setTransactionElapsedTime(Instant transactionEndTime) {
                long ns = Duration.between(transactionStartTime, transactionEndTime).toMillis();
-               //String unit = " Seconds";
-               //if(ns == 1){
-                       //unit = " Second";
-               //}
-               
-               //if(ns < 1){
-                       //ns = Duration.between(transactionStartTime, transactionEndTime).toMillis();
-                       //unit = " milliseconds";
-               //}
-               context.put(TRANSACTION_ELAPSED_TIME, ns); // + unit);
+
+               context.put(TRANSACTION_ELAPSED_TIME, ns); 
        }
 
        /**
@@ -572,16 +532,8 @@ public class ONAPLoggingContext {
        
        public void setMetricElapsedTime(Instant metricEndTime) {
                long ns = Duration.between(metricStartTime, metricEndTime).toMillis();
-               //String unit = " Seconds";
-               //if(ns == 1){
-                       //unit = " Second";
-               //}
-               
-               //if(ns < 1){
-                       //ns = Duration.between(metricStartTime, metricEndTime).toMillis();
-                       //unit = " milliseconds";
-               //}
-               context.put(METRIC_ELAPSED_TIME, ns); // + unit);
+
+               context.put(METRIC_ELAPSED_TIME, ns);
        }
 
        /**
index b4d4d8d..e0778ea 100644 (file)
@@ -24,6 +24,8 @@ import javax.servlet.http.HttpServletRequest;
 
 public class ONAPLoggingUtils {
 
+       private ONAPLoggingUtils() {};
+       
        public static ONAPLoggingContext getLoggingContextForRequest(HttpServletRequest request,
                        ONAPLoggingContext baseContext)
        {
index 01fc0dd..7b9bba6 100644 (file)
@@ -24,7 +24,7 @@ import java.util.concurrent.ConcurrentHashMap;
 
 public class DroolsPDPMDCInfo implements MDCInfo{
 
-    private static ConcurrentHashMap<String, String> mdcMap = new ConcurrentHashMap<String, String>();
+    private static ConcurrentHashMap<String, String> mdcMap = new ConcurrentHashMap<>();
 
     static {
        
index cbb8c7a..1fce479 100644 (file)
@@ -30,7 +30,7 @@ import java.util.HashMap;
 public class ErrorCodeMap {
        
 
-    public static HashMap<MessageCodes, ErrorCodeInfo> hm = new HashMap<MessageCodes, ErrorCodeInfo>();
+    protected static final HashMap<MessageCodes, ErrorCodeInfo> hm = new HashMap<>();
     
     private static String ERROR_PERMISSIONS = "POLICY-100E";
        private static String ERROR_PERMISSIONS_DESCRIPTION = "This is a Permissions Error. Please check the error message for detail information";
@@ -79,7 +79,7 @@ public class ErrorCodeMap {
        hm.put(MessageCodes.ERROR_UNKNOWN, new ErrorCodeInfo(ERROR_UNKNOWN, ERROR_UNKNOWN_DESCRIPTION));
        hm.put(MessageCodes.ERROR_AUDIT, new ErrorCodeInfo(ERROR_AUDIT, ERROR_AUDIT_DESCRIPTION));
     }
-    
+    private ErrorCodeMap() {};
     static class ErrorCodeInfo {
        
        private String errorCode;
index 2aaa114..2267b90 100644 (file)
@@ -33,6 +33,9 @@ public class EventData {
        private Instant startTime = null;
        private Instant endTime = null;
 
+               //Default constructor takes no arguments.
+               //Is empty because instance variables are assigned
+               //their default values upon declaration.
        public EventData() {
                
        }
@@ -68,6 +71,7 @@ public class EventData {
                this.endTime = endTime;
        }
        
+       @Override
        public String toString(){
                return requestID + " Starting Time : " + this.startTime + " Ending Time : " + this.endTime;
        }
index 7e4d45d..5869986 100644 (file)
@@ -37,7 +37,7 @@ public class EventTrackInfo {
                 * Load factor of 0,9 ensures a dense packaging inside ConcurrentHashMap which will optimize memory use
                 * ConcurencyLevel set to 1 will ensure that only one shard is created and maintained 
                 */
-               eventInfo = new ConcurrentHashMap<String, EventData>(16, 0.9f, 1);      
+               eventInfo = new ConcurrentHashMap<>(16, 0.9f, 1);       
        }
    
        /**
index d0a7cc1..8dc7ecb 100644 (file)
@@ -56,8 +56,8 @@ public class EventTrackInfoHandler extends TimerTask {
                        return;
                }
 
-               Instant startTime = null;
-               long ns = 0;
+               Instant startTime;
+               long ns;
 
                ArrayList<String> expiredEvents = null;
 
@@ -76,7 +76,7 @@ public class EventTrackInfoHandler extends TimerTask {
 
                        if (ns > PolicyLogger.EXPIRED_TIME){    
                                if (expiredEvents == null) {
-                                       expiredEvents = new ArrayList<String>();
+                                       expiredEvents = new ArrayList<>();
                                }
                                expiredEvents.add(key);
 
index fc44dcf..d57ed0c 100644 (file)
@@ -27,7 +27,7 @@ import java.util.concurrent.ConcurrentHashMap;
  * Interface needs to be implemented by DroolsPDPMDCInfo
  *
  */
-
+@FunctionalInterface
 public interface MDCInfo {
        
        public ConcurrentHashMap<String, String> getMDCInfo();
index 7507c9e..e2ab31c 100644 (file)
@@ -121,7 +121,7 @@ public class PolicyLogger {
                        transId = UUID.randomUUID().toString();
                }
                
-               if(component != null && component.equalsIgnoreCase("DROOLS")){
+               if("DROOLS".equalsIgnoreCase(component)){
                        MDC.put(TARGET_ENTITY, "POLICY");
                        MDC.put(TARGET_SERVICE_NAME,  "drools evaluate rule");  
                        return postMDCInfoForEvent(transId, new DroolsPDPMDCInfo());
@@ -144,15 +144,7 @@ public class PolicyLogger {
                Instant startTime = Instant.now();
                Instant endTime = Instant.now();
                long ns = Duration.between(startTime, endTime).toMillis(); // use millisecond as default and remove unit from log
-               //String unit = " Seconds";
-               //if(ns == 1){
-                       //unit = " Second";
-               //}
-               
-               //if(ns < 1){
-                       //ns = Duration.between(startTime, endTime).toMillis();
-                       //unit = " milliseconds";
-               //}
+
                MDC.put(MDC_INSTANCE_UUID, "");
                MDC.put(MDC_ALERT_SEVERITY, "");
                
@@ -164,7 +156,7 @@ public class PolicyLogger {
                //set default values for these required fields below, they can be overridden
                formatedTime = sdf.format(Date.from(endTime));
                MDC.put(END_TIME_STAMP, formatedTime);
-               MDC.put(ELAPSED_TIME, Long.toString(ns)); // + unit);
+               MDC.put(ELAPSED_TIME, Long.toString(ns));
                
                MDC.put(PARTNER_NAME, "N/A");
                
@@ -190,7 +182,7 @@ public class PolicyLogger {
                        
                        ConcurrentHashMap<String, String> mdcMap = mdcInfo.getMDCInfo();
                    Iterator<String> keyIterator = mdcMap.keySet().iterator();
-                   String key = "";
+                   String key;
                    
                    while(keyIterator.hasNext()){
                        key = keyIterator.next();
@@ -207,15 +199,6 @@ public class PolicyLogger {
                Instant startTime = Instant.now();
                Instant endTime = Instant.now();
                long ns = Duration.between(startTime, endTime).toMillis(); // use millisecond as default and remove unit from log
-               //String unit = " Seconds";
-               //if(ns == 1){
-                       //unit = " Second";
-               //}
-               
-               //if(ns < 1){
-                       //ns = Duration.between(startTime, endTime).toMillis();
-                       //unit = " milliseconds";
-               //}
 
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS+00:00");
        
@@ -225,7 +208,7 @@ public class PolicyLogger {
                //set default values for these required fields below, they can be overridden
                formatedTime = sdf.format(Date.from(endTime));
                MDC.put(END_TIME_STAMP, formatedTime);
-               MDC.put(ELAPSED_TIME, Long.toString(ns)); // + unit);
+               MDC.put(ELAPSED_TIME, Long.toString(ns));
 
                return transId;
        }
@@ -238,15 +221,7 @@ public class PolicyLogger {
                Instant startTime = Instant.now();
                Instant endTime = Instant.now();
                long ns = Duration.between(startTime, endTime).toMillis();
-               //String unit = " Seconds";
-               //if(ns == 1){
-                       //unit = " Second";
-               //}
-               
-               //if(ns < 1){
-                       //ns = Duration.between(startTime, endTime).toMillis();
-                       //unit = " milliseconds";
-               //}
+
                MDC.put(MDC_INSTANCE_UUID, "");
                MDC.put(MDC_ALERT_SEVERITY, "");
                
@@ -258,7 +233,7 @@ public class PolicyLogger {
                //set default values for these required fields below, they can be overridden
                formatedTime = sdf.format(Date.from(endTime));
                MDC.put(END_TIME_STAMP, formatedTime);
-               MDC.put(ELAPSED_TIME, Long.toString(ns)); // + unit);
+               MDC.put(ELAPSED_TIME, Long.toString(ns));
                
                MDC.put(PARTNER_NAME, "N/A");
                
@@ -770,11 +745,9 @@ public class PolicyLogger {
                            isEventTrackerRunning = true;
                        }
                        
-               }else if( size <= STOP_CHECK_POINT){
+               }else if( size <= STOP_CHECK_POINT && isEventTrackerRunning){
                    
-                       if(isEventTrackerRunning){
-                               stopCleanUp();
-                       }                       
+                       stopCleanUp();  
                }
        }
        
@@ -951,27 +924,18 @@ public class PolicyLogger {
                MDC.put(RESPONSE_DESCRIPTION, "N/A");
                
                long ns = Duration.between(startTime, endTime).toMillis();
-               //String unit = " Seconds";
-               //if(ns == 1){
-                       //unit = " Second";
-               //}
                
-               //if(ns < 1){
-                       //ns = Duration.between(startTime, endTime).toMillis();
-                       //unit = " milliseconds";
-               //}
-               
-               MDC.put(ELAPSED_TIME, Long.toString(ns)); // + unit);
+               MDC.put(ELAPSED_TIME, Long.toString(ns));
                
                auditLogger.info(MessageCodes.RULE_AUDIT_START_END_INFO,
                        serviceName, rule, startTime.toString(), endTime.toString(), Long.toString(ns), policyVersion);
                
                //--- remove the record from the concurrentHashMap
-               if(eventTracker != null){
-                       if(eventTracker.getEventDataByRequestID(eventId) != null){
-                               eventTracker.remove(eventId);
-                               debugLogger.info("eventTracker.remove(" + eventId + ")");
-                       }
+               if(eventTracker != null && eventTracker.getEventDataByRequestID(eventId) != null){
+
+                       eventTracker.remove(eventId);
+                       debugLogger.info("eventTracker.remove(" + eventId + ")");
+                       
                }       
        }
 
@@ -1089,7 +1053,7 @@ public class PolicyLogger {
         PrintWriter pw = new PrintWriter(sw);
         t.printStackTrace(pw);
         String newStValue = sw.toString().replace ('|', '!').replace ("\n", " - ");
-        int curSize = (arguments == null ? 0 : arguments.length);
+        int curSize = arguments == null ? 0 : arguments.length;
         StringBuffer newArgument = new StringBuffer();
         for(int i=0; i<curSize; i++) {
                newArgument.append(arguments[i]);
@@ -1151,11 +1115,11 @@ public class PolicyLogger {
                // fetch and verify definitions of some properties
                try{
                        
-                       int timerDelayTime = Integer.parseInt(loggerProperties.getProperty("timer.delay.time", ""+1000));
-                       int checkInterval = Integer.parseInt(loggerProperties.getProperty("check.interval", ""+30000));
-                       int expiredDate = Integer.parseInt(loggerProperties.getProperty("event.expired.time",""+86400));
-                       int concurrentHashMapLimit = Integer.parseInt(loggerProperties.getProperty("concurrentHashMap.limit", ""+5000));
-                       int stopCheckPoint = Integer.parseInt(loggerProperties.getProperty("stop.check.point",""+2500));                        
+                       int timerDelayTime = Integer.parseInt(loggerProperties.getProperty("timer.delay.time", Integer.toString(1000)));
+                       int checkInterval = Integer.parseInt(loggerProperties.getProperty("check.interval", Integer.toString(30000)));
+                       int expiredDate = Integer.parseInt(loggerProperties.getProperty("event.expired.time", Integer.toString(86400)));
+                       int concurrentHashMapLimit = Integer.parseInt(loggerProperties.getProperty("concurrentHashMap.limit", Integer.toString(5000)));
+                       int stopCheckPoint = Integer.parseInt(loggerProperties.getProperty("stop.check.point", Integer.toString(2500)));                        
                    String loggerType = loggerProperties.getProperty("logger.type",logger_type.toString());
                    
                    String debugLevel = loggerProperties.getProperty("debugLogger.level","INFO");
@@ -1166,7 +1130,7 @@ public class PolicyLogger {
                    String overrideLogbackLevel = loggerProperties.getProperty("override.logback.level.setup");
 
                    if(overrideLogbackLevel != null && !overrideLogbackLevel.isEmpty()) {
-                       if(overrideLogbackLevel.equalsIgnoreCase("TRUE")){
+                       if("TRUE".equalsIgnoreCase(overrideLogbackLevel)){
                                isOverrideLogbackLevel = true;
                        }else{
                                isOverrideLogbackLevel = false;
@@ -1295,15 +1259,15 @@ public class PolicyLogger {
                        
                        if (loggerType != null){
                                
-                               if (loggerType.equalsIgnoreCase("EELF")){
+                               if ("EELF".equalsIgnoreCase(loggerType)){
                                        
                                        logger_type = LoggerType.EELF;
                                        
-                               }else if (loggerType.equalsIgnoreCase("LOG4J")){
+                               }else if ("LOG4J".equalsIgnoreCase(loggerType)){
                                        
                                        logger_type = LoggerType.LOG4J;
                                        
-                               }else if (loggerType.equalsIgnoreCase("SYSTEMOUT")){
+                               }else if ("SYSTEMOUT".equalsIgnoreCase(loggerType)){
                                        
                                        logger_type = LoggerType.SYSTEMOUT;
                                        
@@ -1368,7 +1332,7 @@ public class PolicyLogger {
        public static void setErrorLevel(String errorLevel){    
                
                if(isOverrideLogbackLevel){
-                       if(errorLevel != null && errorLevel.equalsIgnoreCase("OFF")){
+                       if("OFF".equalsIgnoreCase(errorLevel)){
                                PolicyLogger.ERROR_LEVEL = Level.OFF; 
                                errorLogger.setLevel(ERROR_LEVEL);
                        }else{
@@ -1385,7 +1349,7 @@ public class PolicyLogger {
        public static void setMetricsLevel(String metricsLevel){
                
                if(isOverrideLogbackLevel){
-                       if(metricsLevel != null && metricsLevel.equalsIgnoreCase("OFF")){
+                       if("OFF".equalsIgnoreCase(metricsLevel)){
                                PolicyLogger.METRICS_LEVEL = Level.OFF;
                                metricsLogger.setLevel(METRICS_LEVEL);
                        }else {
@@ -1403,7 +1367,7 @@ public class PolicyLogger {
        public static void setAuditLevel(String auditLevel){
                
                if(isOverrideLogbackLevel){
-                       if(auditLevel != null && auditLevel.equalsIgnoreCase("OFF")){
+                       if("OFF".equalsIgnoreCase(auditLevel)){
                                PolicyLogger.AUDIT_LEVEL = Level.OFF; 
                                auditLogger.setLevel(AUDIT_LEVEL);
                        }else {
index 797f857..2cf591c 100644 (file)
@@ -39,9 +39,9 @@ import org.onap.policy.common.logging.flexlogger.PropertyUtil.Listener;
 public class FlexLogger extends SecurityManager{
 
        private static LoggerType loggerType = LoggerType.EELF;
-    private static ConcurrentHashMap<String, Logger4J> logger4JMap = new ConcurrentHashMap<String, Logger4J>();
-    private static ConcurrentHashMap<String, EelfLogger> eelfLoggerMap = new ConcurrentHashMap<String, EelfLogger>();
-    private static ConcurrentHashMap<String, SystemOutLogger> systemOutMap = new ConcurrentHashMap<String, SystemOutLogger>();
+    private static ConcurrentHashMap<String, Logger4J> logger4JMap = new ConcurrentHashMap<>();
+    private static ConcurrentHashMap<String, EelfLogger> eelfLoggerMap = new ConcurrentHashMap<>();
+    private static ConcurrentHashMap<String, SystemOutLogger> systemOutMap = new ConcurrentHashMap<>();
     //--- init logger first
        static {
                loggerType = initlogger();
@@ -60,10 +60,10 @@ public class FlexLogger extends SecurityManager{
                        logger = getEelfLogger(clazz, false);                   
                        break;
                case LOG4J:                     
-                       logger = getLog4JLogger(clazz);                 
+                       logger = getLog4JLogger();                      
                        break;
                case SYSTEMOUT:
-                       logger = getSystemOutLogger(null);
+                       logger = getSystemOutLogger();
                        break;
                }
 
@@ -87,7 +87,7 @@ public class FlexLogger extends SecurityManager{
                        logger = getLog4JLogger(s);
                        break;                  
                case SYSTEMOUT:
-                       logger = getSystemOutLogger(null);
+                       logger = getSystemOutLogger();
                        break;
                }
 
@@ -109,10 +109,10 @@ public class FlexLogger extends SecurityManager{
                        logger = getEelfLogger(clazz, isNewTransaction);
                        break;
                case LOG4J:
-                       logger = getLog4JLogger(clazz);
+                       logger = getLog4JLogger();
                        break;
                case SYSTEMOUT:
-                       logger = getSystemOutLogger(null);
+                       logger = getSystemOutLogger();
                        break;
                }
 
@@ -137,7 +137,7 @@ public class FlexLogger extends SecurityManager{
                        logger = getLog4JLogger(s);
                        break;
                case SYSTEMOUT:
-                       logger = getSystemOutLogger(null);
+                       logger = getSystemOutLogger();
                        break;
                }
 
@@ -156,7 +156,7 @@ public class FlexLogger extends SecurityManager{
         * Returns an instance of Logger4J
         * @param clazz
         */
-   private static Logger4J getLog4JLogger(Class<?> clazz){
+   private static Logger4J getLog4JLogger(){
                 String className = new FlexLogger().getClassName();
 
                if(!logger4JMap.containsKey(className)){
@@ -190,8 +190,8 @@ public class FlexLogger extends SecurityManager{
         */
    private static EelfLogger getEelfLogger(Class<?> clazz, boolean isNewTransaction){
 
-               String className = "";
-               EelfLogger logger = null;
+               String className;
+               EelfLogger logger;
                if(clazz != null){
                        className = clazz.getName();
                }else{
@@ -221,7 +221,7 @@ public class FlexLogger extends SecurityManager{
         * Returns an instance of SystemOutLogger
         * @param clazz
         */
-   private static SystemOutLogger getSystemOutLogger(Class<?> clazz){
+   private static SystemOutLogger getSystemOutLogger(){
 
                 String className = new FlexLogger().getClassName();
                
@@ -253,8 +253,7 @@ public class FlexLogger extends SecurityManager{
                                if (loggerTypeString != null){                                  
                                        if (loggerTypeString.equalsIgnoreCase("EELF")){                                 
                                                loggerType = LoggerType.EELF;
-                                               if (overrideLogbackLevel != null && 
-                                                       overrideLogbackLevel.equalsIgnoreCase("TRUE")) {
+                                               if ("TRUE".equalsIgnoreCase(overrideLogbackLevel)) {
                                                         System.out.println("FlexLogger: start listener.");
                                                     properties = PropertyUtil.getProperties
                                                                                 ("config/policyLogger.properties", 
@@ -292,6 +291,7 @@ public class FlexLogger extends SecurityManager{
                /**
                 * This method will be called automatically if he policyLogger.properties got updated
                 */
+               @Override
                public void propertiesChanged(Properties properties,
                                Set<String> changedKeys) {
                        
index eddece1..ff33c29 100644 (file)
@@ -30,8 +30,6 @@ public class FlexLoggerTester {
                // get an instance of logger 
                Logger  logger = FlexLogger.getLogger(FlexLoggerTester.class);
                
-               //logger.info("this is a testing of FlexLogger with logger type:" + FlexLogger.loggerType);
-               
                logger.info("logger.isAuditEnabled():" + logger.isAuditEnabled());
                logger.info("logger.isDebugEnabled():" + logger.isDebugEnabled());
                logger.info("logger.isErrorEnabled():" + logger.isErrorEnabled());
index 598dd09..d2a9823 100644 (file)
@@ -56,7 +56,7 @@ public class PropertyUtil
 
                // load properties (may throw an IOException)
                rval.load(fis);
-               return(rval);
+               return rval;
          }
        finally
          {
@@ -75,7 +75,7 @@ public class PropertyUtil
    */
   static public Properties getProperties(String fileName) throws IOException
   {
-       return(getProperties(new File(fileName)));
+       return getProperties(new File(fileName));
   }
 
   /* ============================================================ */
@@ -87,6 +87,7 @@ public class PropertyUtil
    * This is the callback interface, used for sending notifications of
    * changes in the properties file.
    */
+  @FunctionalInterface
   public interface Listener
   {
        /**
@@ -100,7 +101,7 @@ public class PropertyUtil
 
   // this table maps canonical file into a 'ListenerRegistration' instance
   static private HashMap<File, ListenerRegistration> registrations =
-       new HashMap<File, ListenerRegistration>();
+       new HashMap<>();
 
   /**
    * This is an internal class - one instance of this exists for each
@@ -141,7 +142,7 @@ public class PropertyUtil
          properties = getProperties(file);
 
          // no listeners yet
-         listeners = new LinkedList<Listener>();
+         listeners = new LinkedList<>();
 
          // add to static table, so this instance can be shared
          registrations.put(file, this);
@@ -163,6 +164,7 @@ public class PropertyUtil
          // create and schedule the timer task, so this is periodically polled
          timerTask = new TimerTask()
                {
+                 @Override
                  public void run()
                  {
                        try
@@ -186,7 +188,7 @@ public class PropertyUtil
        synchronized Properties addListener(Listener listener)
        {
          listeners.add(listener);
-         return((Properties)properties.clone());
+         return (Properties)properties.clone();
        }
 
        /**
@@ -203,7 +205,7 @@ public class PropertyUtil
          // one is being removed.
          synchronized(registrations)
                {
-                 if (listeners.size() == 0)
+                 if (listeners.isEmpty())
                        {
                          timerTask.cancel();
                          registrations.remove(file);
@@ -226,7 +228,7 @@ public class PropertyUtil
                  // Save old set, and initial set of changed properties.
                  Properties oldProperties = properties;
                  HashSet<String> changedProperties =
-                       new HashSet<String>(oldProperties.stringPropertyNames());
+                       new HashSet<>(oldProperties.stringPropertyNames());
 
                  // Fetch the list of listeners that we will potentially notify,
                  // and the new properties. Note that this is in a 'synchronized'
@@ -259,7 +261,7 @@ public class PropertyUtil
                        }
 
                  // 'changedProperties' should be correct at this point
-                 if (changedProperties.size() != 0)
+                 if (!changedProperties.isEmpty())
                        {
                          // there were changes - notify everyone in 'listeners'
                          for (final Listener notify : listeners)
@@ -269,12 +271,13 @@ public class PropertyUtil
                                  final Properties tmpProperties =
                                        (Properties)(properties.clone());
                                  final HashSet<String> tmpChangedProperties =
-                                       new HashSet<String>(changedProperties);
+                                       new HashSet<>(changedProperties);
 
                                  // Do the notification in a separate thread, so blocking
                                  // won't cause any problems.
                                  new Thread()
                                  {
+                                       @Override
                                        public void run()
                                        {
                                          notify.propertiesChanged
@@ -309,25 +312,25 @@ public class PropertyUtil
        if (listener == null)
          {
                // no listener specified -- just fetch the properties
-               return(getProperties(file));
+               return getProperties(file);
          }
 
        // Convert the file to a canonical form in order to avoid the situation
        // where different names refer to the same file.
-       file = file.getCanonicalFile();
+       File tempFile = file.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(tempFile);
                if (reg == null)
                  {
                        // a new registration is needed
-                       reg = new ListenerRegistration(file);
+                       reg = new ListenerRegistration(tempFile);
                  }
-               return(reg.addListener(listener));
+               return reg.addListener(listener);
          }
   }
 
@@ -350,7 +353,7 @@ public class PropertyUtil
   static public Properties getProperties(String fileName, Listener listener)
        throws IOException
   {
-       return(getProperties(new File(fileName), listener));
+       return getProperties(new File(fileName), listener);
   }
 
   /**
@@ -394,6 +397,7 @@ public class PropertyUtil
                this.name = name;
          }
 
+       @Override
        public void propertiesChanged(Properties properties, Set<String> changedKeys)
          {
                System.out.println("Test(" + name + ")\nproperties = " + properties
index 715edfa..7f4a109 100644 (file)
@@ -35,7 +35,7 @@ public class SharedContext extends Slf4jLoggingContext implements SharedLoggingC
        public SharedContext ( LoggingContext base )
        {
                super ( base );
-               fMap = new HashMap<String,String> ();
+               fMap = new HashMap<> ();
        }
 
        @Override
index 187b295..628d4b9 100644 (file)
@@ -40,12 +40,13 @@ public class Slf4jLoggingContext implements LoggingContext
                MDC.put ( key, value );
        }
 
+       @Override
        public void put ( String key, long value )
        {
-               put ( key, "" + value );
+               put ( key, Long.toString(value));
        }
 
-       
+       @Override
        public String get ( String key, String defaultValue )
        {
                String result = MDC.get ( key );
@@ -56,9 +57,10 @@ public class Slf4jLoggingContext implements LoggingContext
                return result;
        }
 
+       @Override
        public long get ( String key, long defaultValue )
        {
-               final String str = get ( key, "" + defaultValue );
+               final String str = get ( key, Long.toString(defaultValue));
                try
                {
                        return Long.parseLong ( str );