You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by jm...@apache.org on 2006/08/31 19:21:45 UTC

svn commit: r438991 - in /incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/wire: ./ jdk/

Author: jmarino
Date: Thu Aug 31 10:21:45 2006
New Revision: 438991

URL: http://svn.apache.org/viewvc?rev=438991&view=rev
Log:
separate basic invocation handling from JDK proxy-specific mechanisms

Added:
    incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/wire/AbstractInboundInvocationHandler.java   (with props)
    incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/wire/AbstractOutboundInvocationHandler.java   (contents, props changed)
      - copied, changed from r438785, incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/wire/jdk/AbstractJDKOutboundInvocationHandler.java
Removed:
    incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/wire/jdk/AbstractJDKOutboundInvocationHandler.java
Modified:
    incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandler.java
    incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKInboundInvocationHandler.java
    incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKOutboundInvocationHandler.java

Added: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/wire/AbstractInboundInvocationHandler.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/wire/AbstractInboundInvocationHandler.java?rev=438991&view=auto
==============================================================================
--- incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/wire/AbstractInboundInvocationHandler.java (added)
+++ incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/wire/AbstractInboundInvocationHandler.java Thu Aug 31 10:21:45 2006
@@ -0,0 +1,87 @@
+/*
+ * 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.InvocationTargetException;
+
+import org.apache.tuscany.spi.component.TargetException;
+import org.apache.tuscany.spi.wire.InboundInvocationChain;
+import org.apache.tuscany.spi.wire.Interceptor;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.MessageChannel;
+import org.apache.tuscany.spi.wire.MessageImpl;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+
+/**
+ * Base class for dispatching an invocation through an {@link InboundInvocationChain}
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class AbstractInboundInvocationHandler {
+
+
+    /**
+     * Dispatches a client request made on a proxy
+     */
+    public Object invoke(InboundInvocationChain chain, TargetInvoker invoker, Object[] args) throws Throwable {
+        MessageChannel requestChannel = chain.getRequestChannel();
+        MessageChannel responseChannel = chain.getResponseChannel();
+        Interceptor headInterceptor = chain.getHeadInterceptor();
+        if (requestChannel == null && headInterceptor == null && responseChannel == null) {
+            try {
+                // short-circuit the dispatch and invoke the target directly
+                if (chain.getTargetInvoker() == null) {
+                    throw new AssertionError("No target invoker [" + chain.getOperation().getName() + "]");
+                }
+                return chain.getTargetInvoker().invokeTarget(args);
+            } catch (InvocationTargetException e) {
+                // the cause was thrown by the target so throw it
+                throw e.getCause();
+            }
+        } else {
+            Message msg = new MessageImpl();
+            msg.setTargetInvoker(invoker);
+            msg.setBody(args);
+            Message resp;
+            if (requestChannel != null) {
+                requestChannel.send(msg);
+                resp = msg.getRelatedCallbackMessage();
+                if (responseChannel != null) {
+                    responseChannel.send(resp);
+                }
+            } else {
+                if (headInterceptor == null) {
+                    throw new TargetException("Expected interceptor on target chain");
+                }
+                // dispatch the wire down the chain and get the response
+                resp = headInterceptor.invoke(msg);
+                if (responseChannel != null) {
+                    responseChannel.send(resp);
+                }
+            }
+            Object body = resp.getBody();
+            if (body instanceof Throwable) {
+                throw (Throwable) body;
+            }
+            return body;
+        }
+    }
+
+
+}

Propchange: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/wire/AbstractInboundInvocationHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/wire/AbstractInboundInvocationHandler.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Copied: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/wire/AbstractOutboundInvocationHandler.java (from r438785, incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/wire/jdk/AbstractJDKOutboundInvocationHandler.java)
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/wire/AbstractOutboundInvocationHandler.java?p2=incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/wire/AbstractOutboundInvocationHandler.java&p1=incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/wire/jdk/AbstractJDKOutboundInvocationHandler.java&r1=438785&r2=438991&rev=438991&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/wire/jdk/AbstractJDKOutboundInvocationHandler.java (original)
+++ incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/wire/AbstractOutboundInvocationHandler.java Thu Aug 31 10:21:45 2006
@@ -16,18 +16,15 @@
  * specific language governing permissions and limitations
  * under the License.    
  */
-package org.apache.tuscany.core.wire.jdk;
+package org.apache.tuscany.core.wire;
 
-import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
 
 import org.apache.tuscany.spi.wire.Interceptor;
 import org.apache.tuscany.spi.wire.Message;
 import org.apache.tuscany.spi.wire.MessageImpl;
 import org.apache.tuscany.spi.wire.OutboundInvocationChain;
 import org.apache.tuscany.spi.wire.TargetInvoker;
-import org.apache.tuscany.spi.wire.WireInvocationHandler;
 
 /**
  * Base class for performing invocations on an outbound chain. Subclasses are responsible for retrieving and supplying
@@ -35,10 +32,7 @@
  *
  * @version $Rev$ $Date$
  */
-public abstract class AbstractJDKOutboundInvocationHandler implements WireInvocationHandler, InvocationHandler {
-
-    public AbstractJDKOutboundInvocationHandler() {
-    }
+public abstract class AbstractOutboundInvocationHandler {
 
     protected Object invoke(OutboundInvocationChain chain, TargetInvoker invoker, Object[] args) throws Throwable {
         Interceptor headInterceptor = chain.getHeadInterceptor();
@@ -85,10 +79,6 @@
                 return body;
             }
         }
-    }
-
-    public Object invoke(Method method, Object[] args) throws Throwable {
-        return invoke(null, method, args);
     }
 
 

Propchange: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/wire/AbstractOutboundInvocationHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/wire/AbstractOutboundInvocationHandler.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandler.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandler.java?rev=438991&r1=438990&r2=438991&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandler.java (original)
+++ incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandler.java Thu Aug 31 10:21:45 2006
@@ -18,6 +18,7 @@
  */
 package org.apache.tuscany.core.wire.jdk;
 
+import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;
 
 import org.apache.tuscany.spi.component.WorkContext;
@@ -26,6 +27,9 @@
 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.wire.AbstractOutboundInvocationHandler;
 
 /**
  * Responsible for invoking on an outbound wire associated with a callback. The handler retrieves the correct outbound
@@ -35,7 +39,8 @@
  *
  * @version $Rev$ $Date$
  */
-public class JDKCallbackInvocationHandler extends AbstractJDKOutboundInvocationHandler {
+public class JDKCallbackInvocationHandler extends AbstractOutboundInvocationHandler
+    implements WireInvocationHandler, InvocationHandler {
 
     private WorkContext context;
 

Modified: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKInboundInvocationHandler.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKInboundInvocationHandler.java?rev=438991&r1=438990&r2=438991&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKInboundInvocationHandler.java (original)
+++ incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKInboundInvocationHandler.java Thu Aug 31 10:21:45 2006
@@ -19,27 +19,25 @@
 package org.apache.tuscany.core.wire.jdk;
 
 import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.tuscany.spi.component.TargetException;
 import org.apache.tuscany.spi.wire.InboundInvocationChain;
-import org.apache.tuscany.spi.wire.Interceptor;
-import org.apache.tuscany.spi.wire.Message;
-import org.apache.tuscany.spi.wire.MessageChannel;
-import org.apache.tuscany.spi.wire.MessageImpl;
 import org.apache.tuscany.spi.wire.TargetInvoker;
 import org.apache.tuscany.spi.wire.WireInvocationHandler;
 
+import org.apache.tuscany.core.wire.AbstractInboundInvocationHandler;
+
 /**
  * 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 class JDKInboundInvocationHandler implements WireInvocationHandler, InvocationHandler {
+public class JDKInboundInvocationHandler extends AbstractInboundInvocationHandler
+    implements WireInvocationHandler, InvocationHandler {
 
     /*
      * an association of an operation to chain holder. The holder contains the invocation chain
@@ -87,47 +85,7 @@
             assert chain != null;
             invoker = chain.getTargetInvoker();
         }
-        MessageChannel requestChannel = chain.getRequestChannel();
-        MessageChannel responseChannel = chain.getResponseChannel();
-        Interceptor headInterceptor = chain.getHeadInterceptor();
-        if (requestChannel == null && headInterceptor == null && responseChannel == null) {
-            try {
-                // short-circuit the dispatch and invoke the target directly
-                if (chain.getTargetInvoker() == null) {
-                    throw new AssertionError("No target invoker [" + method.getName() + "]");
-                }
-                return chain.getTargetInvoker().invokeTarget(args);
-            } catch (InvocationTargetException e) {
-                // the cause was thrown by the target so throw it
-                throw e.getCause();
-            }
-        } else {
-            Message msg = new MessageImpl();
-            msg.setTargetInvoker(invoker);
-            msg.setBody(args);
-            Message resp;
-            if (requestChannel != null) {
-                requestChannel.send(msg);
-                resp = msg.getRelatedCallbackMessage();
-                if (responseChannel != null) {
-                    responseChannel.send(resp);
-                }
-            } else {
-                if (headInterceptor == null) {
-                    throw new TargetException("Expected interceptor on target chain");
-                }
-                // dispatch the wire down the chain and get the response
-                resp = headInterceptor.invoke(msg);
-                if (responseChannel != null) {
-                    responseChannel.send(resp);
-                }
-            }
-            Object body = resp.getBody();
-            if (body instanceof Throwable) {
-                throw (Throwable) body;
-            }
-            return body;
-        }
+        return invoke(chain, invoker, args);
     }
 
 

Modified: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKOutboundInvocationHandler.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKOutboundInvocationHandler.java?rev=438991&r1=438990&r2=438991&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKOutboundInvocationHandler.java (original)
+++ incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKOutboundInvocationHandler.java Thu Aug 31 10:21:45 2006
@@ -18,6 +18,7 @@
  */
 package org.apache.tuscany.core.wire.jdk;
 
+import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;
 import java.util.HashMap;
 import java.util.Map;
@@ -28,6 +29,9 @@
 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.wire.AbstractOutboundInvocationHandler;
 
 /**
  * Receives a request from a proxy and performs an invocation on an {@link org.apache.tuscany.spi.wire.OutboundWire} via
@@ -35,7 +39,8 @@
  *
  * @version $Rev$ $Date$
  */
-public class JDKOutboundInvocationHandler extends AbstractJDKOutboundInvocationHandler {
+public class JDKOutboundInvocationHandler extends AbstractOutboundInvocationHandler
+    implements WireInvocationHandler, InvocationHandler {
 
     /*
      * an association of an operation to chain holder. The holder contains an invocation chain
@@ -90,6 +95,10 @@
             invoker = chain.getTargetInvoker();
         }
         return invoke(chain, invoker, args);
+    }
+
+    public Object invoke(Method method, Object[] args) throws Throwable {
+        return invoke(null, method, args);
     }
 
     /**



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org