summaryrefslogtreecommitdiffstats
path: root/branches/sca-java-1.x
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-11-09 19:09:33 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-11-09 19:09:33 +0000
commit8be9672804ac30d0681bae0043dfcfa06c19f71b (patch)
tree7d1365768f136a15b6aaebf9d0293959e2bc742d /branches/sca-java-1.x
parentc49cf55e3f8fd2da4c89ec708bee69ab8bd13306 (diff)
Turn the IdentityHashMap into a ConcurrentHashMap to avoid expensive synchronizations
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@834176 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'branches/sca-java-1.x')
-rw-r--r--branches/sca-java-1.x/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeWireImpl.java47
1 files changed, 23 insertions, 24 deletions
diff --git a/branches/sca-java-1.x/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeWireImpl.java b/branches/sca-java-1.x/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeWireImpl.java
index cc71374296..4a90d47fa9 100644
--- a/branches/sca-java-1.x/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeWireImpl.java
+++ b/branches/sca-java-1.x/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeWireImpl.java
@@ -21,9 +21,9 @@ package org.apache.tuscany.sca.core.assembly;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
-import java.util.IdentityHashMap;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
import org.apache.tuscany.sca.assembly.Binding;
import org.apache.tuscany.sca.assembly.Component;
@@ -82,8 +82,8 @@ public class RuntimeWireImpl implements RuntimeWire {
private List<InvocationChain> chains;
private InvocationChain bindingInvocationChain;
// Cache
- private transient final Map<Operation, InvocationChain> invocationChainMap =
- new IdentityHashMap<Operation, InvocationChain>();
+ private transient final Map<Integer, InvocationChain> invocationChainMap =
+ new ConcurrentHashMap<Integer, InvocationChain>();
/**
@@ -135,29 +135,28 @@ public class RuntimeWireImpl implements RuntimeWire {
}
public InvocationChain getInvocationChain(Operation operation) {
- synchronized (invocationChainMap) {
- InvocationChain cached = invocationChainMap.get(operation);
- if (cached == null) {
- for (InvocationChain chain : getInvocationChains()) {
- Operation op = null;
- if (wireSource.getContract() != null) {
- // Reference chain
- op = chain.getSourceOperation();
- } else {
- // Service chain
- op = chain.getTargetOperation();
- }
- if (interfaceContractMapper.isCompatible(operation, op, op.getInterface().isRemotable())) {
- invocationChainMap.put(operation, chain);
- return chain;
- }
+ Integer id = operation == null ? new Integer(0) : new Integer(System.identityHashCode(operation));
+ InvocationChain cached = invocationChainMap.get(id);
+ if (cached == null) {
+ for (InvocationChain chain : getInvocationChains()) {
+ Operation op = null;
+ if (wireSource.getContract() != null) {
+ // Reference chain
+ op = chain.getSourceOperation();
+ } else {
+ // Service chain
+ op = chain.getTargetOperation();
+ }
+ if (interfaceContractMapper.isCompatible(operation, op, op.getInterface().isRemotable())) {
+ invocationChainMap.put(id, chain);
+ return chain;
}
- invocationChainMap.put(operation, null);
- return null;
-
- } else {
- return cached;
}
+ invocationChainMap.put(id, null);
+ return null;
+
+ } else {
+ return cached;
}
}