summaryrefslogtreecommitdiffstats
path: root/branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire
diff options
context:
space:
mode:
Diffstat (limited to 'branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire')
-rw-r--r--branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/BridgingInterceptor.java29
-rw-r--r--branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/CallbackInterfaceInterceptor.java60
-rw-r--r--branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/InboundInvocationChainImpl.java41
-rw-r--r--branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/InboundWireImpl.java166
-rw-r--r--branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/IncompatibleServiceContractExceptionFormatter.java95
-rw-r--r--branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/InvocationChainImpl.java107
-rw-r--r--branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/InvokerInterceptor.java59
-rw-r--r--branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/LoopBackWire.java33
-rw-r--r--branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/NoMethodForOperationException.java42
-rw-r--r--branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/NonBlockingBridgingInterceptor.java189
-rw-r--r--branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/OptimizedWireObjectFactory.java47
-rw-r--r--branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/OutboundInvocationChainImpl.java53
-rw-r--r--branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/OutboundWireImpl.java176
-rw-r--r--branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/SynchronousBridgingInterceptor.java55
-rw-r--r--branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireObjectFactory.java84
-rw-r--r--branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireServiceExtension.java287
-rw-r--r--branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireUtils.java146
-rw-r--r--branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandler.java137
-rw-r--r--branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKInboundInvocationHandler.java173
-rw-r--r--branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKOutboundInvocationHandler.java249
-rw-r--r--branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKWireService.java114
21 files changed, 0 insertions, 2342 deletions
diff --git a/branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/BridgingInterceptor.java b/branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/BridgingInterceptor.java
deleted file mode 100644
index c1766fbb6f..0000000000
--- a/branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/BridgingInterceptor.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * 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;
-
-import org.apache.tuscany.spi.wire.Interceptor;
-
-/**
- * Responsible for bridging an outbound to an inbound invocation chain associated with a source and target respectively
- *
- * @version $Rev$ $Date$
- */
-public interface BridgingInterceptor extends Interceptor {
-}
diff --git a/branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/CallbackInterfaceInterceptor.java b/branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/CallbackInterfaceInterceptor.java
deleted file mode 100644
index 06f0e62f70..0000000000
--- a/branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/CallbackInterfaceInterceptor.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * 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;
-
-import org.osoa.sca.NoRegisteredCallbackException;
-
-import org.apache.tuscany.spi.wire.Interceptor;
-import org.apache.tuscany.spi.wire.Message;
-
-/**
- * An interceptor applied to the outbound side of a wire that ensures the callback target implements the required
- * service contract. This is required as callback targets may be set dynamically by service implementations.
- *
- * @version $Rev$ $Date$
- */
-public class CallbackInterfaceInterceptor implements Interceptor {
- private boolean invokingServiceImplements;
- private Interceptor next;
-
- public CallbackInterfaceInterceptor(boolean invokingServiceImplements) {
- this.invokingServiceImplements = invokingServiceImplements;
- }
-
- public Message invoke(Message msg) {
- // TODO check in the context if a callback object is set, if so invoke next since the setCallback will
- // perform the check
- if (!invokingServiceImplements) {
- throw new NoRegisteredCallbackException("Callback target does not implement the callback interface");
- }
- return next.invoke(msg);
- }
-
- public void setNext(Interceptor next) {
- this.next = next;
- }
-
- public Interceptor getNext() {
- return next;
- }
-
- public boolean isOptimizable() {
- return false;
- }
-}
diff --git a/branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/InboundInvocationChainImpl.java b/branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/InboundInvocationChainImpl.java
deleted file mode 100644
index 45b580d419..0000000000
--- a/branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/InboundInvocationChainImpl.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * 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;
-
-import org.apache.tuscany.spi.model.Operation;
-import org.apache.tuscany.spi.wire.InboundInvocationChain;
-
-/**
- * Contains a target-side invocation chain
- *
- * @version $Rev$ $Date$
- */
-public class InboundInvocationChainImpl extends InvocationChainImpl implements InboundInvocationChain {
-
- /**
- * Creates an new target-side chain for the given operation
- */
- public InboundInvocationChainImpl(Operation operation) {
- super(operation);
- }
-
- public void prepare() {
- }
-
-}
diff --git a/branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/InboundWireImpl.java b/branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/InboundWireImpl.java
deleted file mode 100644
index b529cafbb6..0000000000
--- a/branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/InboundWireImpl.java
+++ /dev/null
@@ -1,166 +0,0 @@
-/*
- * 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;
-
-import java.util.HashMap;
-import java.util.Map;
-import javax.xml.namespace.QName;
-
-import org.apache.tuscany.spi.component.AtomicComponent;
-import org.apache.tuscany.spi.component.SCAObject;
-import org.apache.tuscany.spi.component.TargetResolutionException;
-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.OutboundInvocationChain;
-import org.apache.tuscany.spi.wire.OutboundWire;
-
-/**
- * Default implementation of an inbound wire
- *
- * @version $Rev$ $Date$
- */
-public class InboundWireImpl implements InboundWire {
- private QName bindingType = LOCAL_BINDING;
- private String serviceName;
- private ServiceContract serviceContract;
- private OutboundWire targetWire;
- private String callbackReferenceName;
- private Map<Operation<?>, InboundInvocationChain> chains = new HashMap<Operation<?>, InboundInvocationChain>();
- private Map<Object, Map<Operation<?>, OutboundInvocationChain>> callbackSourceChainMaps =
- new HashMap<Object, Map<Operation<?>, OutboundInvocationChain>>();
- private SCAObject container;
- private AtomicComponent targetComponent;
- private boolean optimizable;
-
-
- /**
- * Creates a local inbound wire
- */
- public InboundWireImpl() {
- }
-
-
- /**
- * Creates an inbound wire for the given binding type
- *
- * @param bindingType the binding type
- */
- public InboundWireImpl(QName bindingType) {
- this.bindingType = bindingType;
- }
-
- public QName getBindingType() {
- return bindingType;
- }
-
- public Object getTargetService() throws TargetResolutionException {
- // JFM fixme hack
- if (targetWire == null && targetComponent != null) {
- return targetComponent.getTargetInstance();
- }
- assert targetWire != null;
- // optimized, no interceptors or handlers on either end
- return targetWire.getTargetService();
- }
-
- public ServiceContract getServiceContract() {
- return serviceContract;
- }
-
- public void setServiceContract(ServiceContract serviceContract) {
- this.serviceContract = serviceContract;
- }
-
- public void addInterface(Class claz) {
- throw new UnsupportedOperationException("Additional proxy interfaces not yet supported");
- }
-
- public String getServiceName() {
- return serviceName;
- }
-
- public void setServiceName(String serviceName) {
- this.serviceName = serviceName;
- }
-
- public Map<Operation<?>, InboundInvocationChain> getInvocationChains() {
- return chains;
- }
-
- public void addInvocationChains(Map<Operation<?>, InboundInvocationChain> chains) {
- this.chains.putAll(chains);
- }
-
- public void addInvocationChain(Operation<?> operation, InboundInvocationChain chain) {
- chains.put(operation, chain);
- }
-
- public Map<Operation<?>, OutboundInvocationChain> getSourceCallbackInvocationChains(Object targetAddr) {
- return callbackSourceChainMaps.get(targetAddr);
- }
-
- public void addSourceCallbackInvocationChains(Object targetAddr,
- Map<Operation<?>, OutboundInvocationChain> chains) {
- callbackSourceChainMaps.put(targetAddr, chains);
- }
-
- public void addSourceCallbackInvocationChain(Object targetAddr,
- Operation operation,
- OutboundInvocationChain chain) {
- Map<Operation<?>, OutboundInvocationChain> chains = callbackSourceChainMaps.get(targetAddr);
- if (chains == null) {
- chains = new HashMap<Operation<?>, OutboundInvocationChain>();
- callbackSourceChainMaps.put(targetAddr, chains);
- }
- chains.put(operation, chain);
- }
-
- public void setTargetWire(OutboundWire wire) {
- targetWire = wire;
- }
-
- public String getCallbackReferenceName() {
- return callbackReferenceName;
- }
-
- public void setCallbackReferenceName(String callbackReferenceName) {
- this.callbackReferenceName = callbackReferenceName;
- }
-
- public boolean isOptimizable() {
- return optimizable;
- }
-
- public void setOptimizable(boolean optimizable) {
- this.optimizable = optimizable;
- }
-
- public SCAObject getContainer() {
- return container;
- }
-
- public void setContainer(SCAObject container) {
- if (container instanceof AtomicComponent) {
- targetComponent = (AtomicComponent) container;
- }
- this.container = container;
- }
-}
diff --git a/branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/IncompatibleServiceContractExceptionFormatter.java b/branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/IncompatibleServiceContractExceptionFormatter.java
deleted file mode 100644
index 92da622d11..0000000000
--- a/branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/IncompatibleServiceContractExceptionFormatter.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * 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;
-
-import java.io.PrintWriter;
-
-import org.osoa.sca.annotations.Destroy;
-import org.osoa.sca.annotations.EagerInit;
-
-import org.apache.tuscany.spi.annotation.Autowire;
-import org.apache.tuscany.spi.model.Operation;
-import org.apache.tuscany.spi.model.ServiceContract;
-import org.apache.tuscany.spi.wire.IncompatibleServiceContractException;
-
-import org.apache.tuscany.host.monitor.ExceptionFormatter;
-import org.apache.tuscany.host.monitor.FormatterRegistry;
-
-/**
- * Formats {@link org.apache.tuscany.spi.wire.IncompatibleServiceContractException} for JDK logging
- *
- * @version $Rev$ $Date$
- */
-@EagerInit
-public class IncompatibleServiceContractExceptionFormatter implements ExceptionFormatter {
- private FormatterRegistry factory;
-
- public IncompatibleServiceContractExceptionFormatter(@Autowire FormatterRegistry factory) {
- this.factory = factory;
- factory.register(this);
- }
-
- public boolean canFormat(Class<?> type) {
- return IncompatibleServiceContractException.class.isAssignableFrom(type);
- }
-
- @Destroy
- public void destroy() {
- factory.unregister(this);
- }
-
- public PrintWriter write(PrintWriter writer, Throwable exception) {
- assert exception instanceof IncompatibleServiceContractException;
- IncompatibleServiceContractException e = (IncompatibleServiceContractException) exception;
- e.appendBaseMessage(writer);
- ServiceContract<?> source = e.getSource();
- String sourceContractName = null;
- if (source != null) {
- sourceContractName = source.getInterfaceName();
- }
- Operation<?> sourceOperation = e.getSourceOperation();
- String sourceOpName = null;
- if (sourceOperation != null) {
- sourceOpName = sourceOperation.getName();
- }
- if (sourceOpName == null) {
- writer.write("\nSource Contract: " + sourceContractName);
- } else {
- writer.write("\nSource Contract: " + sourceContractName + "/" + sourceOpName);
- }
- ServiceContract<?> target = e.getTarget();
- String targetContractName = null;
- if (target != null) {
- targetContractName = target.getInterfaceName();
- }
- Operation<?> targetOperation = e.getTargetOperation();
- String targetOpName = null;
- if (targetOperation != null) {
- targetOpName = targetOperation.getName();
- }
- if (targetOpName == null) {
- writer.write("\nTarget Contract: " + targetContractName + "\n");
- } else {
- writer.write("\nTarget Contract: " + targetContractName + "/" + targetOpName + "\n");
-
- }
- e.appendContextStack(writer);
- return writer;
- }
-}
diff --git a/branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/InvocationChainImpl.java b/branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/InvocationChainImpl.java
deleted file mode 100644
index d93426af4c..0000000000
--- a/branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/InvocationChainImpl.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * 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;
-
-import org.apache.tuscany.spi.model.Operation;
-import org.apache.tuscany.spi.wire.Interceptor;
-import org.apache.tuscany.spi.wire.InvocationChain;
-import org.apache.tuscany.spi.wire.TargetInvoker;
-
-/**
- * Contains functionality common to source- and target- side invocation chains
- *
- * @version $Rev$ $Date$
- */
-public abstract class InvocationChainImpl implements InvocationChain {
- protected Operation operation;
- protected TargetInvoker targetInvoker;
- protected Interceptor interceptorChainHead;
- protected Interceptor interceptorChainTail;
-
-
- // the pointer to a bridged target head interceptor or null if the target has no interceptors
- protected Interceptor targetInterceptorChainHead;
-
- public InvocationChainImpl(Operation operation) {
- assert operation != null : "No operation type specified";
- this.operation = operation;
- }
-
- public Operation getOperation() {
- return operation;
- }
-
- public void setTargetInvoker(TargetInvoker invoker) {
- this.targetInvoker = invoker;
- }
-
- public TargetInvoker getTargetInvoker() {
- return targetInvoker;
- }
-
- public void addInterceptor(Interceptor interceptor) {
- if (interceptorChainHead == null) {
- interceptorChainHead = interceptor;
- } else {
- interceptorChainTail.setNext(interceptor);
- }
- interceptorChainTail = interceptor;
- }
-
- public void addInterceptor(int index, Interceptor interceptor) {
- int i = 0;
- Interceptor next = interceptorChainHead;
- Interceptor prev = null;
- while (next != null && i < index) {
- prev = next;
- next = next.getNext();
- i++;
- }
- if (i == index) {
- if (prev != null) {
- prev.setNext(interceptor);
- } else {
- interceptorChainHead = interceptor;
- }
- interceptor.setNext(next);
- if (next == null) {
- interceptorChainTail = interceptor;
- }
- } else {
- throw new ArrayIndexOutOfBoundsException(index);
- }
- }
-
- public Interceptor getHeadInterceptor() {
- return interceptorChainHead;
- }
-
- public Interceptor getTailInterceptor() {
- return interceptorChainTail;
- }
-
- public void setTargetInterceptor(Interceptor interceptor) {
- targetInterceptorChainHead = interceptor;
- }
-
- public Interceptor getTargetInterceptor() {
- return targetInterceptorChainHead;
- }
-
-}
diff --git a/branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/InvokerInterceptor.java b/branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/InvokerInterceptor.java
deleted file mode 100644
index 90b17a930c..0000000000
--- a/branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/InvokerInterceptor.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * 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;
-
-import org.apache.tuscany.spi.wire.Interceptor;
-import org.apache.tuscany.spi.wire.InvocationRuntimeException;
-import org.apache.tuscany.spi.wire.Message;
-import org.apache.tuscany.spi.wire.TargetInvoker;
-
-/**
- * Serves as a tail interceptor on a target wire chain. This implementation dispatches to the target invoker passed
- * inside the wire message. Target invokers are passed from the source in order to allow for caching of target
- * instances.
- *
- * @version $Rev$ $Date$
- * @see org.apache.tuscany.spi.wire.TargetInvoker
- */
-public class InvokerInterceptor implements Interceptor {
-
- public InvokerInterceptor() {
- }
-
- public Message invoke(Message msg) throws InvocationRuntimeException {
- TargetInvoker invoker = msg.getTargetInvoker();
- if (invoker == null) {
- throw new InvocationRuntimeException("No target invoker specified on message");
- }
- return invoker.invoke(msg);
- }
-
- public void setNext(Interceptor next) {
- throw new IllegalStateException("This interceptor must be the last one in an target interceptor chain");
- }
-
- public Interceptor getNext() {
- return null;
- }
-
- public boolean isOptimizable() {
- return true;
- }
-
-}
diff --git a/branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/LoopBackWire.java b/branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/LoopBackWire.java
deleted file mode 100644
index a2cd71cafe..0000000000
--- a/branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/LoopBackWire.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * 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;
-
-import org.apache.tuscany.spi.component.TargetResolutionException;
-
-/**
- * A specialized wire that points back to its target container. Used to autowire to parent composites
- *
- * @version $Rev$ $Date$
- */
-public class LoopBackWire extends InboundWireImpl {
-
- public Object getTargetService() throws TargetResolutionException {
- return getContainer();
- }
-}
diff --git a/branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/NoMethodForOperationException.java b/branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/NoMethodForOperationException.java
deleted file mode 100644
index aec281d190..0000000000
--- a/branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/NoMethodForOperationException.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * 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;
-
-import org.apache.tuscany.spi.wire.ProxyCreationException;
-
-/**
- * Thrown when an {@link org.apache.tuscany.spi.model.Operation} cannot be mapped to a method on an interface
- * @version $Rev$ $Date$
- */
-public class NoMethodForOperationException extends ProxyCreationException {
- public NoMethodForOperationException() {
- }
-
- public NoMethodForOperationException(String message) {
- super(message);
- }
-
- public NoMethodForOperationException(String message, Throwable cause) {
- super(message, cause);
- }
-
- public NoMethodForOperationException(Throwable cause) {
- super(cause);
- }
-}
diff --git a/branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/NonBlockingBridgingInterceptor.java b/branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/NonBlockingBridgingInterceptor.java
deleted file mode 100644
index 225cab79bc..0000000000
--- a/branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/NonBlockingBridgingInterceptor.java
+++ /dev/null
@@ -1,189 +0,0 @@
-/*
- * 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;
-
-import java.util.LinkedList;
-
-import org.osoa.sca.CompositeContext;
-import org.osoa.sca.CurrentCompositeContext;
-import org.osoa.sca.ServiceRuntimeException;
-
-import org.apache.tuscany.spi.component.WorkContext;
-import org.apache.tuscany.spi.services.work.WorkScheduler;
-import org.apache.tuscany.spi.wire.Interceptor;
-import org.apache.tuscany.spi.wire.Message;
-import org.apache.tuscany.spi.wire.TargetInvoker;
-import org.apache.tuscany.spi.model.Scope;
-
-/**
- * Bridges interceptors in a non-blocking fashion between an {@link org.apache.tuscany.spi.wire.InboundInvocationChain}
- * and an {@link org.apache.tuscany.spi.wire.OutboundInvocationChain} by using a {@link
- * org.apache.tuscany.spi.component.WorkContext}.
- *
- * @version $$Rev$$ $$Date$$
- */
-public class NonBlockingBridgingInterceptor implements BridgingInterceptor {
-
- private static final Message RESPONSE = new ImmutableMessage();
-
- private WorkScheduler workScheduler;
- private WorkContext workContext;
- private Interceptor next;
-
- public NonBlockingBridgingInterceptor(WorkScheduler workScheduler, WorkContext workContext) {
- this.workScheduler = workScheduler;
- this.workContext = workContext;
- }
-
- public NonBlockingBridgingInterceptor(WorkScheduler workScheduler, WorkContext workContext, Interceptor next) {
- this.workScheduler = workScheduler;
- this.workContext = workContext;
- this.next = next;
- }
-
- public Message invoke(final Message msg) {
- final CompositeContext currentContext = CurrentCompositeContext.getContext();
- // Retrieve conversation id to transfer to new thread
- // Notice that we cannot clear the conversation id from the current thread
- final Object conversationID = workContext.getIdentifier(Scope.CONVERSATION);
- // Schedule the invocation of the next interceptor in a new Work instance
- try {
- workScheduler.scheduleWork(new Runnable() {
- public void run() {
- workContext.setCurrentCorrelationId(null);
- // if we got a conversation id, transfer it to new thread
- if (conversationID != null) {
- workContext.setIdentifier(Scope.CONVERSATION, conversationID);
- }
- CompositeContext oldContext = CurrentCompositeContext.setContext(currentContext);
- try {
- next.invoke(msg);
- } catch (Exception e) {
- // REVIEW uncomment when it is available
- // monitor.executionError(e);
- e.printStackTrace();
- } finally {
- CurrentCompositeContext.setContext(oldContext);
- }
- }
- });
- } catch (Exception e) {
- throw new ServiceRuntimeException(e);
- }
- return RESPONSE;
- }
-
- public Interceptor getNext() {
- return next;
- }
-
- public void setNext(Interceptor next) {
- this.next = next;
- }
-
- public boolean isOptimizable() {
- return false;
- }
-
- /**
- * A dummy message passed back on an invocation
- */
- private static class ImmutableMessage implements Message {
-
- public Object getBody() {
- return null;
- }
-
- public void setBody(Object body) {
- if (body != null) {
- throw new UnsupportedOperationException();
- }
- }
-
- public void setTargetInvoker(TargetInvoker invoker) {
- throw new UnsupportedOperationException();
- }
-
- public TargetInvoker getTargetInvoker() {
- return null;
- }
-
- public Message getRelatedCallbackMessage() {
- return null;
- }
-
- public Object getFromAddress() {
- return null;
- }
-
- public void setFromAddress(Object fromAddress) {
- throw new UnsupportedOperationException();
- }
-
- public Object popFromAddress() {
- return null;
- }
-
- public void pushFromAddress(Object fromAddress) {
- throw new UnsupportedOperationException();
- }
-
- public LinkedList<Object> getCallbackRoutingChain() {
- return null;
- }
-
- public void setCallbackRoutingChain(LinkedList<Object> fromAddresses) {
- throw new UnsupportedOperationException();
- }
-
- public Object getMessageId() {
- return null;
- }
-
- public void setMessageId(Object messageId) {
- throw new UnsupportedOperationException();
- }
-
- public Object getCorrelationId() {
- return null;
- }
-
- public void setCorrelationId(Object correlationId) {
- throw new UnsupportedOperationException();
- }
-
- public boolean isFault() {
- return false;
- }
-
- public void setBodyWithFault(Object fault) {
- throw new UnsupportedOperationException();
- }
-
- public short getConversationSequence() {
- return TargetInvoker.NONE;
- }
-
- public void setConversationSequence(short sequence) {
-
- }
-
- }
-
-}
diff --git a/branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/OptimizedWireObjectFactory.java b/branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/OptimizedWireObjectFactory.java
deleted file mode 100644
index 4a4b268201..0000000000
--- a/branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/OptimizedWireObjectFactory.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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;
-
-import org.apache.tuscany.spi.ObjectCreationException;
-import org.apache.tuscany.spi.ObjectFactory;
-import org.apache.tuscany.spi.component.TargetResolutionException;
-import org.apache.tuscany.spi.wire.OutboundWire;
-
-/**
- * Returns a target instance directly from a wire
- *
- * @version $Rev$ $Date$
- */
-public class OptimizedWireObjectFactory implements ObjectFactory {
-
- private OutboundWire wire;
-
- public OptimizedWireObjectFactory(OutboundWire factory) {
- this.wire = factory;
- }
-
- public Object getInstance() throws ObjectCreationException {
- try {
- return wire.getTargetService();
- } catch (TargetResolutionException e) {
- throw new ObjectCreationException(e);
- }
- }
-
-}
diff --git a/branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/OutboundInvocationChainImpl.java b/branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/OutboundInvocationChainImpl.java
deleted file mode 100644
index a9d83cb7a0..0000000000
--- a/branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/OutboundInvocationChainImpl.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * 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;
-
-import org.apache.tuscany.spi.model.Operation;
-import org.apache.tuscany.spi.wire.OutboundInvocationChain;
-
-/**
- * Contains a outgoing invocation pipeline for a service operation.
- *
- * @version $Rev$ $Date$
- */
-public class OutboundInvocationChainImpl extends InvocationChainImpl implements OutboundInvocationChain {
-
- /**
- * Creates an new outbound chain
- */
- public OutboundInvocationChainImpl(Operation operation) {
- super(operation);
- }
-
- public void prepare() {
- if (interceptorChainHead != null) {
- if (targetInterceptorChainHead != null) {
- // Connect source interceptor chain directly to target interceptor chain
- interceptorChainTail.setNext(targetInterceptorChainHead);
- }
- } else {
- // no source interceptor chain or source handlers, connect to target interceptor chain or channel
- if (targetInterceptorChainHead != null) {
- interceptorChainHead = targetInterceptorChainHead;
- interceptorChainTail = targetInterceptorChainHead;
- }
- }
- }
-
-}
diff --git a/branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/OutboundWireImpl.java b/branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/OutboundWireImpl.java
deleted file mode 100644
index bad92ffe1e..0000000000
--- a/branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/OutboundWireImpl.java
+++ /dev/null
@@ -1,176 +0,0 @@
-/*
- * 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;
-
-import java.util.HashMap;
-import java.util.Map;
-import javax.xml.namespace.QName;
-
-import org.apache.tuscany.spi.QualifiedName;
-import org.apache.tuscany.spi.component.SCAObject;
-import org.apache.tuscany.spi.component.TargetResolutionException;
-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.OutboundInvocationChain;
-import org.apache.tuscany.spi.wire.OutboundWire;
-
-/**
- * Default implementation of an outbound wire
- *
- * @version $Rev$ $Date$
- */
-public class OutboundWireImpl implements OutboundWire {
- private QName bindingType = LOCAL_BINDING;
- private ServiceContract serviceContract;
- private Class<?>[] callbackInterfaces;
- private Map<Operation<?>, OutboundInvocationChain> chains = new HashMap<Operation<?>, OutboundInvocationChain>();
- private Map<Operation<?>, InboundInvocationChain> callbackTargetChains =
- new HashMap<Operation<?>, InboundInvocationChain>();
- private String referenceName;
- private QualifiedName targetName;
- private InboundWire targetWire;
- private SCAObject container;
- private boolean autowire;
- private boolean optimizable;
-
- /**
- * Creates a local outbound wire
- */
- public OutboundWireImpl() {
- }
-
- /**
- * Creates an outbound wire for the given binding type
- *
- * @param bindingType the binding type
- */
- public OutboundWireImpl(QName bindingType) {
- this.bindingType = bindingType;
- }
-
- public void setOptimizable(boolean optimizable) {
- this.optimizable = optimizable;
- }
-
- public QName getBindingType() {
- return bindingType;
- }
-
- public Object getTargetService() throws TargetResolutionException {
- if (targetWire == null) {
- return null;
- }
- // optimized, no interceptors or handlers on either end
- return targetWire.getTargetService();
- }
-
- public ServiceContract getServiceContract() {
- return serviceContract;
- }
-
- public void setServiceContract(ServiceContract serviceContract) {
- this.serviceContract = serviceContract;
- }
-
- public void addInterface(Class<?> claz) {
- throw new UnsupportedOperationException("Additional proxy interfaces not yet supported");
- }
-
- public void setCallbackInterface(Class<?> interfaze) {
- callbackInterfaces = new Class[]{interfaze};
- }
-
- public Class<?> getCallbackInterface() {
- return callbackInterfaces[0];
- }
-
- public void addCallbackInterface(Class<?> claz) {
- throw new UnsupportedOperationException("Additional callback interfaces not yet supported");
- }
-
- public Class[] getImplementedCallbackInterfaces() {
- return callbackInterfaces;
- }
-
- public void setTargetWire(InboundWire wire) {
- this.targetWire = wire;
- }
-
- public Map<Operation<?>, OutboundInvocationChain> getInvocationChains() {
- return chains;
- }
-
- public void addInvocationChains(Map<Operation<?>, OutboundInvocationChain> chains) {
- this.chains.putAll(chains);
- }
-
- public void addInvocationChain(Operation<?> operation, OutboundInvocationChain chain) {
- chains.put(operation, chain);
- }
-
- public Map<Operation<?>, InboundInvocationChain> getTargetCallbackInvocationChains() {
- return callbackTargetChains;
- }
-
- public void addTargetCallbackInvocationChains(Map<Operation<?>, InboundInvocationChain> chains) {
- callbackTargetChains.putAll(chains);
- }
-
- public void addTargetCallbackInvocationChain(Operation operation, InboundInvocationChain chain) {
- callbackTargetChains.put(operation, chain);
- }
-
- public String getReferenceName() {
- return referenceName;
- }
-
- public void setReferenceName(String referenceName) {
- this.referenceName = referenceName;
- }
-
- public QualifiedName getTargetName() {
- return targetName;
- }
-
- public void setTargetName(QualifiedName targetName) {
- this.targetName = targetName;
- }
-
- public boolean isAutowire() {
- return autowire;
- }
-
- public void setAutowire(boolean autowire) {
- this.autowire = autowire;
- }
-
- public boolean isOptimizable() {
- return optimizable;
- }
-
- public SCAObject getContainer() {
- return container;
- }
-
- public void setContainer(SCAObject container) {
- this.container = container;
- }
-}
diff --git a/branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/SynchronousBridgingInterceptor.java b/branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/SynchronousBridgingInterceptor.java
deleted file mode 100644
index f09bda400a..0000000000
--- a/branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/SynchronousBridgingInterceptor.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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;
-
-import org.apache.tuscany.spi.wire.Interceptor;
-import org.apache.tuscany.spi.wire.Message;
-
-/**
- * Synchronously bridges interceptors between an {@link org.apache.tuscany.spi.wire.InboundInvocationChain} and an
- * {@link org.apache.tuscany.spi.wire.OutboundInvocationChain}.
- *
- * @version $$Rev$$ $$Date$$
- */
-public class SynchronousBridgingInterceptor implements BridgingInterceptor {
- private Interceptor next;
-
- public SynchronousBridgingInterceptor() {
- }
-
- public SynchronousBridgingInterceptor(Interceptor next) {
- this.next = next;
- }
-
- public Message invoke(Message msg) {
- return next.invoke(msg);
- }
-
- public Interceptor getNext() {
- return next;
- }
-
- public void setNext(Interceptor next) {
- this.next = next;
- }
-
- public boolean isOptimizable() {
- return true;
- }
-}
diff --git a/branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireObjectFactory.java b/branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireObjectFactory.java
deleted file mode 100644
index c04869e8f5..0000000000
--- a/branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireObjectFactory.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * 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;
-
-import java.lang.reflect.Method;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.tuscany.spi.ObjectCreationException;
-import org.apache.tuscany.spi.ObjectFactory;
-import org.apache.tuscany.spi.component.TargetResolutionException;
-import org.apache.tuscany.spi.wire.OutboundChainHolder;
-import org.apache.tuscany.spi.wire.OutboundWire;
-import org.apache.tuscany.spi.wire.WireService;
-
-/**
- * Uses a wire to return an object instance
- *
- * @version $Rev$ $Date$
- */
-public class WireObjectFactory<T> implements ObjectFactory<T> {
- private Class<T> interfaze;
- private OutboundWire wire;
- private WireService wireService;
- // the cache of proxy interface method to operation mappings
- private Map<Method, OutboundChainHolder> mappings;
- private boolean optimizable;
-
- /**
- * Constructor.
- *
- * @param interfaze the interface to inject on the client
- * @param wire the backing wire
- * @param wireService the wire service to create the proxy
- * @throws NoMethodForOperationException
- */
- public WireObjectFactory(Class<T> interfaze, OutboundWire wire, WireService wireService)
- throws NoMethodForOperationException {
- this.interfaze = interfaze;
- this.wire = wire;
- this.wireService = wireService;
- this.mappings = WireUtils.createInterfaceToWireMapping(interfaze, wire);
- }
-
- public T getInstance() throws ObjectCreationException {
- // note optimization must be done lazily as wire object factories are created during the build phase prior
- // to the outbound and inbound wires being connected
- if ((optimizable
- || wire.isOptimizable())
- && wire.getServiceContract().getInterfaceClass() != null
- && interfaze.isAssignableFrom(wire.getServiceContract().getInterfaceClass())) {
- optimizable = true;
- try {
- return interfaze.cast(wire.getTargetService());
- } catch (TargetResolutionException e) {
- throw new ObjectCreationException(e);
- }
- }
- // clone the cached mappings
- Map<Method, OutboundChainHolder> newChains = new HashMap<Method, OutboundChainHolder>(mappings.size());
- for (Map.Entry<Method, OutboundChainHolder> entry : mappings.entrySet()) {
- newChains.put(entry.getKey(), entry.getValue().clone());
- }
- return interfaze.cast(wireService.createProxy(interfaze, wire, newChains));
- }
-
-
-}
diff --git a/branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireServiceExtension.java b/branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireServiceExtension.java
deleted file mode 100644
index 460a6a40a8..0000000000
--- a/branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireServiceExtension.java
+++ /dev/null
@@ -1,287 +0,0 @@
-/*
- * 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;
-
-import java.util.Map;
-
-import org.apache.tuscany.spi.QualifiedName;
-import org.apache.tuscany.spi.component.AtomicComponent;
-import org.apache.tuscany.spi.component.ReferenceBinding;
-import org.apache.tuscany.spi.component.ServiceBinding;
-import org.apache.tuscany.spi.component.WorkContext;
-import org.apache.tuscany.spi.model.ComponentDefinition;
-import org.apache.tuscany.spi.model.ComponentType;
-import org.apache.tuscany.spi.model.Implementation;
-import org.apache.tuscany.spi.model.Operation;
-import org.apache.tuscany.spi.model.ReferenceDefinition;
-import org.apache.tuscany.spi.model.ReferenceTarget;
-import org.apache.tuscany.spi.model.ServiceContract;
-import org.apache.tuscany.spi.model.ServiceDefinition;
-import org.apache.tuscany.spi.policy.PolicyBuilderRegistry;
-import org.apache.tuscany.spi.wire.InboundInvocationChain;
-import org.apache.tuscany.spi.wire.InboundWire;
-import org.apache.tuscany.spi.wire.IncompatibleServiceContractException;
-import org.apache.tuscany.spi.wire.OutboundInvocationChain;
-import org.apache.tuscany.spi.wire.OutboundWire;
-import org.apache.tuscany.spi.wire.WireService;
-
-import org.apache.tuscany.core.binding.local.LocalReferenceBinding;
-
-/**
- * Base class for wire service extensions
- *
- * @version $Rev$ $Date$
- */
-public abstract class WireServiceExtension implements WireService {
- protected PolicyBuilderRegistry policyRegistry;
- protected WorkContext context;
-
- protected WireServiceExtension(WorkContext context, PolicyBuilderRegistry policyRegistry) {
- this.policyRegistry = policyRegistry;
- this.context = context;
- }
-
- public OutboundInvocationChain createOutboundChain(Operation<?> operation) {
- return new OutboundInvocationChainImpl(operation);
- }
-
- public InboundInvocationChain createInboundChain(Operation<?> operation) {
- return new InboundInvocationChainImpl(operation);
- }
-
- public InboundWire createWire(ServiceDefinition service) {
- InboundWire wire = new InboundWireImpl();
- ServiceContract<?> contract = service.getServiceContract();
- wire.setServiceContract(contract);
- wire.setServiceName(service.getName());
- for (Operation<?> operation : contract.getOperations().values()) {
- InboundInvocationChain chain = createInboundChain(operation);
- // TODO handle policy
- chain.addInterceptor(new InvokerInterceptor());
- wire.addInvocationChain(operation, chain);
- }
- if (contract.getCallbackName() != null) {
- wire.setCallbackReferenceName(service.getCallbackReferenceName());
- }
- return wire;
- }
-
- public void createWires(AtomicComponent component, ComponentDefinition<?> definition) {
- Implementation<?> implementation = definition.getImplementation();
- ComponentType<?, ?, ?> componentType = implementation.getComponentType();
- // create incoming service wires
- for (ServiceDefinition service : componentType.getServices().values()) {
- InboundWire wire = createWire(service);
- wire.setContainer(component);
- component.addInboundWire(wire);
- }
- // create outgoing reference wires
- for (ReferenceTarget referenceTarget : definition.getReferenceTargets().values()) {
- Map<String, ? extends ReferenceDefinition> references = componentType.getReferences();
- ReferenceDefinition mappedReference = references.get(referenceTarget.getReferenceName());
- assert mappedReference != null;
- OutboundWire wire = createWire(referenceTarget, mappedReference);
- wire.setContainer(component);
- component.addOutboundWire(wire);
- }
- }
-
- public void createWires(ReferenceBinding referenceBinding, ServiceContract<?> contract, QualifiedName targetName) {
- InboundWire inboundWire = new InboundWireImpl(referenceBinding.getBindingType());
- inboundWire.setServiceContract(contract);
- inboundWire.setContainer(referenceBinding);
- for (Operation<?> operation : contract.getOperations().values()) {
- InboundInvocationChain chain = createInboundChain(operation);
- inboundWire.addInvocationChain(operation, chain);
- }
- OutboundWire outboundWire = new OutboundWireImpl(referenceBinding.getBindingType());
- outboundWire.setTargetName(targetName);
-
- // [rfeng] Check if the Reference has the binding contract
- ServiceContract<?> bindingContract = referenceBinding.getBindingServiceContract();
- if (bindingContract == null) {
- bindingContract = contract;
- }
- outboundWire.setServiceContract(bindingContract);
- outboundWire.setContainer(referenceBinding);
- for (Operation<?> operation : bindingContract.getOperations().values()) {
- OutboundInvocationChain chain = createOutboundChain(operation);
- if (referenceBinding instanceof LocalReferenceBinding) {
- // Not ideal but the local binding case is special as its inbound and outbound wires are connected
- // before the outbound wire is connected to the reference target. This requires the binding outbound
- // chain to have an interceptor to connect to from the binding inbound chain. This outbound
- // interceptor will then be bridged to the head target interceptor
- chain.addInterceptor(new SynchronousBridgingInterceptor());
- } else {
- chain.addInterceptor(new InvokerInterceptor());
- }
- outboundWire.addInvocationChain(operation, chain);
- }
- // Add target callback chain to outbound wire
- if (contract.getCallbackName() != null) {
- outboundWire.setCallbackInterface(contract.getCallbackClass());
- for (Operation<?> operation : contract.getCallbackOperations().values()) {
- InboundInvocationChain callbackTargetChain = createInboundChain(operation);
- // TODO handle policy
- callbackTargetChain.addInterceptor(new InvokerInterceptor());
- outboundWire.addTargetCallbackInvocationChain(operation, callbackTargetChain);
- }
- }
- referenceBinding.setInboundWire(inboundWire);
- referenceBinding.setOutboundWire(outboundWire);
- }
-
- public void createWires(ServiceBinding serviceBinding, ServiceContract<?> contract, String targetName) {
- InboundWire inboundWire = new InboundWireImpl(serviceBinding.getBindingType());
- // [rfeng] Check if the Reference has the serviceBinding contract
- ServiceContract<?> bindingContract = serviceBinding.getBindingServiceContract();
- if (bindingContract == null) {
- bindingContract = contract;
- }
- inboundWire.setServiceContract(bindingContract);
- inboundWire.setContainer(serviceBinding);
- for (Operation<?> operation : bindingContract.getOperations().values()) {
- InboundInvocationChain inboundChain = createInboundChain(operation);
- inboundChain.addInterceptor(new SynchronousBridgingInterceptor());
- inboundWire.addInvocationChain(operation, inboundChain);
- }
-
- OutboundWire outboundWire = new OutboundWireImpl(serviceBinding.getBindingType());
- outboundWire.setServiceContract(contract);
- outboundWire.setTargetName(new QualifiedName(targetName));
- outboundWire.setContainer(serviceBinding);
-
- for (Operation<?> operation : contract.getOperations().values()) {
- OutboundInvocationChain outboundChain = createOutboundChain(operation);
- outboundWire.addInvocationChain(operation, outboundChain);
- }
-
- // Add target callback chain to outbound wire
- if (contract.getCallbackName() != null) {
- outboundWire.setCallbackInterface(contract.getCallbackClass());
- for (Operation<?> operation : contract.getCallbackOperations().values()) {
- InboundInvocationChain callbackTargetChain = createInboundChain(operation);
- // TODO handle policy
- callbackTargetChain.addInterceptor(new InvokerInterceptor());
- outboundWire.addTargetCallbackInvocationChain(operation, callbackTargetChain);
- }
- }
- serviceBinding.setInboundWire(inboundWire);
- serviceBinding.setOutboundWire(outboundWire);
- }
-
- /**
- * Compares two operations for wiring compatibility as defined by the SCA assembly specification, namely: <p/> <ol>
- * <li>compatibility for the individual method is defined as compatibility of the signature, that is method name,
- * input types, and output types MUST BE the same. <li>the order of the input and output types also MUST BE the
- * same. <li>the set of Faults and Exceptions expected by the source MUST BE the same or be a superset of those
- * specified by the service. </ol>
- *
- * @param source the source contract to compare
- * @param target the target contract to compare
- * @throws org.apache.tuscany.spi.wire.IncompatibleServiceContractException
- * if the two contracts don't match
- */
- public void checkCompatibility(ServiceContract<?> source, ServiceContract<?> target, boolean ignoreCallback)
- throws IncompatibleServiceContractException {
- if (source == target) {
- // Shortcut for performance
- return;
- }
- if (source.isRemotable() != target.isRemotable()) {
- throw new IncompatibleServiceContractException("Remotable settings do not match", source, target);
- }
- if (source.getInteractionScope() != target.getInteractionScope()) {
- throw new IncompatibleServiceContractException("Interaction scopes settings do not match", source, target);
- }
-
- for (Operation<?> operation : source.getOperations().values()) {
- Operation<?> targetOperation = target.getOperations().get(operation.getName());
- if (targetOperation == null) {
- throw new IncompatibleServiceContractException("Operation not found on target", source, target);
- }
- if (!operation.equals(targetOperation)) {
- throw new IncompatibleServiceContractException("Target operations are not compatible", source, target);
- }
- }
-
- if (ignoreCallback) {
- return;
- }
-
- for (Operation<?> operation : source.getCallbackOperations().values()) {
- Operation<?> targetOperation = target.getCallbackOperations().get(operation.getName());
- if (targetOperation == null) {
- throw new IncompatibleServiceContractException("Callback operation not found on target",
- source,
- target,
- null,
- targetOperation);
- }
- if (!operation.equals(targetOperation)) {
- throw new IncompatibleServiceContractException("Target callback operation is not compatible",
- source,
- target,
- operation,
- targetOperation);
- }
- }
- }
-
- /**
- * Creates a wire for flowing outbound invocations from a reference
- *
- * @param target the reference definition
- * @param definition the reference target configuration
- * @return the wire the outbound wire
- */
- protected OutboundWire createWire(ReferenceTarget target, ReferenceDefinition definition) {
- if (!definition.isAutowire() && target.getTargets().size() != 1) {
- //TODO multiplicity
- throw new UnsupportedOperationException();
- }
- ServiceContract<?> contract = definition.getServiceContract();
- OutboundWire wire = new OutboundWireImpl();
- if (!definition.isAutowire()) {
- QualifiedName qName = new QualifiedName(target.getTargets().get(0).toString());
- wire.setTargetName(qName);
- } else {
- wire.setAutowire(true);
- }
- wire.setServiceContract(contract);
- wire.setReferenceName(target.getReferenceName());
- for (Operation<?> operation : contract.getOperations().values()) {
- //TODO handle policy
- OutboundInvocationChain chain = createOutboundChain(operation);
- wire.addInvocationChain(operation, chain);
-
- }
- if (contract.getCallbackName() != null) {
- wire.setCallbackInterface(contract.getCallbackClass());
- for (Operation<?> operation : contract.getCallbackOperations().values()) {
- InboundInvocationChain callbackTargetChain = createInboundChain(operation);
- // TODO handle policy
- callbackTargetChain.addInterceptor(new InvokerInterceptor());
- wire.addTargetCallbackInvocationChain(operation, callbackTargetChain);
- }
- }
- return wire;
- }
-
-}
diff --git a/branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireUtils.java b/branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireUtils.java
deleted file mode 100644
index 73aa34e6bb..0000000000
--- a/branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireUtils.java
+++ /dev/null
@@ -1,146 +0,0 @@
-/*
- * 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;
-
-import java.lang.reflect.Method;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.tuscany.spi.component.Component;
-import org.apache.tuscany.spi.component.SCAObject;
-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;
-import org.apache.tuscany.spi.wire.Interceptor;
-import org.apache.tuscany.spi.wire.OutboundChainHolder;
-import org.apache.tuscany.spi.wire.OutboundInvocationChain;
-import org.apache.tuscany.spi.wire.OutboundWire;
-
-/**
- * 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) {
- throw new NoMethodForOperationException(operation.getName());
- }
- chains.put(method, chain);
- }
- return chains;
- }
-
-
- /**
- * Maps methods on an interface to operations on a wire
- *
- * @param interfaze the interface to map from
- * @param wire the wire to map to
- * @return a collection of method to operation mappings
- * @throws NoMethodForOperationException
- */
- public static Map<Method, OutboundChainHolder> createInterfaceToWireMapping(Class<?> interfaze, OutboundWire wire)
- throws NoMethodForOperationException {
- Map<Operation<?>, OutboundInvocationChain> invocationChains = wire.getInvocationChains();
- Map<Method, OutboundChainHolder> chains = new HashMap<Method, OutboundChainHolder>(invocationChains.size());
- Method[] methods = interfaze.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());
- }
- chains.put(method, new OutboundChainHolder(entry.getValue()));
- }
- return chains;
- }
-
- /**
- * Determines if the given wire is optimizable, i.e. its invocation chains may be bypassed during an invocation.
- * This is typically calculated during the connect phase to optimize away invocation chains.
- *
- * @param wire the wire
- * @return true if the wire is optimizable
- */
- public static boolean isOptimizable(OutboundWire wire) {
- for (OutboundInvocationChain chain : wire.getInvocationChains().values()) {
- if (chain.getHeadInterceptor() != null) {
- Interceptor current = chain.getHeadInterceptor();
- if (current == null) {
- break;
- }
- while (current != null) {
- if (!current.isOptimizable()) {
- return false;
- }
- current = current.getNext();
- }
- }
- }
- // if there is a callback, the wire is never optimizable since the callback target needs to be disambiguated
- return wire.getTargetCallbackInvocationChains().isEmpty();
- }
-
- /**
- * Determines if the given wire is optimizable, i.e. its invocation chains may be bypassed during an invocation.
- * This is typically calculated during the connect phase to optimize away invocation chains.
- *
- * @param wire the wire
- * @return true if the wire is optimizable
- */
- public static boolean isOptimizable(InboundWire wire) {
- SCAObject container = wire.getContainer();
- if (!(container instanceof Component) || !((Component) container).isOptimizable()) {
- return false;
- }
- for (InboundInvocationChain chain : wire.getInvocationChains().values()) {
- if (chain.getHeadInterceptor() != null) {
- Interceptor current = chain.getHeadInterceptor();
- while (current != null) {
- if (!current.isOptimizable()) {
- return false;
- }
- current = current.getNext();
- }
- }
- }
- return true;
- }
-
-}
diff --git a/branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandler.java b/branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandler.java
deleted file mode 100644
index 741ef21794..0000000000
--- a/branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandler.java
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- * 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.Externalizable;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.LinkedList;
-import java.util.Map;
-
-import org.osoa.sca.NoRegisteredCallbackException;
-
-import org.apache.tuscany.spi.component.AtomicComponent;
-import org.apache.tuscany.spi.component.ReactivationException;
-import org.apache.tuscany.spi.component.SCAExternalizable;
-import org.apache.tuscany.spi.component.WorkContext;
-import static org.apache.tuscany.spi.idl.java.JavaIDLUtils.findOperation;
-import org.apache.tuscany.spi.model.Operation;
-import org.apache.tuscany.spi.wire.AbstractOutboundInvocationHandler;
-import org.apache.tuscany.spi.wire.InboundWire;
-import org.apache.tuscany.spi.wire.OutboundInvocationChain;
-import org.apache.tuscany.spi.wire.TargetInvoker;
-import org.apache.tuscany.spi.wire.WireInvocationHandler;
-
-
-/**
- * Responsible for invoking on an outbound wire associated with a callback. The handler retrieves the correct outbound
- * callback wire from the work context.
- * <p/>
- * TODO cache target invoker
- *
- * @version $Rev$ $Date$
- */
-public class JDKCallbackInvocationHandler extends AbstractOutboundInvocationHandler
- implements WireInvocationHandler, InvocationHandler, Externalizable, SCAExternalizable {
- private transient WorkContext context;
- private transient InboundWire wire;
- private String serviceName;
-
- /**
- * Constructor used for deserialization only
- */
- public JDKCallbackInvocationHandler() {
- }
-
- public JDKCallbackInvocationHandler(InboundWire wire, WorkContext context) {
- this.context = context;
- this.wire = wire;
- this.serviceName = wire.getServiceName();
- }
-
- @SuppressWarnings({"unchecked"})
- public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
- if (method.getParameterTypes().length == 0 && "toString".equals(method.getName())) {
- return "[Proxy - " + Integer.toHexString(hashCode()) + "]";
- } else if (method.getDeclaringClass().equals(Object.class)
- && "equals".equals(method.getName())) {
- // TODO implement
- throw new UnsupportedOperationException();
- } else if (Object.class.equals(method.getDeclaringClass())
- && "hashCode".equals(method.getName())) {
- return hashCode();
- // TODO beter hash algorithm
- }
- Object correlationId = context.getCurrentCorrelationId();
- context.setCurrentCorrelationId(null);
- LinkedList<Object> callbackRoutingChain = (LinkedList<Object>) context.getCurrentCallbackRoutingChain().clone();
- if (callbackRoutingChain == null) {
- throw new AssertionError("Missing stack of from addresses");
- }
- Object targetAddress = callbackRoutingChain.removeFirst();
- if (targetAddress == null) {
- throw new AssertionError("Popped a null from address from stack");
- }
- //TODO optimize as this is slow in local invocations
- Map<Operation<?>, OutboundInvocationChain> sourceCallbackInvocationChains =
- wire.getSourceCallbackInvocationChains(targetAddress);
- Operation operation = findOperation(method, sourceCallbackInvocationChains.keySet());
- OutboundInvocationChain chain = sourceCallbackInvocationChains.get(operation);
- TargetInvoker invoker = chain.getTargetInvoker();
-
- try {
- return invoke(chain, invoker, args, correlationId, callbackRoutingChain);
- } catch (InvocationTargetException e) {
- Throwable t = e.getCause();
- if (t instanceof NoRegisteredCallbackException) {
- throw t;
- }
- throw e;
- }
- }
-
-
- 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.getInboundWire(serviceName);
- }
-}
diff --git a/branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKInboundInvocationHandler.java b/branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKInboundInvocationHandler.java
deleted file mode 100644
index d0d82484e3..0000000000
--- a/branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKInboundInvocationHandler.java
+++ /dev/null
@@ -1,173 +0,0 @@
-/*
- * 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.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.component.AtomicComponent;
-import org.apache.tuscany.spi.component.ReactivationException;
-import org.apache.tuscany.spi.component.SCAExternalizable;
-import org.apache.tuscany.spi.component.TargetInvocationException;
-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;
-
-import org.apache.tuscany.core.wire.WireUtils;
-
-
-/**
- * Receives a request from a proxy and performs an invocation on an {@link org.apache.tuscany.spi.wire.InboundWire} via
- * an {@link InboundInvocationChain}
- *
- * @version $Rev$ $Date$
- */
-public final class JDKInboundInvocationHandler extends AbstractInboundInvocationHandler
- implements WireInvocationHandler, InvocationHandler, Externalizable, SCAExternalizable {
- private static final long serialVersionUID = -307902641125881043L;
-
- /*
- * an association of an operation to chain holder. The holder contains the invocation chain
- * and a local clone of the master TargetInvoker. TargetInvokers will be cloned by the handler and placed in the
- * holder if they are cacheable. This allows optimizations such as avoiding target resolution when a source refers
- * 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 transient Map<Method, ChainHolder> chains;
- private transient WorkContext context;
- private String serviceName;
- private Class<?> interfaze;
-
- /**
- * Constructor used for deserialization only
- */
- public JDKInboundInvocationHandler() {
- }
-
- public JDKInboundInvocationHandler(Class<?> interfaze, InboundWire wire, WorkContext context) {
- this.context = context;
- this.serviceName = wire.getServiceName();
- this.interfaze = interfaze;
- init(interfaze, wire);
- }
-
- public void setWorkContext(WorkContext context) {
- this.context = context;
- }
-
- /**
- * Dispatches a client request made on a proxy
- */
- public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
- ChainHolder holder = chains.get(method);
- if (holder == null) {
- if (method.getParameterTypes().length == 0 && "toString".equals(method.getName())) {
- return "[Proxy - " + Integer.toHexString(hashCode()) + "]";
- } else if (method.getDeclaringClass().equals(Object.class)
- && "equals".equals(method.getName())) {
- // TODO implement
- throw new UnsupportedOperationException();
- } else if (Object.class.equals(method.getDeclaringClass())
- && "hashCode".equals(method.getName())) {
- return hashCode();
- // TODO beter hash algorithm
- }
- throw new TargetInvocationException("Operation not configured", method.getName());
- }
- InboundInvocationChain chain = holder.chain;
- TargetInvoker invoker;
- if (holder.cachedInvoker == null) {
- assert chain != null;
- if (chain.getTargetInvoker() == null) {
- String name = chain.getOperation().getName();
- throw new TargetInvocationException("No target invoker configured for operation", name);
- }
- if (chain.getTargetInvoker().isCacheable()) {
- // clone and store the invoker locally
- holder.cachedInvoker = (TargetInvoker) chain.getTargetInvoker().clone();
- invoker = holder.cachedInvoker;
- } else {
- invoker = chain.getTargetInvoker();
- }
- } else {
- assert chain != null;
- invoker = chain.getTargetInvoker();
- }
- context.setCurrentCorrelationId(null);
- return invoke(chain, invoker, args);
- }
-
-
- public Object invoke(Method method, Object[] args) throws Throwable {
- return invoke(null, method, args);
- }
-
- public void writeExternal(ObjectOutput out) throws IOException {
- out.writeObject(serviceName);
- out.writeObject(interfaze);
- }
-
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- serviceName = (String) in.readObject();
- interfaze = (Class<?>) 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.getInboundWire(serviceName);
- init(interfaze, wire);
- }
-
- private void init(Class<?> interfaze, InboundWire wire) {
- this.chains = new HashMap<Method, ChainHolder>();
- 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
- * the chain master
- */
- private class ChainHolder {
- InboundInvocationChain chain;
- TargetInvoker cachedInvoker;
-
- public ChainHolder(InboundInvocationChain config) {
- this.chain = config;
- }
-
- }
-
-}
diff --git a/branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKOutboundInvocationHandler.java b/branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKOutboundInvocationHandler.java
deleted file mode 100644
index 99cfb3c627..0000000000
--- a/branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKOutboundInvocationHandler.java
+++ /dev/null
@@ -1,249 +0,0 @@
-/*
- * 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.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.List;
-import java.util.Map;
-import java.util.UUID;
-
-import org.osoa.sca.NoRegisteredCallbackException;
-
-import org.apache.tuscany.spi.component.AtomicComponent;
-import org.apache.tuscany.spi.component.ReactivationException;
-import org.apache.tuscany.spi.component.SCAExternalizable;
-import org.apache.tuscany.spi.component.SCAObject;
-import org.apache.tuscany.spi.component.TargetInvocationException;
-import org.apache.tuscany.spi.component.WorkContext;
-import static org.apache.tuscany.spi.model.InteractionScope.CONVERSATIONAL;
-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.OutboundChainHolder;
-import org.apache.tuscany.spi.wire.OutboundInvocationChain;
-import org.apache.tuscany.spi.wire.OutboundWire;
-import org.apache.tuscany.spi.wire.TargetInvoker;
-import org.apache.tuscany.spi.wire.WireInvocationHandler;
-
-import org.apache.tuscany.core.implementation.PojoAtomicComponent;
-import org.apache.tuscany.core.wire.NoMethodForOperationException;
-import org.apache.tuscany.core.wire.WireUtils;
-
-
-/**
- * Receives a request from a proxy and performs an invocation on an {@link org.apache.tuscany.spi.wire.OutboundWire} via
- * an {@link org.apache.tuscany.spi.wire.OutboundInvocationChain}
- *
- * @version $Rev$ $Date$
- */
-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
- * and a local clone of the master TargetInvoker. TargetInvokers will be cloned by the handler and placed in the
- * holder if they are cacheable. This allows optimizations such as avoiding target resolution when a source refers
- * 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 transient Map<Method, OutboundChainHolder> chains;
- private transient WorkContext workContext;
- private transient Object fromAddress;
- private transient boolean wireContainerIsAtomicComponent;
- private transient boolean contractHasCallback;
- private transient boolean callbackIsImplemented;
- private transient String callbackClassName;
- private transient boolean contractIsRemotable;
- private transient boolean contractIsConversational;
- private transient String convIdForRemotableTarget;
- private transient String convIdFromThread;
- private String referenceName;
- private Class<?> interfaze;
-
- /**
- * Constructor used for deserialization only
- */
- public JDKOutboundInvocationHandler() {
- }
-
- public JDKOutboundInvocationHandler(Class<?> interfaze, OutboundWire wire, WorkContext workContext)
- throws NoMethodForOperationException {
- this.workContext = workContext;
- this.interfaze = interfaze;
- init(interfaze, wire, null);
- }
-
- public JDKOutboundInvocationHandler(Class<?> interfaze,
- OutboundWire wire,
- Map<Method, OutboundChainHolder> mapping,
- WorkContext workContext)
- throws NoMethodForOperationException {
- this.workContext = workContext;
- this.interfaze = interfaze;
- init(interfaze, wire, mapping);
- }
-
- public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
- OutboundChainHolder holder = chains.get(method);
- if (holder == null) {
- if (method.getParameterTypes().length == 0 && "toString".equals(method.getName())) {
- return "[Proxy - " + Integer.toHexString(hashCode()) + "]";
- } else if (method.getDeclaringClass().equals(Object.class)
- && "equals".equals(method.getName())) {
- // TODO implement
- throw new UnsupportedOperationException();
- } else if (Object.class.equals(method.getDeclaringClass())
- && "hashCode".equals(method.getName())) {
- return hashCode();
- // TODO beter hash algorithm
- }
- throw new TargetInvocationException("Operation not configured", method.getName());
- }
- OutboundInvocationChain chain = holder.getChain();
- TargetInvoker invoker;
-
- if (holder.getCachedInvoker() == null) {
- assert chain != null;
- if (chain.getTargetInvoker() == null) {
- String name = chain.getOperation().getName();
- throw new TargetInvocationException("No target invoker configured for operation", name);
- }
- if (chain.getTargetInvoker().isCacheable()) {
- // clone and store the invoker locally
- holder.setCachedInvoker((TargetInvoker) chain.getTargetInvoker().clone());
- invoker = holder.getCachedInvoker();
- } else {
- invoker = chain.getTargetInvoker();
- }
- } else {
- assert chain != null;
- invoker = chain.getTargetInvoker();
- }
-
- if (wireContainerIsAtomicComponent && contractHasCallback && !callbackIsImplemented) {
- throw new NoRegisteredCallbackException("Instance is does not implement callback: "
- + callbackClassName);
- }
-
- if (contractIsConversational) {
- assert workContext != null : "Work context cannot be null for conversational invocation";
- // Check for a conv id on thread and remember it
- convIdFromThread = (String) workContext.getIdentifier(Scope.CONVERSATION);
- if (contractIsRemotable) {
- if (convIdForRemotableTarget == null) {
- convIdForRemotableTarget = createConversationID();
- }
- // Always use the conv id for this target
- workContext.setIdentifier(Scope.CONVERSATION, convIdForRemotableTarget);
- } else if (convIdFromThread == null) {
- String newConvId = createConversationID();
- workContext.setIdentifier(Scope.CONVERSATION, newConvId);
- }
- }
-
- Object result = invoke(chain, invoker, args, null, null);
- if (contractIsConversational && contractIsRemotable) {
- // Make sure we restore the remembered conv id to continue propagating
- workContext.setIdentifier(Scope.CONVERSATION, convIdFromThread);
- }
- return result;
- }
-
- public Object invoke(Method method, Object[] args) throws Throwable {
- return invoke(null, method, args);
- }
-
- protected Object getFromAddress() {
- return contractHasCallback ? fromAddress : null;
- }
-
- public void setWorkContext(WorkContext context) {
- workContext = context;
- }
-
- public void writeExternal(ObjectOutput out) throws IOException {
- out.writeObject(referenceName);
- out.writeObject(interfaze);
- }
-
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- referenceName = (String) in.readObject();
- interfaze = (Class<?>) 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) {
- throw new ReactivationException("Reference wire not found", referenceName, owner.getName());
- }
- // TODO handle multiplicity
- OutboundWire wire = wires.get(0);
- try {
- init(interfaze, wire, null);
- } catch (NoMethodForOperationException e) {
- throw new ReactivationException(e);
- }
- }
-
- private void init(Class<?> interfaze, OutboundWire wire, Map<Method, OutboundChainHolder> mapping)
- throws NoMethodForOperationException {
- ServiceContract contract = wire.getServiceContract();
- this.referenceName = wire.getReferenceName();
- SCAObject wireContainer = wire.getContainer();
- this.fromAddress = (wireContainer == null) ? null : wireContainer.getName();
- this.contractIsConversational = contract.getInteractionScope().equals(CONVERSATIONAL);
- this.contractIsRemotable = contract.isRemotable();
- this.contractHasCallback = contract.getCallbackClass() != null;
- if (contractHasCallback) {
- this.callbackClassName = contract.getCallbackClass().getName();
- } else {
- this.callbackClassName = null;
- }
- // FIXME JFM this should be done during the callback and not be dependent on PojoAtomicComponent
- this.wireContainerIsAtomicComponent = wireContainer instanceof PojoAtomicComponent;
- if (wireContainerIsAtomicComponent && contractHasCallback) {
- this.callbackIsImplemented =
- ((PojoAtomicComponent) wireContainer).implementsCallback(contract.getCallbackClass());
- } else {
- this.callbackIsImplemented = false;
- }
- if (mapping == null) {
- chains = WireUtils.createInterfaceToWireMapping(interfaze, wire);
- } else {
- chains = mapping;
- }
- }
-
- // TODO Temporary fix to return a string with a UUID
- private String createConversationID() {
- return UUID.randomUUID().toString();
- }
-
-
-}
diff --git a/branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKWireService.java b/branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKWireService.java
deleted file mode 100644
index e15b851351..0000000000
--- a/branches/pre-spec-changes/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKWireService.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * 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.lang.reflect.Proxy;
-import java.util.Map;
-
-import org.osoa.sca.annotations.Constructor;
-import org.osoa.sca.annotations.EagerInit;
-
-import org.apache.tuscany.spi.annotation.Autowire;
-import org.apache.tuscany.spi.component.WorkContext;
-import org.apache.tuscany.spi.policy.PolicyBuilderRegistry;
-import org.apache.tuscany.spi.wire.InboundWire;
-import org.apache.tuscany.spi.wire.OutboundChainHolder;
-import org.apache.tuscany.spi.wire.OutboundWire;
-import org.apache.tuscany.spi.wire.ProxyCreationException;
-import org.apache.tuscany.spi.wire.Wire;
-import org.apache.tuscany.spi.wire.WireInvocationHandler;
-
-import org.apache.tuscany.core.wire.WireServiceExtension;
-
-/**
- * the default implementation of a wire service that uses JDK dynamic proxies
- *
- * @version $$Rev$$ $$Date$$
- */
-@EagerInit
-public class JDKWireService extends WireServiceExtension {
-
- public JDKWireService() {
- super(null, null);
- }
-
- @Constructor
- public JDKWireService(@Autowire WorkContext context, @Autowire PolicyBuilderRegistry policyRegistry) {
- super(context, policyRegistry);
- }
-
- public <T> T createProxy(Class<T> interfaze, Wire wire) throws ProxyCreationException {
- assert interfaze != null;
- assert wire != null;
- if (wire instanceof InboundWire) {
- InboundWire inbound = (InboundWire) wire;
- JDKInboundInvocationHandler handler = new JDKInboundInvocationHandler(interfaze, inbound, context);
- ClassLoader cl = interfaze.getClassLoader();
- return interfaze.cast(Proxy.newProxyInstance(cl, new Class[]{interfaze}, handler));
- } else if (wire instanceof OutboundWire) {
- OutboundWire outbound = (OutboundWire) wire;
- JDKOutboundInvocationHandler handler = new JDKOutboundInvocationHandler(interfaze, outbound, context);
- ClassLoader cl = interfaze.getClassLoader();
- return interfaze.cast(Proxy.newProxyInstance(cl, new Class[]{interfaze}, handler));
- } else {
- throw new ProxyCreationException("Invalid wire type", wire.getClass().getName());
- }
- }
-
- public <T> T createProxy(Class<T> interfaze, Wire wire, Map<Method, OutboundChainHolder> mapping)
- throws ProxyCreationException {
- assert interfaze != null;
- assert wire != null;
- assert mapping != null;
- if (wire instanceof InboundWire) {
- InboundWire inbound = (InboundWire) wire;
- JDKInboundInvocationHandler handler = new JDKInboundInvocationHandler(interfaze, inbound, context);
- ClassLoader cl = interfaze.getClassLoader();
- return interfaze.cast(Proxy.newProxyInstance(cl, new Class[]{interfaze}, handler));
- } else if (wire instanceof OutboundWire) {
- OutboundWire outbound = (OutboundWire) wire;
- JDKOutboundInvocationHandler handler = new JDKOutboundInvocationHandler(interfaze, outbound, context);
- ClassLoader cl = interfaze.getClassLoader();
- return interfaze.cast(Proxy.newProxyInstance(cl, new Class[]{interfaze}, handler));
- } else {
- throw new ProxyCreationException("Invalid wire type", wire.getClass().getName());
- }
- }
-
- public Object createCallbackProxy(Class<?> interfaze, InboundWire wire) throws ProxyCreationException {
- ClassLoader cl = interfaze.getClassLoader();
- JDKCallbackInvocationHandler handler = new JDKCallbackInvocationHandler(wire, context);
- return interfaze.cast(Proxy.newProxyInstance(cl, new Class[]{interfaze}, handler));
- }
-
- public WireInvocationHandler createHandler(Class<?> interfaze, Wire wire) {
- assert wire != null;
- if (wire instanceof InboundWire) {
- InboundWire inbound = (InboundWire) wire;
- return new JDKInboundInvocationHandler(interfaze, inbound, context);
- } else if (wire instanceof OutboundWire) {
- OutboundWire outbound = (OutboundWire) wire;
- return new JDKOutboundInvocationHandler(interfaze, outbound, context);
- } else {
- throw new ProxyCreationException("Invalid wire type", wire.getClass().getName());
- }
- }
-
-}