diff options
author | antelder <antelder@13f79535-47bb-0310-9956-ffa450edef68> | 2010-04-09 12:35:22 +0000 |
---|---|---|
committer | antelder <antelder@13f79535-47bb-0310-9956-ffa450edef68> | 2010-04-09 12:35:22 +0000 |
commit | 4910dda543a66c96f4fabe11bfd3fc45b0aa7c0b (patch) | |
tree | 3c3ce5f94fb20dfc88d9c7a856be83ba26e286c9 /sca-java-2.x/trunk/modules | |
parent | 551f6edf58b574ab5e12207b7c44433514415354 (diff) |
Synchronize shutdown to avoid exceptions when things happen concurently
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@932387 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules')
-rw-r--r-- | sca-java-2.x/trunk/modules/endpoint-hazelcast/src/main/java/org/apache/tuscany/sca/endpoint/hazelcast/HazelcastEndpointRegistry.java | 62 |
1 files changed, 36 insertions, 26 deletions
diff --git a/sca-java-2.x/trunk/modules/endpoint-hazelcast/src/main/java/org/apache/tuscany/sca/endpoint/hazelcast/HazelcastEndpointRegistry.java b/sca-java-2.x/trunk/modules/endpoint-hazelcast/src/main/java/org/apache/tuscany/sca/endpoint/hazelcast/HazelcastEndpointRegistry.java index d0a1f0350e..2e2168aecd 100644 --- a/sca-java-2.x/trunk/modules/endpoint-hazelcast/src/main/java/org/apache/tuscany/sca/endpoint/hazelcast/HazelcastEndpointRegistry.java +++ b/sca-java-2.x/trunk/modules/endpoint-hazelcast/src/main/java/org/apache/tuscany/sca/endpoint/hazelcast/HazelcastEndpointRegistry.java @@ -69,6 +69,7 @@ public class HazelcastEndpointRegistry extends BaseEndpointRegistry implements E private Map<String, Endpoint> localEndpoints = new ConcurrentHashMap<String, Endpoint>();
protected MultiMap<String, String> endpointOwners;
private AssemblyFactory assemblyFactory;
+ private Object shutdownMutex = new Object();
public HazelcastEndpointRegistry(ExtensionPointRegistry registry,
Map<String, String> attributes,
@@ -103,10 +104,12 @@ public class HazelcastEndpointRegistry extends BaseEndpointRegistry implements E public void stop() {
if (hazelcastInstance != null) {
- hazelcastInstance.shutdown();
- hazelcastInstance = null;
- endpointMap = null;
- endpointOwners = null;
+ synchronized (shutdownMutex) {
+ hazelcastInstance.shutdown();
+ hazelcastInstance = null;
+ endpointMap = null;
+ endpointOwners = null;
+ }
}
}
@@ -215,20 +218,25 @@ public class HazelcastEndpointRegistry extends BaseEndpointRegistry implements E }
public void removeEndpoint(Endpoint endpoint) {
- String localMemberAddr = hazelcastInstance.getCluster().getLocalMember().getInetSocketAddress().toString();
- String endpointURI = endpoint.getURI();
- Transaction txn = hazelcastInstance.getTransaction();
- txn.begin();
- try {
- endpointMap.remove(endpointURI);
- endpointOwners.remove(localMemberAddr, endpointURI);
- txn.commit();
- } catch (Throwable e) {
- txn.rollback();
- throw new ServiceRuntimeException(e);
+ if (hazelcastInstance == null) {
+ return;
+ }
+ synchronized (shutdownMutex) {
+ String localMemberAddr = hazelcastInstance.getCluster().getLocalMember().getInetSocketAddress().toString();
+ String endpointURI = endpoint.getURI();
+ Transaction txn = hazelcastInstance.getTransaction();
+ txn.begin();
+ try {
+ endpointMap.remove(endpointURI);
+ endpointOwners.remove(localMemberAddr, endpointURI);
+ txn.commit();
+ } catch (Throwable e) {
+ txn.rollback();
+ throw new ServiceRuntimeException(e);
+ }
+ localEndpoints.remove(endpointURI);
+ logger.info("Removed endpoint - " + endpoint);
}
- localEndpoints.remove(endpointURI);
- logger.info("Removed endpoint - " + endpoint);
}
@@ -280,17 +288,19 @@ public class HazelcastEndpointRegistry extends BaseEndpointRegistry implements E try {
String memberAddr = event.getMember().getInetSocketAddress().toString();
if (endpointOwners.containsKey(memberAddr)) {
- ILock lock = hazelcastInstance.getLock("EndpointOwners/" + memberAddr);
- lock.lock();
- try {
- if (endpointOwners.containsKey(memberAddr)) {
- Collection<String> keys = endpointOwners.remove(memberAddr);
- for (Object k : keys) {
- endpointMap.remove(k);
+ synchronized (shutdownMutex) {
+ ILock lock = hazelcastInstance.getLock("EndpointOwners/" + memberAddr);
+ lock.lock();
+ try {
+ if (endpointOwners.containsKey(memberAddr)) {
+ Collection<String> keys = endpointOwners.remove(memberAddr);
+ for (Object k : keys) {
+ endpointMap.remove(k);
+ }
}
+ } finally {
+ lock.unlock();
}
- } finally {
- lock.unlock();
}
}
} catch (Exception e) {
|