You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@knox.apache.org by kr...@apache.org on 2018/12/11 16:26:43 UTC
knox git commit: KNOX-1668 - Enable PMD multithreading ruleset
Repository: knox
Updated Branches:
refs/heads/master f7eb4538b -> c2cbb345b
KNOX-1668 - Enable PMD multithreading ruleset
Signed-off-by: Kevin Risden <kr...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/knox/repo
Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/c2cbb345
Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/c2cbb345
Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/c2cbb345
Branch: refs/heads/master
Commit: c2cbb345b0af2cba3ab63a726aef6df0573fe71a
Parents: f7eb453
Author: Kevin Risden <kr...@apache.org>
Authored: Tue Dec 11 10:48:41 2018 -0500
Committer: Kevin Risden <kr...@apache.org>
Committed: Tue Dec 11 11:15:31 2018 -0500
----------------------------------------------------------------------
.../resources/build-tools/pmd/pmd-ruleset.xml | 5 +-
.../resources/build-tools/spotbugs-filter.xml | 10 ----
.../ambari/AmbariConfigurationMonitor.java | 13 +----
.../gateway/i18n/messages/MessagesFactory.java | 2 +-
.../loggers/jdk/JdkMessageLoggerFactory.java | 2 -
.../loggers/sout/SoutMessageLoggerFactory.java | 8 +--
.../loggers/test/TestMessageLoggerFactory.java | 8 +--
.../gateway/i18n/messages/MessagesTest.java | 2 -
.../org/apache/knox/gateway/GatewayServlet.java | 2 +-
.../topology/impl/DefaultTopologyService.java | 2 +-
.../RemoteConfigurationMonitorFactory.java | 6 +-
.../websockets/ProxyWebSocketAdapter.java | 60 ++++++--------------
.../gateway/audit/api/AuditServiceFactory.java | 8 +--
.../audit/api/CorrelationServiceFactory.java | 9 +--
.../gateway/audit/log4j/appender/JdbmQueue.java | 2 +-
.../appender/JdbmStoreAndForwardAppender.java | 5 +-
16 files changed, 34 insertions(+), 110 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/knox/blob/c2cbb345/build-tools/src/main/resources/build-tools/pmd/pmd-ruleset.xml
----------------------------------------------------------------------
diff --git a/build-tools/src/main/resources/build-tools/pmd/pmd-ruleset.xml b/build-tools/src/main/resources/build-tools/pmd/pmd-ruleset.xml
index a36e899..dc2c394 100644
--- a/build-tools/src/main/resources/build-tools/pmd/pmd-ruleset.xml
+++ b/build-tools/src/main/resources/build-tools/pmd/pmd-ruleset.xml
@@ -65,7 +65,10 @@ limitations under the License.
<exclude name="ReturnEmptyArrayRatherThanNull" />
<exclude name="UseProperClassLoader" />
</rule>
- <!--<rule ref="category/java/multithreading.xml" />-->
+ <rule ref="category/java/multithreading.xml">
+ <exclude name="AvoidSynchronizedAtMethodLevel" />
+ <exclude name="UseConcurrentHashMap" />
+ </rule>
<rule ref="category/java/performance.xml">
<exclude name="AvoidInstantiatingObjectsInLoops" />
<exclude name="InefficientEmptyStringCheck" />
http://git-wip-us.apache.org/repos/asf/knox/blob/c2cbb345/build-tools/src/main/resources/build-tools/spotbugs-filter.xml
----------------------------------------------------------------------
diff --git a/build-tools/src/main/resources/build-tools/spotbugs-filter.xml b/build-tools/src/main/resources/build-tools/spotbugs-filter.xml
index 3a32686..e9d4a34 100644
--- a/build-tools/src/main/resources/build-tools/spotbugs-filter.xml
+++ b/build-tools/src/main/resources/build-tools/spotbugs-filter.xml
@@ -21,16 +21,6 @@ limitations under the License.
xsi:schemaLocation="https://github.com/spotbugs/filter/3.0.0 https://raw.githubusercontent.com/spotbugs/spotbugs/3.1.0/spotbugs/etc/findbugsfilter.xsd">
<Match>
- <Class name="org.apache.knox.gateway.i18n.messages.loggers.sout.SoutMessageLoggerFactory" />
- <Bug pattern="ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD" />
- </Match>
-
- <Match>
- <Class name="org.apache.knox.gateway.i18n.messages.loggers.test.TestMessageLoggerFactory" />
- <Bug pattern="ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD" />
- </Match>
-
- <Match>
<Class name="org.apache.knox.gateway.security.ldap.SimpleLdapDirectoryServer" />
<Bug pattern="PATH_TRAVERSAL_IN" />
</Match>
http://git-wip-us.apache.org/repos/asf/knox/blob/c2cbb345/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariConfigurationMonitor.java
----------------------------------------------------------------------
diff --git a/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariConfigurationMonitor.java b/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariConfigurationMonitor.java
index 3f1b035..e533734 100644
--- a/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariConfigurationMonitor.java
+++ b/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariConfigurationMonitor.java
@@ -39,7 +39,6 @@ import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
class AmbariConfigurationMonitor implements ClusterConfigurationMonitor {
-
private static final String TYPE = "Ambari";
private static final String CLUSTERS_DATA_DIR_NAME = "clusters";
@@ -54,7 +53,6 @@ class AmbariConfigurationMonitor implements ClusterConfigurationMonitor {
static final String INTERVAL_PROPERTY_NAME = "org.apache.knox.gateway.topology.discovery.ambari.monitor.interval";
-
private static final AmbariServiceDiscoveryMessages log = MessagesFactory.get(AmbariServiceDiscoveryMessages.class);
// Ambari address
@@ -263,6 +261,7 @@ class AmbariConfigurationMonitor implements ClusterConfigurationMonitor {
}
}
+ @SuppressWarnings("PMD.DoNotUseThreads")
@Override
public void start() {
(new Thread(internalMonitor, "AmbariConfigurationMonitor")).start();
@@ -294,7 +293,6 @@ class AmbariConfigurationMonitor implements ClusterConfigurationMonitor {
clusterMonitorConfigurations.computeIfAbsent(config.getAddress(), k -> new HashMap<>()).put(clusterName, config);
}
-
/**
* Get the service discovery configuration associated with the specified Ambari instance and cluster.
*
@@ -311,7 +309,6 @@ class AmbariConfigurationMonitor implements ClusterConfigurationMonitor {
return config;
}
-
/**
* Add cluster configuration data to the monitor, which it will use when determining if configuration has changed.
*
@@ -342,7 +339,6 @@ class AmbariConfigurationMonitor implements ClusterConfigurationMonitor {
addClusterConfigVersions(discoveryConfig.getAddress(), clusterName, configVersions);
}
-
/**
* Remove the configuration record for the specified Ambari instance and cluster name.
*
@@ -395,7 +391,6 @@ class AmbariConfigurationMonitor implements ClusterConfigurationMonitor {
return result;
}
-
/**
* Get all the clusters the monitor knows about.
*
@@ -415,10 +410,8 @@ class AmbariConfigurationMonitor implements ClusterConfigurationMonitor {
}
return result;
-
}
-
/**
* Notify registered change listeners.
*
@@ -431,7 +424,6 @@ class AmbariConfigurationMonitor implements ClusterConfigurationMonitor {
}
}
-
/**
* Request the current active configuration version info from Ambari.
*
@@ -458,11 +450,11 @@ class AmbariConfigurationMonitor implements ClusterConfigurationMonitor {
return configVersions;
}
-
/**
* The thread that polls Ambari for configuration details for clusters associated with discovered topologies,
* compares them with the current recorded values, and notifies any listeners when differences are discovered.
*/
+ @SuppressWarnings("PMD.DoNotUseThreads")
static final class PollingConfigAnalyzer implements Runnable {
private static final int DEFAULT_POLLING_INTERVAL = 60;
@@ -534,5 +526,4 @@ class AmbariConfigurationMonitor implements ClusterConfigurationMonitor {
}
}
}
-
}
http://git-wip-us.apache.org/repos/asf/knox/blob/c2cbb345/gateway-i18n/src/main/java/org/apache/knox/gateway/i18n/messages/MessagesFactory.java
----------------------------------------------------------------------
diff --git a/gateway-i18n/src/main/java/org/apache/knox/gateway/i18n/messages/MessagesFactory.java b/gateway-i18n/src/main/java/org/apache/knox/gateway/i18n/messages/MessagesFactory.java
index 751febd..8343b3f 100644
--- a/gateway-i18n/src/main/java/org/apache/knox/gateway/i18n/messages/MessagesFactory.java
+++ b/gateway-i18n/src/main/java/org/apache/knox/gateway/i18n/messages/MessagesFactory.java
@@ -49,7 +49,7 @@ public class MessagesFactory {
MessageLoggerFactory factory;
ServiceLoader<MessageLoggerFactory> loader = ServiceLoader.load( MessageLoggerFactory.class );
Iterator<MessageLoggerFactory> factories = loader.iterator();
- if( factories != null && factories.hasNext() ) {
+ if(factories.hasNext()) {
factory = loader.iterator().next();
} else {
factory = new JdkMessageLoggerFactory();
http://git-wip-us.apache.org/repos/asf/knox/blob/c2cbb345/gateway-i18n/src/main/java/org/apache/knox/gateway/i18n/messages/loggers/jdk/JdkMessageLoggerFactory.java
----------------------------------------------------------------------
diff --git a/gateway-i18n/src/main/java/org/apache/knox/gateway/i18n/messages/loggers/jdk/JdkMessageLoggerFactory.java b/gateway-i18n/src/main/java/org/apache/knox/gateway/i18n/messages/loggers/jdk/JdkMessageLoggerFactory.java
index 965d28f..7fc9007 100644
--- a/gateway-i18n/src/main/java/org/apache/knox/gateway/i18n/messages/loggers/jdk/JdkMessageLoggerFactory.java
+++ b/gateway-i18n/src/main/java/org/apache/knox/gateway/i18n/messages/loggers/jdk/JdkMessageLoggerFactory.java
@@ -23,10 +23,8 @@ import org.apache.knox.gateway.i18n.messages.MessageLoggerFactory;
import java.util.logging.Logger;
public class JdkMessageLoggerFactory implements MessageLoggerFactory {
-
@Override
public MessageLogger getLogger( String name ) {
return new JdkMessageLogger( Logger.getLogger( name ) );
}
-
}
http://git-wip-us.apache.org/repos/asf/knox/blob/c2cbb345/gateway-i18n/src/main/java/org/apache/knox/gateway/i18n/messages/loggers/sout/SoutMessageLoggerFactory.java
----------------------------------------------------------------------
diff --git a/gateway-i18n/src/main/java/org/apache/knox/gateway/i18n/messages/loggers/sout/SoutMessageLoggerFactory.java b/gateway-i18n/src/main/java/org/apache/knox/gateway/i18n/messages/loggers/sout/SoutMessageLoggerFactory.java
index 9f02c1d..496cd58 100644
--- a/gateway-i18n/src/main/java/org/apache/knox/gateway/i18n/messages/loggers/sout/SoutMessageLoggerFactory.java
+++ b/gateway-i18n/src/main/java/org/apache/knox/gateway/i18n/messages/loggers/sout/SoutMessageLoggerFactory.java
@@ -24,19 +24,14 @@ import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public class SoutMessageLoggerFactory implements MessageLoggerFactory {
-
- private static SoutMessageLoggerFactory INSTANCE;
+ private static final SoutMessageLoggerFactory INSTANCE = new SoutMessageLoggerFactory();
private static final Map<String,MessageLogger> LOGGERS = new ConcurrentHashMap<>();
public static SoutMessageLoggerFactory getFactory() {
- if( INSTANCE == null ) {
- INSTANCE = new SoutMessageLoggerFactory();
- }
return INSTANCE;
}
public SoutMessageLoggerFactory() {
- INSTANCE = this;
}
@Override
@@ -48,5 +43,4 @@ public class SoutMessageLoggerFactory implements MessageLoggerFactory {
}
return logger;
}
-
}
http://git-wip-us.apache.org/repos/asf/knox/blob/c2cbb345/gateway-i18n/src/main/java/org/apache/knox/gateway/i18n/messages/loggers/test/TestMessageLoggerFactory.java
----------------------------------------------------------------------
diff --git a/gateway-i18n/src/main/java/org/apache/knox/gateway/i18n/messages/loggers/test/TestMessageLoggerFactory.java b/gateway-i18n/src/main/java/org/apache/knox/gateway/i18n/messages/loggers/test/TestMessageLoggerFactory.java
index 6f23de6..4941e10 100644
--- a/gateway-i18n/src/main/java/org/apache/knox/gateway/i18n/messages/loggers/test/TestMessageLoggerFactory.java
+++ b/gateway-i18n/src/main/java/org/apache/knox/gateway/i18n/messages/loggers/test/TestMessageLoggerFactory.java
@@ -24,19 +24,14 @@ import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public class TestMessageLoggerFactory implements MessageLoggerFactory {
-
- private static TestMessageLoggerFactory INSTANCE;
+ private static final TestMessageLoggerFactory INSTANCE = new TestMessageLoggerFactory();
private static final Map<String,MessageLogger> LOGGERS = new ConcurrentHashMap<>();
public static TestMessageLoggerFactory getFactory() {
- if( INSTANCE == null ) {
- INSTANCE = new TestMessageLoggerFactory();
- }
return INSTANCE;
}
public TestMessageLoggerFactory() {
- INSTANCE = this;
}
@Override
@@ -48,5 +43,4 @@ public class TestMessageLoggerFactory implements MessageLoggerFactory {
}
return logger;
}
-
}
http://git-wip-us.apache.org/repos/asf/knox/blob/c2cbb345/gateway-i18n/src/test/java/org/apache/knox/gateway/i18n/messages/MessagesTest.java
----------------------------------------------------------------------
diff --git a/gateway-i18n/src/test/java/org/apache/knox/gateway/i18n/messages/MessagesTest.java b/gateway-i18n/src/test/java/org/apache/knox/gateway/i18n/messages/MessagesTest.java
index 873a666..dc252b6 100644
--- a/gateway-i18n/src/test/java/org/apache/knox/gateway/i18n/messages/MessagesTest.java
+++ b/gateway-i18n/src/test/java/org/apache/knox/gateway/i18n/messages/MessagesTest.java
@@ -45,7 +45,5 @@ public class MessagesTest {
assertThat( record.getCaller().getClassName(), is( this.getClass().getName() ) );
assertThat( record.getCaller().getMethodName(), is( "testFirst" ) );
-
}
-
}
http://git-wip-us.apache.org/repos/asf/knox/blob/c2cbb345/gateway-server/src/main/java/org/apache/knox/gateway/GatewayServlet.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/knox/gateway/GatewayServlet.java b/gateway-server/src/main/java/org/apache/knox/gateway/GatewayServlet.java
index ee2558f..dcfe6ce 100644
--- a/gateway-server/src/main/java/org/apache/knox/gateway/GatewayServlet.java
+++ b/gateway-server/src/main/java/org/apache/knox/gateway/GatewayServlet.java
@@ -64,7 +64,7 @@ public class GatewayServlet implements Servlet, Filter {
AuditConstants.KNOX_SERVICE_NAME, AuditConstants.KNOX_COMPONENT_NAME );
private FilterConfigAdapter filterConfig;
- private volatile GatewayFilter filter;
+ private GatewayFilter filter;
public GatewayServlet( GatewayFilter filter ) {
this.filterConfig = null;
http://git-wip-us.apache.org/repos/asf/knox/blob/c2cbb345/gateway-server/src/main/java/org/apache/knox/gateway/services/topology/impl/DefaultTopologyService.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/knox/gateway/services/topology/impl/DefaultTopologyService.java b/gateway-server/src/main/java/org/apache/knox/gateway/services/topology/impl/DefaultTopologyService.java
index a3b9021..deef8aa 100644
--- a/gateway-server/src/main/java/org/apache/knox/gateway/services/topology/impl/DefaultTopologyService.java
+++ b/gateway-server/src/main/java/org/apache/knox/gateway/services/topology/impl/DefaultTopologyService.java
@@ -111,7 +111,7 @@ public class DefaultTopologyService
private DescriptorsMonitor descriptorsMonitor;
private Set<TopologyListener> listeners;
- private volatile Map<File, Topology> topologies;
+ private Map<File, Topology> topologies;
private AliasService aliasService;
private RemoteConfigurationMonitor remoteMonitor;
http://git-wip-us.apache.org/repos/asf/knox/blob/c2cbb345/gateway-server/src/main/java/org/apache/knox/gateway/topology/monitor/RemoteConfigurationMonitorFactory.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/knox/gateway/topology/monitor/RemoteConfigurationMonitorFactory.java b/gateway-server/src/main/java/org/apache/knox/gateway/topology/monitor/RemoteConfigurationMonitorFactory.java
index 83eeed4..0874267 100644
--- a/gateway-server/src/main/java/org/apache/knox/gateway/topology/monitor/RemoteConfigurationMonitorFactory.java
+++ b/gateway-server/src/main/java/org/apache/knox/gateway/topology/monitor/RemoteConfigurationMonitorFactory.java
@@ -26,16 +26,15 @@ import org.apache.knox.gateway.services.config.client.RemoteConfigurationRegistr
import java.util.ServiceLoader;
public class RemoteConfigurationMonitorFactory {
-
private static final GatewayMessages log = MessagesFactory.get(GatewayMessages.class);
private static RemoteConfigurationRegistryClientService remoteConfigRegistryClientService;
- public static void setClientService(RemoteConfigurationRegistryClientService clientService) {
+ static void setClientService(RemoteConfigurationRegistryClientService clientService) {
remoteConfigRegistryClientService = clientService;
}
- private static RemoteConfigurationRegistryClientService getClientService() {
+ private static synchronized RemoteConfigurationRegistryClientService getClientService() {
if (remoteConfigRegistryClientService == null) {
GatewayServices services = GatewayServer.getGatewayServices();
if (services != null) {
@@ -70,5 +69,4 @@ public class RemoteConfigurationMonitorFactory {
return rcm;
}
-
}
http://git-wip-us.apache.org/repos/asf/knox/blob/c2cbb345/gateway-server/src/main/java/org/apache/knox/gateway/websockets/ProxyWebSocketAdapter.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/knox/gateway/websockets/ProxyWebSocketAdapter.java b/gateway-server/src/main/java/org/apache/knox/gateway/websockets/ProxyWebSocketAdapter.java
index 529cf3f..82a711f 100644
--- a/gateway-server/src/main/java/org/apache/knox/gateway/websockets/ProxyWebSocketAdapter.java
+++ b/gateway-server/src/main/java/org/apache/knox/gateway/websockets/ProxyWebSocketAdapter.java
@@ -42,9 +42,7 @@ import org.eclipse.jetty.websocket.api.WebSocketAdapter;
* @since 0.10
*/
public class ProxyWebSocketAdapter extends WebSocketAdapter {
-
- private static final WebsocketLogMessages LOG = MessagesFactory
- .get(WebsocketLogMessages.class);
+ private static final WebsocketLogMessages LOG = MessagesFactory.get(WebsocketLogMessages.class);
/* URI for the backend */
private final URI backend;
@@ -78,7 +76,6 @@ public class ProxyWebSocketAdapter extends WebSocketAdapter {
@Override
public void onWebSocketConnect(final Session frontEndSession) {
-
/*
* Let's connect to the backend, this is where the Backend-to-frontend
* plumbing takes place
@@ -109,9 +106,7 @@ public class ProxyWebSocketAdapter extends WebSocketAdapter {
}
@Override
- public void onWebSocketBinary(final byte[] payload, final int offset,
- final int length) {
-
+ public void onWebSocketBinary(final byte[] payload, final int offset, final int length) {
if (isNotConnected()) {
return;
}
@@ -122,7 +117,6 @@ public class ProxyWebSocketAdapter extends WebSocketAdapter {
@Override
public void onWebSocketText(final String message) {
-
if (isNotConnected()) {
return;
}
@@ -136,23 +130,13 @@ public class ProxyWebSocketAdapter extends WebSocketAdapter {
} catch (IOException e) {
LOG.connectionFailed(e);
}
-
}
@Override
public void onWebSocketClose(int statusCode, String reason) {
super.onWebSocketClose(statusCode, reason);
-
- /* do the cleaning business in seperate thread so we don't block */
- pool.execute(new Runnable() {
- @Override
- public void run() {
- closeQuietly();
- }
- });
-
+ cleanup();
LOG.onConnectionClose(backend.toString());
-
}
@Override
@@ -176,32 +160,21 @@ public class ProxyWebSocketAdapter extends WebSocketAdapter {
if(frontendSession != null && !frontendSession.isOpen()) {
frontendSession.close(StatusCode.SERVER_ERROR, t.getMessage());
}
-
- /* do the cleaning business in seperate thread so we don't block */
- pool.execute(new Runnable() {
- @Override
- public void run() {
- closeQuietly();
- }
- });
-
+ cleanup();
}
}
private MessageEventCallback getMessageCallback() {
-
return new MessageEventCallback() {
@Override
public void doCallback(String message) {
/* do nothing */
-
}
@Override
public void onConnectionOpen(Object session) {
/* do nothing */
-
}
@Override
@@ -210,17 +183,8 @@ public class ProxyWebSocketAdapter extends WebSocketAdapter {
frontendSession.close(reason.getCloseCode().getCode(),
reason.getReasonPhrase());
} finally {
-
- /* do the cleaning business in seperate thread so we don't block */
- pool.execute(new Runnable() {
- @Override
- public void run() {
- closeQuietly();
- }
- });
-
+ cleanup();
}
-
}
@Override
@@ -259,8 +223,18 @@ public class ProxyWebSocketAdapter extends WebSocketAdapter {
}
- private void closeQuietly() {
+ @SuppressWarnings("PMD.DoNotUseThreads")
+ private void cleanup() {
+ /* do the cleaning business in separate thread so we don't block */
+ pool.execute(new Runnable() {
+ @Override
+ public void run() {
+ closeQuietly();
+ }
+ });
+ }
+ private void closeQuietly() {
try {
if(backendSession != null && !backendSession.isOpen()) {
backendSession.close();
@@ -280,7 +254,5 @@ public class ProxyWebSocketAdapter extends WebSocketAdapter {
if(frontendSession != null && !frontendSession.isOpen()) {
frontendSession.close();
}
-
}
-
}
http://git-wip-us.apache.org/repos/asf/knox/blob/c2cbb345/gateway-util-common/src/main/java/org/apache/knox/gateway/audit/api/AuditServiceFactory.java
----------------------------------------------------------------------
diff --git a/gateway-util-common/src/main/java/org/apache/knox/gateway/audit/api/AuditServiceFactory.java b/gateway-util-common/src/main/java/org/apache/knox/gateway/audit/api/AuditServiceFactory.java
index 77e8f7b..ce91698 100644
--- a/gateway-util-common/src/main/java/org/apache/knox/gateway/audit/api/AuditServiceFactory.java
+++ b/gateway-util-common/src/main/java/org/apache/knox/gateway/audit/api/AuditServiceFactory.java
@@ -20,9 +20,8 @@ package org.apache.knox.gateway.audit.api;
import org.apache.knox.gateway.audit.log4j.audit.Log4jAuditService;
public abstract class AuditServiceFactory {
-
// The global audit service instance.
- private static AuditService auditService;
+ private static final AuditService auditService = new Log4jAuditService();
// To prevent instantiation.
private AuditServiceFactory() {
@@ -33,11 +32,6 @@ public abstract class AuditServiceFactory {
* @return The default audit service implementation. Will not be null.
*/
public static AuditService getAuditService() {
- // Race condition acceptable and will only result in multiple service instantiations.
- if( auditService == null ) {
- auditService = new Log4jAuditService();
- }
return auditService;
}
-
}
http://git-wip-us.apache.org/repos/asf/knox/blob/c2cbb345/gateway-util-common/src/main/java/org/apache/knox/gateway/audit/api/CorrelationServiceFactory.java
----------------------------------------------------------------------
diff --git a/gateway-util-common/src/main/java/org/apache/knox/gateway/audit/api/CorrelationServiceFactory.java b/gateway-util-common/src/main/java/org/apache/knox/gateway/audit/api/CorrelationServiceFactory.java
index a7e5dbd..ca1f389 100644
--- a/gateway-util-common/src/main/java/org/apache/knox/gateway/audit/api/CorrelationServiceFactory.java
+++ b/gateway-util-common/src/main/java/org/apache/knox/gateway/audit/api/CorrelationServiceFactory.java
@@ -19,11 +19,9 @@ package org.apache.knox.gateway.audit.api;
import org.apache.knox.gateway.audit.log4j.correlation.Log4jCorrelationService;
-
public abstract class CorrelationServiceFactory {
-
// The global correlation service instance.
- private static CorrelationService correlationService;
+ private static final CorrelationService correlationService = new Log4jCorrelationService();
// To prevent instantiation.
private CorrelationServiceFactory() {
@@ -34,11 +32,6 @@ public abstract class CorrelationServiceFactory {
* @return The default correlation service implementation. Will not be null.
*/
public static CorrelationService getCorrelationService() {
- // Race condition acceptable and will only result in multiple service instantiations.
- if( correlationService == null ) {
- correlationService = new Log4jCorrelationService();
- }
return correlationService;
}
-
}
http://git-wip-us.apache.org/repos/asf/knox/blob/c2cbb345/gateway-util-common/src/main/java/org/apache/knox/gateway/audit/log4j/appender/JdbmQueue.java
----------------------------------------------------------------------
diff --git a/gateway-util-common/src/main/java/org/apache/knox/gateway/audit/log4j/appender/JdbmQueue.java b/gateway-util-common/src/main/java/org/apache/knox/gateway/audit/log4j/appender/JdbmQueue.java
index eb0fbd1..a21136d 100644
--- a/gateway-util-common/src/main/java/org/apache/knox/gateway/audit/log4j/appender/JdbmQueue.java
+++ b/gateway-util-common/src/main/java/org/apache/knox/gateway/audit/log4j/appender/JdbmQueue.java
@@ -54,7 +54,7 @@ public class JdbmQueue<E> {
data.put( stat.lastEnqueue, e );
db.commit();
committed = true;
- notify();
+ notifyAll();
} finally {
if( !committed ) {
db.rollback();
http://git-wip-us.apache.org/repos/asf/knox/blob/c2cbb345/gateway-util-common/src/main/java/org/apache/knox/gateway/audit/log4j/appender/JdbmStoreAndForwardAppender.java
----------------------------------------------------------------------
diff --git a/gateway-util-common/src/main/java/org/apache/knox/gateway/audit/log4j/appender/JdbmStoreAndForwardAppender.java b/gateway-util-common/src/main/java/org/apache/knox/gateway/audit/log4j/appender/JdbmStoreAndForwardAppender.java
index 3aec64f..b3d445e 100644
--- a/gateway-util-common/src/main/java/org/apache/knox/gateway/audit/log4j/appender/JdbmStoreAndForwardAppender.java
+++ b/gateway-util-common/src/main/java/org/apache/knox/gateway/audit/log4j/appender/JdbmStoreAndForwardAppender.java
@@ -28,7 +28,7 @@ import org.apache.log4j.spi.LoggingEvent;
public class JdbmStoreAndForwardAppender extends AppenderSkeleton {
private File file;
- private Thread forwarder;
+ private Thread forwarder; //NOPMD - Expected use of threading
private JdbmQueue<LoggingEvent> queue;
private Logger forward;
private boolean fetchLocationInfo = true;
@@ -87,8 +87,8 @@ public class JdbmStoreAndForwardAppender extends AppenderSkeleton {
}
}
+ @SuppressWarnings("PMD.DoNotUseThreads")
private class Forwarder extends Thread {
-
@Override
public void run() {
final AtomicBoolean done = new AtomicBoolean( false );
@@ -118,5 +118,4 @@ public class JdbmStoreAndForwardAppender extends AppenderSkeleton {
}
}
}
-
}