You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@synapse.apache.org by hi...@apache.org on 2012/07/29 14:57:15 UTC
svn commit: r1366841 - in
/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse:
config/SynapseConfiguration.java endpoints/EndpointView.java
Author: hiranya
Date: Sun Jul 29 12:57:15 2012
New Revision: 1366841
URL: http://svn.apache.org/viewvc?rev=1366841&view=rev
Log:
Fixing a race condition in SynapseConfiguration and using a shared thread pool for running endpoint stat collector tasks
Modified:
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfiguration.java
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/EndpointView.java
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfiguration.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfiguration.java?rev=1366841&r1=1366840&r2=1366841&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfiguration.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfiguration.java Sun Jul 29 12:57:15 2012
@@ -739,10 +739,15 @@ public class SynapseConfiguration implem
if (o == null || o instanceof Entry) {
if (o == null) {
// this is not a local definition
- Entry entry = new Entry(key);
- entry.setType(Entry.REMOTE_ENTRY);
- addEntry(key, entry);
- return entry;
+ synchronized (this) {
+ o = localRegistry.get(key);
+ if (o == null) {
+ Entry entry = new Entry(key);
+ entry.setType(Entry.REMOTE_ENTRY);
+ addEntry(key, entry);
+ return entry;
+ }
+ }
}
return (Entry) o;
} else {
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/EndpointView.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/EndpointView.java?rev=1366841&r1=1366840&r2=1366841&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/EndpointView.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/EndpointView.java Sun Jul 29 12:57:15 2012
@@ -24,10 +24,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.util.*;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.ThreadFactory;
-import java.util.concurrent.TimeUnit;
+import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;
/**
@@ -36,7 +33,14 @@ import java.util.concurrent.atomic.Atomi
public class EndpointView implements EndpointViewMBean, MessageLevelMetricsCollector {
private static final Log log = LogFactory.getLog(EndpointView.class);
- private static final Long ONE = (long) 1;
+ private static final Long ONE = 1L;
+ private static final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(20,
+ new ThreadFactory() {
+ public Thread newThread(Runnable r) {
+ return new Thread(r, "endpoint-jmx-stat-collector");
+ }
+ }
+ );
/** The name of the endpoint */
private String endpointName = null;
@@ -79,7 +83,7 @@ public class EndpointView implements End
private long lastResetTime = System.currentTimeMillis();
- private ScheduledExecutorService scheduler;
+ private ScheduledFuture future;
private Queue<Integer> suspensionCounts = new LinkedList<Integer>();
private Queue<Integer> timeoutCounts = new LinkedList<Integer>();
@@ -93,13 +97,7 @@ public class EndpointView implements End
this.endpointName = endpointName;
this.endpoint = endpoint;
- scheduler = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() {
- public Thread newThread(Runnable r) {
- return new Thread(r, endpointName + "-endpoint-stat-collector");
- }
- });
-
- scheduler.scheduleAtFixedRate(new Runnable() {
+ this.future = scheduler.scheduleAtFixedRate(new Runnable() {
public void run() {
if (suspensionCounts.size() == 15) {
suspensionCounts.remove();
@@ -115,12 +113,12 @@ public class EndpointView implements End
}
public void destroy() {
- scheduler.shutdownNow();
+ future.cancel(true);
}
// --- endpoint control ---
/**
- * Switch on a leaf endpoint, or all endpoints on a group - from maintenence
+ * Switch on a leaf endpoint, or all endpoints on a group - from maintenance
* @throws Exception
*/
public void switchOn() throws Exception {
@@ -138,7 +136,7 @@ public class EndpointView implements End
}
/**
- * Switch off a leaf endpoint, or all endpoints of a group - for maintenence
+ * Switch off a leaf endpoint, or all endpoints of a group - for maintenance
*
* @throws Exception
*/
@@ -173,7 +171,7 @@ public class EndpointView implements End
/**
* Is this leaf level endpoint in timeout state? For a group, has all endpoints timed out?
- * @return true if a leaf level endpoint has timedout, For a group, has all endpoints timed out?
+ * @return true if a leaf level endpoint has timed out, For a group, has all endpoints timed out?
* @throws Exception
*/
public boolean isTimedout() throws Exception {
@@ -466,7 +464,7 @@ public class EndpointView implements End
/**
* Number of bytes received, receiving replies
- * @return # of byted received, receiving replies
+ * @return # of bytes received, receiving replies
*/
public long getBytesReceived() {
if (endpoint.getChildren() != null) {