You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by jm...@apache.org on 2006/11/24 06:34:39 UTC
svn commit: r478773 - in /incubator/tuscany/java/sca/kernel:
core/src/main/java/org/apache/tuscany/core/component/
core/src/main/java/org/apache/tuscany/core/wire/jdk/
core/src/test/java/org/apache/tuscany/core/implementation/java/
core/src/test/java/o...
Author: jmarino
Date: Thu Nov 23 21:34:26 2006
New Revision: 478773
URL: http://svn.apache.org/viewvc?view=rev&rev=478773
Log:
make JDK invocation handlers serializable
Added:
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/WireUtils.java (with props)
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandlerSerializationTestCase.java (with props)
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInboundInvocationHandlerSerializationTestCase.java (with props)
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKOutboundInvocationHandlerSerializationTestCase.java (with props)
incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/ReactivationException.java (with props)
incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/SCAExternalizable.java (with props)
Modified:
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/component/WorkContextImpl.java
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandler.java
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKInboundInvocationHandler.java
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKOutboundInvocationHandler.java
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKWireService.java
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/GetServiceByNameTestCase.java
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/InboundInvocationErrorTestCase.java
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandlerTestCase.java
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInboundInvocationHandlerTestCase.java
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKOutboundInvocationHandlerTestCase.java
incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/component/WorkContext.java
incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/WireInvocationHandler.java
incubator/tuscany/java/sca/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/TargetInvokerExtensionTestCase.java
incubator/tuscany/java/sca/kernel/spi/src/test/java/org/apache/tuscany/spi/wire/AbstractOutboundInvocationHandlerTestCase.java
Modified: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/component/WorkContextImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/component/WorkContextImpl.java?view=diff&rev=478773&r1=478772&r2=478773
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/component/WorkContextImpl.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/component/WorkContextImpl.java Thu Nov 23 21:34:26 2006
@@ -61,12 +61,12 @@
map.put(CORRELATION_ID, correlationId);
}
- public Object getCurrentAtomicComponent() {
+ public AtomicComponent getCurrentAtomicComponent() {
Map<Object, Object> map = workContext.get();
if (map == null) {
return null;
}
- return map.get(CURRENT_ATOMIC);
+ return (AtomicComponent) map.get(CURRENT_ATOMIC);
}
public void setCurrentAtomicComponent(AtomicComponent component) {
Modified: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandler.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandler.java?view=diff&rev=478773&r1=478772&r2=478773
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandler.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandler.java Thu Nov 23 21:34:26 2006
@@ -18,12 +18,19 @@
*/
package org.apache.tuscany.core.wire.jdk;
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.LinkedList;
import java.util.Map;
+import org.apache.tuscany.spi.ReactivationException;
+import org.apache.tuscany.spi.SCAExternalizable;
import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.component.AtomicComponent;
import static org.apache.tuscany.spi.idl.java.JavaIDLUtils.findOperation;
import org.apache.tuscany.spi.model.Operation;
import org.apache.tuscany.spi.wire.AbstractOutboundInvocationHandler;
@@ -42,14 +49,21 @@
* @version $Rev$ $Date$
*/
public class JDKCallbackInvocationHandler extends AbstractOutboundInvocationHandler
- implements WireInvocationHandler, InvocationHandler {
-
+ implements WireInvocationHandler, InvocationHandler, Externalizable, SCAExternalizable {
private transient WorkContext context;
- private transient InboundWire inboundWire;
+ private transient InboundWire wire;
+ private String serviceName;
+
+ /**
+ * Constructor used for deserialization only
+ */
+ public JDKCallbackInvocationHandler() {
+ }
- public JDKCallbackInvocationHandler(WorkContext context, InboundWire inboundWire) {
+ public JDKCallbackInvocationHandler(InboundWire wire, WorkContext context) {
this.context = context;
- this.inboundWire = inboundWire;
+ this.wire = wire;
+ this.serviceName = wire.getServiceName();
}
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
@@ -77,7 +91,7 @@
}
//TODO optimize as this is slow in local invocations
Map<Operation<?>, OutboundInvocationChain> sourceCallbackInvocationChains =
- inboundWire.getSourceCallbackInvocationChains(targetAddress);
+ wire.getSourceCallbackInvocationChains(targetAddress);
Operation operation = findOperation(method, sourceCallbackInvocationChains.keySet());
OutboundInvocationChain chain = sourceCallbackInvocationChains.get(operation);
TargetInvoker invoker = chain.getTargetInvoker();
@@ -87,5 +101,25 @@
public Object invoke(Method method, Object[] args) throws Throwable {
return invoke(null, method, args);
+ }
+
+ public void writeExternal(ObjectOutput out) throws IOException {
+ out.writeObject(serviceName);
+ }
+
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ serviceName = (String) in.readObject();
+ }
+
+ public void setWorkContext(WorkContext context) {
+ this.context = context;
+ }
+
+ public void reactivate() throws ReactivationException {
+ AtomicComponent owner = context.getCurrentAtomicComponent();
+ if (owner == null) {
+ throw new ReactivationException("Current atomic component not set on work context");
+ }
+ wire = owner.getInboundWires().get(serviceName);
}
}
Modified: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKInboundInvocationHandler.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKInboundInvocationHandler.java?view=diff&rev=478773&r1=478772&r2=478773
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKInboundInvocationHandler.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKInboundInvocationHandler.java Thu Nov 23 21:34:26 2006
@@ -18,15 +18,23 @@
*/
package org.apache.tuscany.core.wire.jdk;
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
+import org.apache.tuscany.spi.ReactivationException;
+import org.apache.tuscany.spi.SCAExternalizable;
+import org.apache.tuscany.spi.component.AtomicComponent;
import org.apache.tuscany.spi.component.TargetException;
import org.apache.tuscany.spi.component.WorkContext;
import org.apache.tuscany.spi.wire.AbstractInboundInvocationHandler;
import org.apache.tuscany.spi.wire.InboundInvocationChain;
+import org.apache.tuscany.spi.wire.InboundWire;
import org.apache.tuscany.spi.wire.TargetInvoker;
import org.apache.tuscany.spi.wire.WireInvocationHandler;
@@ -37,8 +45,8 @@
*
* @version $Rev$ $Date$
*/
-public class JDKInboundInvocationHandler extends AbstractInboundInvocationHandler
- implements WireInvocationHandler, InvocationHandler {
+public final class JDKInboundInvocationHandler extends AbstractInboundInvocationHandler
+ implements WireInvocationHandler, InvocationHandler, Externalizable, SCAExternalizable {
private static final long serialVersionUID = -307902641125881043L;
/*
@@ -48,14 +56,23 @@
* to a target of greater scope since the target reference can be maintained by the invoker. When a target invoker
* is not cacheable, the master associated with the wire chains will be used.
*/
- private Map<Method, ChainHolder> chains;
- private WorkContext context;
+ private transient Map<Method, ChainHolder> chains;
+ private transient WorkContext context;
+ private String serviceName;
- public JDKInboundInvocationHandler(Map<Method, InboundInvocationChain> invocationChains, WorkContext context) {
- this.chains = new HashMap<Method, ChainHolder>(invocationChains.size());
- for (Map.Entry<Method, InboundInvocationChain> entry : invocationChains.entrySet()) {
- this.chains.put(entry.getKey(), new ChainHolder(entry.getValue()));
- }
+ /**
+ * Constructor used for deserialization only
+ */
+ public JDKInboundInvocationHandler() {
+ }
+
+ public JDKInboundInvocationHandler(InboundWire wire, WorkContext context) {
+ this.context = context;
+ this.serviceName = wire.getServiceName();
+ init(wire);
+ }
+
+ public void setWorkContext(WorkContext context) {
this.context = context;
}
@@ -109,7 +126,33 @@
return invoke(null, method, args);
}
+ public void writeExternal(ObjectOutput out) throws IOException {
+ out.writeObject(serviceName);
+ }
+
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ serviceName = (String) in.readObject();
+ }
+
+ public void reactivate() throws ReactivationException {
+ // TODO this method will be extremely slow - look to optimize
+ AtomicComponent owner = context.getCurrentAtomicComponent();
+ if (owner == null) {
+ throw new ReactivationException("Current atomic component not set on work context");
+ }
+ InboundWire wire = owner.getInboundWires().get(serviceName);
+ init(wire);
+ }
+ private void init(InboundWire wire) {
+ this.chains = new HashMap<Method, ChainHolder>();
+ Class<?> interfaze = wire.getServiceContract().getInterfaceClass();
+ Method[] methods = interfaze.getMethods();
+ Map<Method, InboundInvocationChain> invocationChains = WireUtils.createInboundMapping(wire, methods);
+ for (Map.Entry<Method, InboundInvocationChain> entry : invocationChains.entrySet()) {
+ this.chains.put(entry.getKey(), new ChainHolder(entry.getValue()));
+ }
+ }
/**
* A holder used to associate an wire chain with a local copy of a target invoker that was previously cloned from
Modified: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKOutboundInvocationHandler.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKOutboundInvocationHandler.java?view=diff&rev=478773&r1=478772&r2=478773
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKOutboundInvocationHandler.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKOutboundInvocationHandler.java Thu Nov 23 21:34:26 2006
@@ -18,18 +18,28 @@
*/
package org.apache.tuscany.core.wire.jdk;
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
+import org.apache.tuscany.spi.ReactivationException;
+import org.apache.tuscany.spi.SCAExternalizable;
+import org.apache.tuscany.spi.component.AtomicComponent;
import org.apache.tuscany.spi.component.TargetException;
import org.apache.tuscany.spi.component.WorkContext;
import static org.apache.tuscany.spi.idl.java.JavaIDLUtils.findMethod;
-import org.apache.tuscany.spi.model.InteractionScope;
+import static org.apache.tuscany.spi.model.InteractionScope.CONVERSATIONAL;
import org.apache.tuscany.spi.model.Operation;
import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.model.ServiceContract;
import org.apache.tuscany.spi.wire.AbstractOutboundInvocationHandler;
+import org.apache.tuscany.spi.wire.MessageId;
import org.apache.tuscany.spi.wire.OutboundInvocationChain;
import org.apache.tuscany.spi.wire.OutboundWire;
import org.apache.tuscany.spi.wire.TargetInvoker;
@@ -42,8 +52,9 @@
*
* @version $Rev$ $Date$
*/
-public class JDKOutboundInvocationHandler extends AbstractOutboundInvocationHandler
- implements WireInvocationHandler, InvocationHandler {
+public final class JDKOutboundInvocationHandler extends AbstractOutboundInvocationHandler
+ implements WireInvocationHandler, InvocationHandler, Externalizable, SCAExternalizable {
+ private static final long serialVersionUID = -6155278451964527325L;
/*
* an association of an operation to chain holder. The holder contains an invocation chain
@@ -52,41 +63,31 @@
* to a target of greater scope since the target reference can be maintained by the invoker. When a target invoker
* is not cacheable, the master associated with the wire chains will be used.
*/
- private Map<Method, ChainHolder> chains;
- private Object fromAddress;
- private boolean contractHasCallback;
- private boolean contractIsRemotable;
- private boolean contractIsConversational;
- private Object convIdForRemotableTarget;
- private Object convIdFromThread;
+ private transient Map<Method, ChainHolder> chains;
+ private transient WorkContext workContext;
+ private transient Object fromAddress;
+ private transient boolean contractHasCallback;
+ private transient boolean contractIsRemotable;
+ private transient boolean contractIsConversational;
+ private transient Object convIdForRemotableTarget;
+ private transient Object convIdFromThread;
+ private String referenceName;
- private WorkContext workContext;
+ /**
+ * Constructor used for deserialization only
+ */
+ public JDKOutboundInvocationHandler() {
+ }
public JDKOutboundInvocationHandler(OutboundWire wire) {
this(wire, null);
+ referenceName = wire.getReferenceName();
}
public JDKOutboundInvocationHandler(OutboundWire wire, WorkContext workContext)
throws NoMethodForOperationException {
- Map<Operation<?>, OutboundInvocationChain> invocationChains = wire.getInvocationChains();
- this.chains = new HashMap<Method, ChainHolder>(invocationChains.size());
- this.fromAddress = (wire.getContainer() == null) ? null : wire.getContainer().getName();
- Method[] methods = wire.getServiceContract().getInterfaceClass().getMethods();
- this.contractHasCallback = wire.getServiceContract().getCallbackClass() != null;
- // TODO optimize this
- for (Map.Entry<Operation<?>, OutboundInvocationChain> entry : invocationChains.entrySet()) {
- Operation operation = entry.getKey();
- Method method = findMethod(operation, methods);
- if (method == null) {
- throw new NoMethodForOperationException(operation.getName());
- }
- this.chains.put(method, new ChainHolder(entry.getValue()));
- }
-
this.workContext = workContext;
- this.contractIsConversational =
- wire.getServiceContract().getInteractionScope().equals(InteractionScope.CONVERSATIONAL);
- this.contractIsRemotable = wire.getServiceContract().isRemotable();
+ init(wire);
}
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
@@ -135,12 +136,12 @@
convIdFromThread = workContext.getIdentifier(Scope.CONVERSATIONAL);
if (contractIsRemotable) {
if (convIdForRemotableTarget == null) {
- convIdForRemotableTarget = new org.apache.tuscany.spi.wire.MessageId();
+ convIdForRemotableTarget = new MessageId();
}
// Always use the conv id for this target
workContext.setIdentifier(Scope.CONVERSATIONAL, convIdForRemotableTarget);
} else if (convIdFromThread == null) {
- Object newConvId = new org.apache.tuscany.spi.wire.MessageId();
+ Object newConvId = new MessageId();
workContext.setIdentifier(Scope.CONVERSATIONAL, newConvId);
}
}
@@ -161,6 +162,60 @@
protected Object getFromAddress() {
return contractHasCallback ? fromAddress : null;
+ }
+
+ public void setWorkContext(WorkContext context) {
+ workContext = context;
+ }
+
+ public void writeExternal(ObjectOutput out) throws IOException {
+ out.writeObject(referenceName);
+ }
+
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ referenceName = (String) in.readObject();
+ }
+
+ public void reactivate() throws ReactivationException {
+ AtomicComponent owner = workContext.getCurrentAtomicComponent();
+ if (owner == null) {
+ throw new ReactivationException("Current atomic component not set on work context");
+ }
+ List<OutboundWire> wires = owner.getOutboundWires().get(referenceName);
+ if (wires == null) {
+ ReactivationException e = new ReactivationException("Reference wire not found");
+ e.setIdentifier(referenceName);
+ e.addContextName(owner.getName());
+ throw e;
+ }
+ // TODO handle multiplicity
+ OutboundWire wire = wires.get(0);
+ try {
+ init(wire);
+ } catch (NoMethodForOperationException e) {
+ throw new ReactivationException(e);
+ }
+ }
+
+ private void init(OutboundWire wire) {
+ ServiceContract contract = wire.getServiceContract();
+ this.referenceName = wire.getReferenceName();
+ this.fromAddress = (wire.getContainer() == null) ? null : wire.getContainer().getName();
+ this.contractIsConversational = contract.getInteractionScope().equals(CONVERSATIONAL);
+ this.contractIsRemotable = contract.isRemotable();
+ this.contractHasCallback = contract.getCallbackClass() != null;
+ Map<Operation<?>, OutboundInvocationChain> invocationChains = wire.getInvocationChains();
+ this.chains = new HashMap<Method, ChainHolder>(invocationChains.size());
+ // TODO optimize this
+ Method[] methods = contract.getInterfaceClass().getMethods();
+ for (Map.Entry<Operation<?>, OutboundInvocationChain> entry : invocationChains.entrySet()) {
+ Operation operation = entry.getKey();
+ Method method = findMethod(operation, methods);
+ if (method == null) {
+ throw new NoMethodForOperationException(operation.getName());
+ }
+ this.chains.put(method, new ChainHolder(entry.getValue()));
+ }
}
/**
Modified: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKWireService.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKWireService.java?view=diff&rev=478773&r1=478772&r2=478773
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKWireService.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKWireService.java Thu Nov 23 21:34:26 2006
@@ -18,9 +18,7 @@
*/
package org.apache.tuscany.core.wire.jdk;
-import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
-import java.util.HashMap;
import java.util.Map;
import org.osoa.sca.annotations.Constructor;
@@ -35,7 +33,6 @@
import org.apache.tuscany.spi.component.ReferenceNotFoundException;
import org.apache.tuscany.spi.component.Service;
import org.apache.tuscany.spi.component.WorkContext;
-import static org.apache.tuscany.spi.idl.java.JavaIDLUtils.findMethod;
import org.apache.tuscany.spi.model.ComponentDefinition;
import org.apache.tuscany.spi.model.ComponentType;
import org.apache.tuscany.spi.model.CompositeComponentType;
@@ -89,9 +86,7 @@
if (wire instanceof InboundWire) {
InboundWire inbound = (InboundWire) wire;
Class<?> interfaze = wire.getServiceContract().getInterfaceClass();
- Method[] methods = interfaze.getMethods();
- Map<Method, InboundInvocationChain> chains = createInboundMapping(inbound, methods);
- JDKInboundInvocationHandler handler = new JDKInboundInvocationHandler(chains, context);
+ JDKInboundInvocationHandler handler = new JDKInboundInvocationHandler(inbound, context);
ClassLoader cl = interfaze.getClassLoader();
//FIXME
return Proxy.newProxyInstance(cl, new Class[]{interfaze}, handler);
@@ -111,7 +106,7 @@
public Object createCallbackProxy(ServiceContract<?> contract, InboundWire wire) throws ProxyCreationException {
Class<?> interfaze = contract.getCallbackClass();
ClassLoader cl = interfaze.getClassLoader();
- JDKCallbackInvocationHandler handler = new JDKCallbackInvocationHandler(context, wire);
+ JDKCallbackInvocationHandler handler = new JDKCallbackInvocationHandler(wire, context);
return interfaze.cast(Proxy.newProxyInstance(cl, new Class[]{interfaze}, handler));
}
@@ -119,9 +114,7 @@
assert wire != null : "Wire was null";
if (wire instanceof InboundWire) {
InboundWire inbound = (InboundWire) wire;
- Method[] methods = inbound.getServiceContract().getInterfaceClass().getMethods();
- Map<Method, InboundInvocationChain> chains = createInboundMapping(inbound, methods);
- return new JDKInboundInvocationHandler(chains, context);
+ return new JDKInboundInvocationHandler(inbound, context);
} else if (wire instanceof OutboundWire) {
OutboundWire outbound = (OutboundWire) wire;
return new JDKOutboundInvocationHandler(outbound, context);
@@ -133,7 +126,7 @@
}
public WireInvocationHandler createCallbackHandler(InboundWire wire) {
- return new JDKCallbackInvocationHandler(context, wire);
+ return new JDKCallbackInvocationHandler(wire, context);
}
public OutboundInvocationChain createOutboundChain(Operation<?> operation) {
@@ -321,21 +314,5 @@
service.setOutboundWire(outboundWire);
}
-
- private Map<Method, InboundInvocationChain> createInboundMapping(InboundWire wire, Method[] methods)
- throws NoMethodForOperationException {
- Map<Method, InboundInvocationChain> chains = new HashMap<Method, InboundInvocationChain>();
- for (Map.Entry<Operation<?>, InboundInvocationChain> entry : wire.getInvocationChains().entrySet()) {
- Operation<?> operation = entry.getKey();
- InboundInvocationChain chain = entry.getValue();
- Method method = findMethod(operation, methods);
- if (method == null) {
- NoMethodForOperationException e = new NoMethodForOperationException();
- e.setIdentifier(operation.getName());
- }
- chains.put(method, chain);
- }
- return chains;
- }
}
Added: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/WireUtils.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/WireUtils.java?view=auto&rev=478773
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/WireUtils.java (added)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/WireUtils.java Thu Nov 23 21:34:26 2006
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.wire.jdk;
+
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.apache.tuscany.spi.idl.java.JavaIDLUtils.findMethod;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.wire.InboundInvocationChain;
+import org.apache.tuscany.spi.wire.InboundWire;
+
+/**
+ * Utilities for operating on wires
+ *
+ * @version $Rev$ $Date$
+ */
+public final class WireUtils {
+
+ private WireUtils() {
+ }
+
+ /**
+ * Maps invocation chains on a wire to corresponding methods
+ *
+ * @param wire the wire containing the invocation chains to map
+ * @param methods the methods to map to
+ * @return a collection containing the method to invocation chain mapping
+ * @throws NoMethodForOperationException
+ */
+ public static Map<Method, InboundInvocationChain> createInboundMapping(InboundWire wire, Method[] methods)
+ throws NoMethodForOperationException {
+ Map<Method, InboundInvocationChain> chains = new HashMap<Method, InboundInvocationChain>();
+ for (Map.Entry<Operation<?>, InboundInvocationChain> entry : wire.getInvocationChains().entrySet()) {
+ Operation<?> operation = entry.getKey();
+ InboundInvocationChain chain = entry.getValue();
+ Method method = findMethod(operation, methods);
+ if (method == null) {
+ NoMethodForOperationException e = new NoMethodForOperationException();
+ e.setIdentifier(operation.getName());
+ }
+ chains.put(method, chain);
+ }
+ return chains;
+ }
+}
Propchange: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/WireUtils.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/WireUtils.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/GetServiceByNameTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/GetServiceByNameTestCase.java?view=diff&rev=478773&r1=478772&r2=478773
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/GetServiceByNameTestCase.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/GetServiceByNameTestCase.java Thu Nov 23 21:34:26 2006
@@ -61,7 +61,7 @@
JavaServiceContract contract = new JavaServiceContract(Target.class);
EasyMock.expect(wire.getServiceContract()).andReturn(contract).anyTimes();
- expect(wire.getServiceName()).andReturn("Target");
+ expect(wire.getServiceName()).andReturn("Target").atLeastOnce();
Map<Operation<?>, InboundInvocationChain> chains = new HashMap<Operation<?>, InboundInvocationChain>();
expect(wire.getInvocationChains()).andReturn(chains);
expect(wire.getCallbackReferenceName()).andReturn(null);
Modified: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/InboundInvocationErrorTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/InboundInvocationErrorTestCase.java?view=diff&rev=478773&r1=478772&r2=478773
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/InboundInvocationErrorTestCase.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/InboundInvocationErrorTestCase.java Thu Nov 23 21:34:26 2006
@@ -20,6 +20,7 @@
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
+import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.Map;
@@ -29,9 +30,9 @@
import org.apache.tuscany.spi.model.Operation;
import org.apache.tuscany.spi.model.ServiceContract;
import org.apache.tuscany.spi.wire.InboundInvocationChain;
+import org.apache.tuscany.spi.wire.InboundWire;
import junit.framework.TestCase;
-
import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
import org.apache.tuscany.core.mock.wire.MockStaticInvoker;
import org.apache.tuscany.core.mock.wire.MockSyncInterceptor;
@@ -44,7 +45,6 @@
* @version $Rev$ $Date$
*/
public class InboundInvocationErrorTestCase extends TestCase {
-
private Method checkedMethod;
private Method runtimeMethod;
private Operation checkedOperation;
@@ -79,15 +79,21 @@
}
public void testCheckedException() throws Exception {
- Map<Method, InboundInvocationChain> chains = new HashMap<Method, InboundInvocationChain>();
- chains.put(checkedMethod, createChain(checkedMethod, checkedOperation));
WorkContext workContext = EasyMock.createNiceMock(WorkContext.class);
EasyMock.replay(workContext);
- JDKInboundInvocationHandler handler = new JDKInboundInvocationHandler(chains, workContext);
+
+ Operation<Type> operation = new Operation<Type>("checkedException", null, null, null, false, null);
+ Map<Operation<?>, InboundInvocationChain> chains = new HashMap<Operation<?>, InboundInvocationChain>();
+ chains.put(operation, createChain(checkedMethod, checkedOperation));
+ InboundWire wire = new InboundWireImpl();
+ wire.addInvocationChains(chains);
+ wire.setServiceContract(new ServiceContract<TestBean>(TestBean.class) {
+ });
+
+ JDKInboundInvocationHandler handler = new JDKInboundInvocationHandler(wire, workContext);
try {
- InboundInvocationErrorTestCase.TestBean proxy = (InboundInvocationErrorTestCase.TestBean) Proxy
- .newProxyInstance(Thread.currentThread().getContextClassLoader(),
- new Class[]{InboundInvocationErrorTestCase.TestBean.class}, handler);
+ ClassLoader ccl = Thread.currentThread().getContextClassLoader();
+ TestBean proxy = (TestBean) Proxy.newProxyInstance(ccl, new Class[]{TestBean.class}, handler);
proxy.checkedException();
} catch (InboundInvocationErrorTestCase.TestException e) {
return;
@@ -96,11 +102,18 @@
}
public void testRuntimeException() throws Exception {
- Map<Method, InboundInvocationChain> chains = new HashMap<Method, InboundInvocationChain>();
- chains.put(runtimeMethod, createChain(runtimeMethod, runtimeOperation));
WorkContext workContext = EasyMock.createNiceMock(WorkContext.class);
EasyMock.replay(workContext);
- JDKInboundInvocationHandler handler = new JDKInboundInvocationHandler(chains, workContext);
+
+ Operation<Type> operation = new Operation<Type>("runtimeException", null, null, null, false, null);
+ Map<Operation<?>, InboundInvocationChain> chains = new HashMap<Operation<?>, InboundInvocationChain>();
+ chains.put(operation, createChain(runtimeMethod, runtimeOperation));
+ InboundWire wire = new InboundWireImpl();
+ wire.addInvocationChains(chains);
+ wire.setServiceContract(new ServiceContract<TestBean>(TestBean.class) {
+ });
+
+ JDKInboundInvocationHandler handler = new JDKInboundInvocationHandler(wire, workContext);
try {
InboundInvocationErrorTestCase.TestBean proxy = (InboundInvocationErrorTestCase.TestBean) Proxy
.newProxyInstance(Thread.currentThread().getContextClassLoader(),
@@ -113,7 +126,7 @@
}
private InboundInvocationChain createChain(Method m, Operation operation) {
- MockStaticInvoker invoker = new MockStaticInvoker(m, new InboundInvocationErrorTestCase.TestBeanImpl());
+ MockStaticInvoker invoker = new MockStaticInvoker(m, new TestBeanImpl());
InboundInvocationChain chain = new InboundInvocationChainImpl(operation);
chain.addInterceptor(new MockSyncInterceptor());
chain.setTargetInvoker(invoker);
@@ -124,20 +137,20 @@
public interface TestBean {
- void checkedException() throws InboundInvocationErrorTestCase.TestException;
+ void checkedException() throws TestException;
- void runtimeException() throws InboundInvocationErrorTestCase.TestRuntimeException;
+ void runtimeException() throws TestRuntimeException;
}
- public class TestBeanImpl implements InboundInvocationErrorTestCase.TestBean {
+ public class TestBeanImpl implements TestBean {
public void checkedException() throws InboundInvocationErrorTestCase.TestException {
- throw new InboundInvocationErrorTestCase.TestException();
+ throw new TestException();
}
- public void runtimeException() throws InboundInvocationErrorTestCase.TestRuntimeException {
- throw new InboundInvocationErrorTestCase.TestRuntimeException();
+ public void runtimeException() throws TestRuntimeException {
+ throw new TestRuntimeException();
}
}
Added: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandlerSerializationTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandlerSerializationTestCase.java?view=auto&rev=478773
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandlerSerializationTestCase.java (added)
+++ incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandlerSerializationTestCase.java Thu Nov 23 21:34:26 2006
@@ -0,0 +1,58 @@
+package org.apache.tuscany.core.wire.jdk;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.tuscany.spi.SCAExternalizable;
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.wire.InboundWire;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.component.WorkContextImpl;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JDKCallbackInvocationHandlerSerializationTestCase extends TestCase {
+ private InboundWire wire;
+ private WorkContext workContext;
+
+ public void testSerializeDeserialize() throws Exception {
+ JDKCallbackInvocationHandler handler = new JDKCallbackInvocationHandler(wire, workContext);
+ ByteArrayOutputStream stream = new ByteArrayOutputStream();
+ ObjectOutputStream ostream = new ObjectOutputStream(stream);
+ ostream.writeObject(handler);
+
+ ObjectInputStream istream = new ObjectInputStream(new ByteArrayInputStream(stream.toByteArray()));
+ SCAExternalizable externalizable = (SCAExternalizable) istream.readObject();
+
+ externalizable.setWorkContext(workContext);
+ externalizable.reactivate();
+ EasyMock.verify(wire);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ wire = EasyMock.createMock(InboundWire.class);
+ EasyMock.expect(wire.getServiceName()).andReturn("foo").atLeastOnce();
+ EasyMock.replay(wire);
+ Map<String, InboundWire> wires = new HashMap<String, InboundWire>();
+ wires.put("foo", wire);
+ AtomicComponent component = EasyMock.createMock(AtomicComponent.class);
+ EasyMock.expect(component.getInboundWires()).andReturn(wires);
+ EasyMock.replay(component);
+ workContext = new WorkContextImpl();
+ workContext.setCurrentAtomicComponent(component);
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ workContext.setCurrentAtomicComponent(null);
+ }
+}
Propchange: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandlerSerializationTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandlerSerializationTestCase.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandlerTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandlerTestCase.java?view=diff&rev=478773&r1=478772&r2=478773
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandlerTestCase.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandlerTestCase.java Thu Nov 23 21:34:26 2006
@@ -35,7 +35,7 @@
public void testToString() {
InboundWireImpl wire = new InboundWireImpl();
wire.setServiceContract(new JavaServiceContract(Foo.class));
- JDKCallbackInvocationHandler handler = new JDKCallbackInvocationHandler(new WorkContextImpl(), wire);
+ JDKCallbackInvocationHandler handler = new JDKCallbackInvocationHandler(wire, new WorkContextImpl());
Foo foo = (Foo) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{Foo.class}, handler);
assertNotNull(foo.toString());
}
@@ -43,7 +43,7 @@
public void testHashCode() {
InboundWireImpl wire = new InboundWireImpl();
wire.setServiceContract(new JavaServiceContract(Foo.class));
- JDKCallbackInvocationHandler handler = new JDKCallbackInvocationHandler(new WorkContextImpl(), wire);
+ JDKCallbackInvocationHandler handler = new JDKCallbackInvocationHandler(wire, new WorkContextImpl());
Foo foo = (Foo) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{Foo.class}, handler);
assertNotNull(foo.hashCode());
}
Added: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInboundInvocationHandlerSerializationTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInboundInvocationHandlerSerializationTestCase.java?view=auto&rev=478773
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInboundInvocationHandlerSerializationTestCase.java (added)
+++ incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInboundInvocationHandlerSerializationTestCase.java Thu Nov 23 21:34:26 2006
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.wire.jdk;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.model.InteractionScope;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.wire.InboundInvocationChain;
+import org.apache.tuscany.spi.wire.InboundWire;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.MessageImpl;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.component.WorkContextImpl;
+import org.apache.tuscany.core.wire.InboundInvocationChainImpl;
+import org.apache.tuscany.core.wire.InvokerInterceptor;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JDKInboundInvocationHandlerSerializationTestCase extends TestCase {
+ private InboundWire wire;
+ private WorkContext workContext;
+ private TargetInvoker invoker;
+
+ public void testSerializeDeserialize() throws Throwable {
+ JDKInboundInvocationHandler handler = new JDKInboundInvocationHandler(wire, workContext);
+ handler.invoke(Foo.class.getMethod("invoke"), null);
+
+ ByteArrayOutputStream stream = new ByteArrayOutputStream();
+ ObjectOutputStream ostream = new ObjectOutputStream(stream);
+ ostream.writeObject(handler);
+
+ ObjectInputStream istream = new ObjectInputStream(new ByteArrayInputStream(stream.toByteArray()));
+ JDKInboundInvocationHandler externalizable = (JDKInboundInvocationHandler) istream.readObject();
+
+ externalizable.setWorkContext(workContext);
+ externalizable.reactivate();
+ externalizable.invoke(Foo.class.getMethod("invoke"), null);
+ EasyMock.verify(wire);
+ EasyMock.verify(invoker);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ ServiceContract<Foo> contract = new ServiceContract<Foo>() {
+ };
+ contract.setInterfaceClass(Foo.class);
+ contract.setInteractionScope(InteractionScope.NONCONVERSATIONAL);
+
+ wire = EasyMock.createMock(InboundWire.class);
+ Map<Operation<?>, InboundInvocationChain> map = new HashMap<Operation<?>, InboundInvocationChain>();
+ Operation<Object> operation = new Operation<Object>("invoke", null, null, null, false, null);
+ map.put(operation, createChain(operation));
+
+ EasyMock.expect(wire.getServiceContract()).andReturn(contract).atLeastOnce();
+ EasyMock.expect(wire.getServiceName()).andReturn("foo").atLeastOnce();
+ EasyMock.expect(wire.getInvocationChains()).andReturn(map).times(2);
+ EasyMock.replay(wire);
+ Map<String, InboundWire> wires = new HashMap<String, InboundWire>();
+ wires.put("foo", wire);
+ AtomicComponent component = EasyMock.createMock(AtomicComponent.class);
+ EasyMock.expect(component.getInboundWires()).andReturn(wires);
+ EasyMock.replay(component);
+ workContext = new WorkContextImpl();
+ workContext.setCurrentAtomicComponent(component);
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ workContext.setCurrentAtomicComponent(null);
+ }
+
+ private InboundInvocationChain createChain(Operation operation) {
+ invoker = EasyMock.createMock(TargetInvoker.class);
+ EasyMock.expect(invoker.invoke(EasyMock.isA(Message.class))).andReturn(new MessageImpl()).times(2);
+ EasyMock.expect(invoker.isCacheable()).andReturn(false).atLeastOnce();
+ EasyMock.replay(invoker);
+ InboundInvocationChain chain = new InboundInvocationChainImpl(operation);
+ chain.setTargetInvoker(invoker);
+ chain.addInterceptor(new InvokerInterceptor());
+ chain.prepare();
+ return chain;
+ }
+
+ public class Foo {
+ public void invoke() {
+ }
+ }
+
+
+}
Propchange: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInboundInvocationHandlerSerializationTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInboundInvocationHandlerSerializationTestCase.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInboundInvocationHandlerTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInboundInvocationHandlerTestCase.java?view=diff&rev=478773&r1=478772&r2=478773
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInboundInvocationHandlerTestCase.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInboundInvocationHandlerTestCase.java Thu Nov 23 21:34:26 2006
@@ -20,24 +20,29 @@
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import org.apache.tuscany.spi.component.WorkContext;
import org.apache.tuscany.spi.idl.InvalidServiceContractException;
import org.apache.tuscany.spi.idl.java.JavaInterfaceProcessorRegistry;
+import org.apache.tuscany.spi.model.DataType;
import org.apache.tuscany.spi.model.Operation;
import org.apache.tuscany.spi.model.ServiceContract;
import org.apache.tuscany.spi.wire.InboundInvocationChain;
+import org.apache.tuscany.spi.wire.InboundWire;
import junit.framework.TestCase;
-
import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
import org.apache.tuscany.core.mock.component.SimpleTarget;
import org.apache.tuscany.core.mock.component.SimpleTargetImpl;
import org.apache.tuscany.core.mock.wire.MockStaticInvoker;
import org.apache.tuscany.core.mock.wire.MockSyncInterceptor;
import org.apache.tuscany.core.wire.InboundInvocationChainImpl;
+import org.apache.tuscany.core.wire.InboundWireImpl;
import org.apache.tuscany.core.wire.InvokerInterceptor;
import org.easymock.classextension.EasyMock;
@@ -52,7 +57,6 @@
private Operation operation;
public void testInterceptorInvoke() throws Throwable {
- Map<Method, InboundInvocationChain> chains = new HashMap<Method, InboundInvocationChain>();
MockStaticInvoker invoker = new MockStaticInvoker(echo, new SimpleTargetImpl());
InboundInvocationChain chain = new InboundInvocationChainImpl(operation);
MockSyncInterceptor interceptor = new MockSyncInterceptor();
@@ -60,25 +64,24 @@
chain.addInterceptor(new InvokerInterceptor());
chain.setTargetInvoker(invoker);
chain.prepare();
- chains.put(echo, chain);
+ InboundWire wire = createWire(chain);
+
WorkContext workContext = EasyMock.createNiceMock(WorkContext.class);
EasyMock.replay(workContext);
- JDKInboundInvocationHandler handler = new JDKInboundInvocationHandler(chains, workContext);
+ JDKInboundInvocationHandler handler = new JDKInboundInvocationHandler(wire, workContext);
assertEquals("foo", handler.invoke(echo, new String[]{"foo"}));
assertEquals(1, interceptor.getCount());
}
-
public void testDirectErrorInvoke() throws Throwable {
InboundInvocationChain source = new InboundInvocationChainImpl(operation);
MockStaticInvoker invoker = new MockStaticInvoker(echo, new SimpleTargetImpl());
source.setTargetInvoker(invoker);
+ InboundWire wire = createWire(source);
- Map<Method, InboundInvocationChain> chains = new HashMap<Method, InboundInvocationChain>();
- chains.put(echo, source);
WorkContext workContext = EasyMock.createNiceMock(WorkContext.class);
EasyMock.replay(workContext);
- JDKInboundInvocationHandler handler = new JDKInboundInvocationHandler(chains, workContext);
+ JDKInboundInvocationHandler handler = new JDKInboundInvocationHandler(wire, workContext);
try {
assertEquals("foo", handler.invoke(echo, new Object[]{}));
fail("Expected " + IllegalArgumentException.class.getName());
@@ -91,20 +94,21 @@
InboundInvocationChain source = new InboundInvocationChainImpl(operation);
MockStaticInvoker invoker = new MockStaticInvoker(echo, new SimpleTargetImpl());
source.setTargetInvoker(invoker);
+ InboundWire wire = createWire(source);
- Map<Method, InboundInvocationChain> chains = new HashMap<Method, InboundInvocationChain>();
- chains.put(echo, source);
WorkContext workContext = EasyMock.createNiceMock(WorkContext.class);
EasyMock.replay(workContext);
- JDKInboundInvocationHandler handler = new JDKInboundInvocationHandler(chains, workContext);
+ JDKInboundInvocationHandler handler = new JDKInboundInvocationHandler(wire, workContext);
assertEquals("foo", handler.invoke(echo, new Object[]{"foo"}));
}
public void testToString() {
WorkContext workContext = EasyMock.createNiceMock(WorkContext.class);
EasyMock.replay(workContext);
- JDKInboundInvocationHandler handler =
- new JDKInboundInvocationHandler(new HashMap<Method, InboundInvocationChain>(), workContext);
+ InboundWireImpl wire = new InboundWireImpl();
+ wire.setServiceContract(new ServiceContract<Foo>(Foo.class) {
+ });
+ JDKInboundInvocationHandler handler = new JDKInboundInvocationHandler(wire, workContext);
Foo foo = (Foo) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{Foo.class}, handler);
assertNotNull(foo.toString());
}
@@ -112,8 +116,10 @@
public void testHashCode() {
WorkContext workContext = EasyMock.createNiceMock(WorkContext.class);
EasyMock.replay(workContext);
- JDKInboundInvocationHandler handler =
- new JDKInboundInvocationHandler(new HashMap<Method, InboundInvocationChain>(), workContext);
+ InboundWireImpl wire = new InboundWireImpl();
+ wire.setServiceContract(new ServiceContract<Foo>(Foo.class) {
+ });
+ JDKInboundInvocationHandler handler = new JDKInboundInvocationHandler(wire, workContext);
Foo foo = (Foo) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{Foo.class}, handler);
assertNotNull(foo.hashCode());
}
@@ -129,6 +135,23 @@
}
operation = contract.getOperations().get("echo");
echo = SimpleTarget.class.getMethod("echo", String.class);
+ }
+
+
+ private InboundWire createWire(InboundInvocationChain chain) {
+ DataType<Type> type = new DataType<Type>(String.class, String.class);
+ List<DataType<Type>> types = new ArrayList<DataType<Type>>();
+ types.add(type);
+ DataType<List<DataType<Type>>> inputType =
+ new DataType<List<DataType<Type>>>(Object[].class, types);
+ Operation<Type> operation = new Operation<Type>("echo", inputType, null, null, false, null);
+ Map<Operation<?>, InboundInvocationChain> chains = new HashMap<Operation<?>, InboundInvocationChain>();
+ chains.put(operation, chain);
+ InboundWire wire = new InboundWireImpl();
+ wire.addInvocationChains(chains);
+ wire.setServiceContract(new ServiceContract<SimpleTarget>(SimpleTarget.class) {
+ });
+ return wire;
}
private interface Foo {
Added: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKOutboundInvocationHandlerSerializationTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKOutboundInvocationHandlerSerializationTestCase.java?view=auto&rev=478773
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKOutboundInvocationHandlerSerializationTestCase.java (added)
+++ incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKOutboundInvocationHandlerSerializationTestCase.java Thu Nov 23 21:34:26 2006
@@ -0,0 +1,125 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.wire.jdk;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.SCAObject;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.model.InteractionScope;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.MessageImpl;
+import org.apache.tuscany.spi.wire.OutboundInvocationChain;
+import org.apache.tuscany.spi.wire.OutboundWire;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.component.WorkContextImpl;
+import org.apache.tuscany.core.wire.InvokerInterceptor;
+import org.apache.tuscany.core.wire.OutboundInvocationChainImpl;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JDKOutboundInvocationHandlerSerializationTestCase extends TestCase {
+ private OutboundWire wire;
+ private WorkContext workContext;
+ private TargetInvoker invoker;
+
+ public void testSerializeDeserialize() throws Throwable {
+ JDKOutboundInvocationHandler handler = new JDKOutboundInvocationHandler(wire, workContext);
+ handler.invoke(Foo.class.getMethod("invoke"), null);
+ ByteArrayOutputStream stream = new ByteArrayOutputStream();
+ ObjectOutputStream ostream = new ObjectOutputStream(stream);
+ ostream.writeObject(handler);
+
+ ObjectInputStream istream = new ObjectInputStream(new ByteArrayInputStream(stream.toByteArray()));
+ JDKOutboundInvocationHandler externalizable = (JDKOutboundInvocationHandler) istream.readObject();
+
+ externalizable.setWorkContext(workContext);
+ externalizable.reactivate();
+ externalizable.invoke(Foo.class.getMethod("invoke"), null);
+ EasyMock.verify(invoker);
+ EasyMock.verify(wire);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ SCAObject container = EasyMock.createMock(SCAObject.class);
+ ServiceContract<Foo> contract = new ServiceContract<Foo>() {
+ };
+ contract.setInterfaceClass(Foo.class);
+ contract.setInteractionScope(InteractionScope.NONCONVERSATIONAL);
+ EasyMock.expect(container.getName()).andReturn("bar").atLeastOnce();
+ EasyMock.replay(container);
+ wire = EasyMock.createMock(OutboundWire.class);
+ Map<Operation<?>, OutboundInvocationChain> map = new HashMap<Operation<?>, OutboundInvocationChain>();
+ Operation<Object> operation = new Operation<Object>("invoke", null, null, null, false, null);
+ map.put(operation, createChain(operation));
+ EasyMock.expect(wire.getContainer()).andReturn(container).atLeastOnce();
+ EasyMock.expect(wire.getServiceContract()).andReturn(contract).atLeastOnce();
+ EasyMock.expect(wire.getReferenceName()).andReturn("foo").atLeastOnce();
+ EasyMock.expect(wire.getInvocationChains()).andReturn(map).times(2);
+ EasyMock.replay(wire);
+ Map<String, List<OutboundWire>> wires = new HashMap<String, List<OutboundWire>>();
+ List<OutboundWire> list = new ArrayList<OutboundWire>();
+ list.add(wire);
+ wires.put("foo", list);
+ AtomicComponent component = EasyMock.createMock(AtomicComponent.class);
+ EasyMock.expect(component.getOutboundWires()).andReturn(wires);
+ EasyMock.replay(component);
+ workContext = new WorkContextImpl();
+ workContext.setCurrentAtomicComponent(component);
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ workContext.setCurrentAtomicComponent(null);
+ }
+
+ private OutboundInvocationChain createChain(Operation operation) {
+ invoker = EasyMock.createMock(TargetInvoker.class);
+ EasyMock.expect(invoker.invoke(EasyMock.isA(Message.class))).andReturn(new MessageImpl()).times(2);
+ EasyMock.expect(invoker.isCacheable()).andReturn(false).atLeastOnce();
+ EasyMock.replay(invoker);
+ OutboundInvocationChain chain = new OutboundInvocationChainImpl(operation);
+ chain.setTargetInvoker(invoker);
+ chain.addInterceptor(new InvokerInterceptor());
+ chain.prepare();
+ return chain;
+ }
+
+ public class Foo {
+
+ public void invoke() {
+ }
+ }
+
+}
Propchange: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKOutboundInvocationHandlerSerializationTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKOutboundInvocationHandlerSerializationTestCase.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKOutboundInvocationHandlerTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKOutboundInvocationHandlerTestCase.java?view=diff&rev=478773&r1=478772&r2=478773
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKOutboundInvocationHandlerTestCase.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKOutboundInvocationHandlerTestCase.java Thu Nov 23 21:34:26 2006
@@ -94,6 +94,7 @@
replay(outboundChain);
outboundChains.put(op1, outboundChain);
expect(outboundWire.getInvocationChains()).andReturn(outboundChains).anyTimes();
+ expect(outboundWire.getReferenceName()).andReturn("fooRef").atLeastOnce();
expect(outboundWire.getContainer()).andReturn(null).anyTimes();
expect(outboundWire.getServiceContract()).andReturn(outboundContract).anyTimes();
replay(outboundWire);
Added: incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/ReactivationException.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/ReactivationException.java?view=auto&rev=478773
==============================================================================
--- incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/ReactivationException.java (added)
+++ incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/ReactivationException.java Thu Nov 23 21:34:26 2006
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.spi;
+
+import org.apache.tuscany.api.TuscanyRuntimeException;
+
+/**
+ * Raised when an error is encountered reactivating a serialized instance
+ *
+ * @version $Rev$ $Date$
+ */
+public class ReactivationException extends TuscanyRuntimeException {
+ public ReactivationException() {
+ }
+
+ public ReactivationException(String message) {
+ super(message);
+ }
+
+ public ReactivationException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public ReactivationException(Throwable cause) {
+ super(cause);
+ }
+}
Propchange: incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/ReactivationException.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/ReactivationException.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/SCAExternalizable.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/SCAExternalizable.java?view=auto&rev=478773
==============================================================================
--- incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/SCAExternalizable.java (added)
+++ incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/SCAExternalizable.java Thu Nov 23 21:34:26 2006
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.spi;
+
+import org.apache.tuscany.spi.component.WorkContext;
+
+/**
+ * A serialization contract for runtime SCA artifacts. When an instance is deserialized, runtime services defined in
+ * this contract must be set before reactivating the instance
+ *
+ * @version $Rev$ $Date$
+ */
+public interface SCAExternalizable {
+
+ /**
+ * Sets the current work context
+ *
+ * @param context the current work context
+ */
+ void setWorkContext(WorkContext context);
+
+ /**
+ * Callback after all values have been set prior to making the instance available in the runtime
+ *
+ * @throws ReactivationException
+ */
+ void reactivate() throws ReactivationException;
+}
Propchange: incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/SCAExternalizable.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/SCAExternalizable.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/component/WorkContext.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/component/WorkContext.java?view=diff&rev=478773&r1=478772&r2=478773
==============================================================================
--- incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/component/WorkContext.java (original)
+++ incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/component/WorkContext.java Thu Nov 23 21:34:26 2006
@@ -38,7 +38,7 @@
*
* @return the current atomic component as a request is processed or null
*/
- public Object getCurrentAtomicComponent();
+ AtomicComponent getCurrentAtomicComponent();
/**
* Sets the current atomic component that is handling processing of a request. Note that in most cases it will not
@@ -46,7 +46,7 @@
*
* @param component the current atomic component
*/
- public void setCurrentAtomicComponent(AtomicComponent component);
+ void setCurrentAtomicComponent(AtomicComponent component);
/**
* Returns the current chain of SCAObject addresses
Modified: incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/WireInvocationHandler.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/WireInvocationHandler.java?view=diff&rev=478773&r1=478772&r2=478773
==============================================================================
--- incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/WireInvocationHandler.java (original)
+++ incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/WireInvocationHandler.java Thu Nov 23 21:34:26 2006
@@ -19,14 +19,13 @@
package org.apache.tuscany.spi.wire;
import java.lang.reflect.Method;
-import java.io.Serializable;
/**
* Implementations are responsible for dispatching an operation down an invocation chain
*
* @version $$Rev$$ $$Date$$
*/
-public interface WireInvocationHandler extends Serializable {
+public interface WireInvocationHandler {
Object invoke(Method method, Object[] args) throws Throwable;
Modified: incubator/tuscany/java/sca/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/TargetInvokerExtensionTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/TargetInvokerExtensionTestCase.java?view=diff&rev=478773&r1=478772&r2=478773
==============================================================================
--- incubator/tuscany/java/sca/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/TargetInvokerExtensionTestCase.java (original)
+++ incubator/tuscany/java/sca/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/TargetInvokerExtensionTestCase.java Thu Nov 23 21:34:26 2006
@@ -34,6 +34,7 @@
*/
public class TargetInvokerExtensionTestCase extends TestCase {
+ @SuppressWarnings("unchecked")
public void testNonBlockingDispatch() {
Object from = new Object();
InboundWire wire = EasyMock.createMock(InboundWire.class);
Modified: incubator/tuscany/java/sca/kernel/spi/src/test/java/org/apache/tuscany/spi/wire/AbstractOutboundInvocationHandlerTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/spi/src/test/java/org/apache/tuscany/spi/wire/AbstractOutboundInvocationHandlerTestCase.java?view=diff&rev=478773&r1=478772&r2=478773
==============================================================================
--- incubator/tuscany/java/sca/kernel/spi/src/test/java/org/apache/tuscany/spi/wire/AbstractOutboundInvocationHandlerTestCase.java (original)
+++ incubator/tuscany/java/sca/kernel/spi/src/test/java/org/apache/tuscany/spi/wire/AbstractOutboundInvocationHandlerTestCase.java Thu Nov 23 21:34:26 2006
@@ -70,6 +70,7 @@
protected Object getFromAddress() {
return new Object();
}
+
}
private class MockInterceptor implements Interceptor {
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org