diff options
author | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-11-11 01:32:09 +0000 |
---|---|---|
committer | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-11-11 01:32:09 +0000 |
commit | b7bdc4339cc4e9e23d105dad618d58958121444a (patch) | |
tree | be0863039b71fb0b05b3f647a0b644d88930a0aa | |
parent | 6c5398315a9b6657353643b170c0f452595dd1e6 (diff) |
Merge the performance fixes from 1.x
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@834737 13f79535-47bb-0310-9956-ffa450edef68
3 files changed, 30 insertions, 14 deletions
diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeWireImpl.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeWireImpl.java index 3284168aeb..f3f559a25e 100644 --- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeWireImpl.java +++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeWireImpl.java @@ -24,6 +24,8 @@ import java.security.AccessController; import java.security.PrivilegedAction; import java.util.ArrayList; 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; @@ -101,6 +103,8 @@ public class RuntimeWireImpl implements RuntimeWire { private RuntimeWireImpl clonedFrom; private List<InvocationChain> chains; + private transient final Map<Operation, InvocationChain> invocationChainMap = + new ConcurrentHashMap<Operation, InvocationChain>(); private InvocationChain bindingInvocationChain; private EndpointReferenceBinder eprBinder; @@ -185,18 +189,27 @@ public class RuntimeWireImpl implements RuntimeWire { } public InvocationChain getInvocationChain(Operation operation) { - for (InvocationChain chain : getInvocationChains()) { - Operation op = null; - if (isReferenceWire) { - op = chain.getSourceOperation(); - } else { - op = chain.getTargetOperation(); - } - if (interfaceContractMapper.isCompatible(operation, op, op.getInterface().isRemotable())) { - return chain; + InvocationChain cached = invocationChainMap.get(operation); + if (cached == null) { + for (InvocationChain chain : getInvocationChains()) { + Operation op = null; + if (isReferenceWire) { + // 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; + } } + invocationChainMap.put(operation, null); + return null; + } else { + return cached; } - return null; } public Object invoke(Message msg) throws InvocationTargetException { diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKInvocationHandler.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKInvocationHandler.java index 148749922e..cfe572ee42 100644 --- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKInvocationHandler.java +++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKInvocationHandler.java @@ -23,7 +23,7 @@ import java.io.Serializable; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Proxy; -import java.util.HashMap; +import java.util.IdentityHashMap; import java.util.List; import java.util.Map; @@ -41,7 +41,6 @@ import org.apache.tuscany.sca.invocation.Invoker; import org.apache.tuscany.sca.invocation.Message; import org.apache.tuscany.sca.invocation.MessageFactory; import org.apache.tuscany.sca.runtime.RuntimeWire; -import org.oasisopen.sca.SCARuntimeException; import org.oasisopen.sca.ServiceReference; import org.oasisopen.sca.ServiceRuntimeException; @@ -61,7 +60,7 @@ public class JDKInvocationHandler implements InvocationHandler, Serializable { protected boolean fixedWire = true; - protected transient Map<Method, InvocationChain> chains = new HashMap<Method, InvocationChain>(); + protected transient Map<Method, InvocationChain> chains = new IdentityHashMap<Method, InvocationChain>(); public JDKInvocationHandler(MessageFactory messageFactory, Class<?> businessInterface, RuntimeWire wire) { this.messageFactory = messageFactory; diff --git a/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaComponentContextProvider.java b/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaComponentContextProvider.java index 6929b5d0ca..c398c3af04 100644 --- a/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaComponentContextProvider.java +++ b/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaComponentContextProvider.java @@ -52,6 +52,7 @@ import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; import org.apache.tuscany.sca.implementation.java.JavaConstructorImpl; import org.apache.tuscany.sca.implementation.java.JavaElementImpl; import org.apache.tuscany.sca.implementation.java.JavaResourceImpl; +import org.apache.tuscany.sca.implementation.java.context.InstanceFactory; import org.apache.tuscany.sca.implementation.java.injection.JavaPropertyValueObjectFactory; import org.apache.tuscany.sca.implementation.java.introspect.JavaIntrospectionHelper; import org.apache.tuscany.sca.interfacedef.Operation; @@ -72,6 +73,7 @@ public class JavaComponentContextProvider { private RuntimeComponent component; private JavaInstanceFactoryProvider<?> instanceFactoryProvider; private ProxyFactory proxyFactory; + private InstanceFactory instanceFactory; public JavaComponentContextProvider(RuntimeComponent component, JavaInstanceFactoryProvider configuration, @@ -92,7 +94,7 @@ public class JavaComponentContextProvider { } InstanceWrapper<?> createInstanceWrapper() throws ObjectCreationException { - return instanceFactoryProvider.createFactory().newInstance(); + return instanceFactory.newInstance(); } void configureProperties(List<ComponentProperty> definedProperties) { @@ -259,6 +261,8 @@ public class JavaComponentContextProvider { } //setUpPolicyHandlers(); + this.instanceFactory = instanceFactoryProvider.createFactory(); + } void addResourceFactory(String name, ObjectFactory<?> factory) { |