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/02/24 23:51:18 UTC

svn commit: r380848 - in /incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core: binding/ context/impl/ runtime/

Author: jmarino
Date: Fri Feb 24 14:51:18 2006
New Revision: 380848

URL: http://svn.apache.org/viewcvs?rev=380848&view=rev
Log:
start of entrypoint and external service impls

Removed:
    incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/binding/BindingChannel.java
    incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/binding/BindingHandler.java
Modified:
    incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/impl/EntryPointContextImpl.java
    incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/impl/ExternalServiceImpl.java
    incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeContextImpl.java

Modified: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/impl/EntryPointContextImpl.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/impl/EntryPointContextImpl.java?rev=380848&r1=380847&r2=380848&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/impl/EntryPointContextImpl.java (original)
+++ incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/impl/EntryPointContextImpl.java Fri Feb 24 14:51:18 2006
@@ -14,14 +14,7 @@
 package org.apache.tuscany.core.context.impl;
 
 import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Proxy;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.apache.tuscany.core.binding.BindingChannel;
-import org.apache.tuscany.core.binding.BindingHandler;
-import org.apache.tuscany.core.binding.MessageContext;
+
 import org.apache.tuscany.core.context.AbstractContext;
 import org.apache.tuscany.core.context.AggregateContext;
 import org.apache.tuscany.core.context.ContextInitException;
@@ -29,9 +22,8 @@
 import org.apache.tuscany.core.context.EntryPointContext;
 import org.apache.tuscany.core.context.QualifiedName;
 import org.apache.tuscany.core.context.TargetException;
-import org.apache.tuscany.core.invocation.spi.ProxyCreationException;
+import org.apache.tuscany.core.invocation.jdk.JDKInvocationHandler;
 import org.apache.tuscany.core.invocation.spi.ProxyFactory;
-import org.apache.tuscany.core.message.Message;
 import org.apache.tuscany.core.message.MessageFactory;
 
 /**
@@ -41,33 +33,38 @@
  */
 public class EntryPointContextImpl extends AbstractContext implements EntryPointContext {
 
-    private BindingChannel channel = new BindingChannelImpl();
-
-    private List<BindingHandler> bindingHandlers = new ArrayList();
-
     private MessageFactory messageFactory;
 
     private AggregateContext parentContext;
 
-    private ProxyFactory targetFactory;
+    private ProxyFactory proxyFactory;
 
     private Object target;
 
-    private InvocationHandler targetInvocationHandler;
+    private InvocationHandler invocationHandler;
 
     // ----------------------------------
     // Constructors
     // ----------------------------------
 
-    public EntryPointContextImpl(String name, ProxyFactory targetFactory, AggregateContext parentContext,
-            MessageFactory messageFctory, List<BindingHandler> bindingHandlers) throws ContextInitException {
+    /**
+     * Creates a new entry point
+     * 
+     * @param name the entry point name
+     * @param proxyFactory the proxy factory containing the invocation chains for the entry point
+     * @param parentContext the containing aggregate of the entry point
+     * @param messageFactory a factory for generating invocation messages
+     * @throws ContextInitException if an error occurs creating the entry point
+     */
+    public EntryPointContextImpl(String name, ProxyFactory proxyFactory, AggregateContext parentContext,
+            MessageFactory messageFactory) throws ContextInitException {
         super(name);
-        assert (targetFactory != null) : "Proxy factory was null";
-        assert (messageFctory != null) : "Message factory was null";
-        this.targetFactory = targetFactory;
+        assert (proxyFactory != null) : "Proxy factory was null";
+        assert (messageFactory != null) : "Message factory was null";
+        this.proxyFactory = proxyFactory;
         this.parentContext = parentContext;
-        this.messageFactory = messageFctory;
-        this.bindingHandlers.addAll(bindingHandlers);
+        this.messageFactory = messageFactory;
+        invocationHandler = new JDKInvocationHandler(messageFactory,proxyFactory.getProxyConfiguration().getInvocationConfigurations());
     }
 
     // ----------------------------------
@@ -75,7 +72,7 @@
     // ----------------------------------
 
     public Object getInstance(QualifiedName qName) throws TargetException {
-        return channel;
+        return invocationHandler;
     }
 
     public Object getInstance(QualifiedName qName, boolean notify) throws TargetException {
@@ -83,68 +80,23 @@
     }
 
     public void start() throws ContextInitException {
-        try {
-            target = targetFactory.createProxy();
-            if (Proxy.isProxyClass(target.getClass())) {
-                // if this is a proxy, short-circuit proxy invocation
-                targetInvocationHandler = Proxy.getInvocationHandler(target);
-            }
-            lifecycleState = RUNNING;
-        } catch (ProxyCreationException e) {
-            lifecycleState = ERROR;
-            ContextInitException ce = new ContextInitException(e);
-            ce.setIdentifier(getName());
-            throw ce;
-        }
+        lifecycleState = RUNNING;
     }
 
     public void stop() throws CoreRuntimeException {
         lifecycleState = STOPPED;
     }
 
-    //----------------------------------
-    // InstanceContext methods
-    //----------------------------------
-
-    public Object getImplementationInstance() throws TargetException{
-        return null;
-    }
-
-    public Object getImplementationInstance(boolean notify) throws TargetException{
-        return null;
-    }
-    
     // ----------------------------------
-    // Private classes
+    // InstanceContext methods
     // ----------------------------------
 
-    /**
-     * Initiates message processing through the entry point
-     */
-    private class BindingChannelImpl implements BindingChannel {
+    public Object getImplementationInstance() throws TargetException {
+        return invocationHandler;
+    }
 
-        public void send(MessageContext ctx) throws TargetException {
-            Message msg = messageFactory.createMessage();
-            ctx.setMessage(msg);
-            for (Iterator iter = bindingHandlers.iterator(); iter.hasNext();) {
-                BindingHandler handler = (BindingHandler) iter.next();
-                if (!handler.process(ctx)) {
-                    break;
-                }
-            }
-            try {
-                if (targetInvocationHandler != null) {
-                    // short-circuit invocation
-                    // TODO in JDKInvocationHandler, we should check to see if args[0] instanceof Message, and if so
-                    // short-circuit message creation
-                    targetInvocationHandler.invoke(target, ctx.getTargetMethod(), new Object[] { msg });
-                } else {
-                    ctx.getTargetMethod().invoke(target, new Object[] { msg });
-                }
-            } catch (Throwable e) {
-                // handle client response and log error
-            }
-        }
+    public Object getImplementationInstance(boolean notify) throws TargetException {
+        return getImplementationInstance();
     }
 
 }

Modified: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/impl/ExternalServiceImpl.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/impl/ExternalServiceImpl.java?rev=380848&r1=380847&r2=380848&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/impl/ExternalServiceImpl.java (original)
+++ incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/impl/ExternalServiceImpl.java Fri Feb 24 14:51:18 2006
@@ -14,11 +14,11 @@
 package org.apache.tuscany.core.context.impl;
 
 import org.apache.tuscany.core.context.AbstractContext;
-import org.apache.tuscany.core.context.ContextInitException;
 import org.apache.tuscany.core.context.CoreRuntimeException;
 import org.apache.tuscany.core.context.ExternalServiceContext;
 import org.apache.tuscany.core.context.QualifiedName;
 import org.apache.tuscany.core.context.TargetException;
+import org.apache.tuscany.core.injection.ObjectFactory;
 import org.apache.tuscany.core.invocation.spi.ProxyCreationException;
 import org.apache.tuscany.core.invocation.spi.ProxyFactory;
 
@@ -29,16 +29,17 @@
  */
 public class ExternalServiceImpl extends AbstractContext implements ExternalServiceContext {
 
-    private ProxyFactory factory;
+    private ProxyFactory targetFactory;
 
-    private Object targetProxy;
+    private ObjectFactory targetInstanceFactory;
 
     // ----------------------------------
     // Constructors
     // ----------------------------------
 
-    public ExternalServiceImpl(String name, ProxyFactory factory) {
+    public ExternalServiceImpl(String name, ProxyFactory targetFactory) {
         super(name);
+        this.targetFactory = targetFactory;
     }
 
     // ----------------------------------
@@ -46,7 +47,15 @@
     // ----------------------------------
 
     public Object getInstance(QualifiedName qName) throws TargetException {
-        return targetProxy;
+        try {
+            return targetFactory.createProxy();
+            // TODO do we cache the proxy, (assumes stateful capabilities will be provided in an interceptor)
+        } catch (ProxyCreationException e) {
+            TargetException te = new TargetException(e);
+            te.addContextName(getName());
+            throw te;
+        }
+
     }
 
     public Object getInstance(QualifiedName qName, boolean notify) throws TargetException {
@@ -54,29 +63,18 @@
     }
 
     public void start() throws CoreRuntimeException {
-        try {
-            // create the target proxy at startup since it is stateless
-            // (assumes stateful capabilities will be provided in an interceptor)
-            targetProxy = factory.createProxy();
-            lifecycleState = RUNNING;
-        } catch (ProxyCreationException e) {
-            lifecycleState = ERROR;
-            ContextInitException ce = new ContextInitException(e);
-            ce.setIdentifier(getName());
-            throw ce;
-        }
+        lifecycleState = RUNNING;
     }
 
     public void stop() throws CoreRuntimeException {
         lifecycleState = STOPPED;
-        targetProxy = null;
     }
 
-    public Object getImplementationInstance() throws TargetException{
-        return null;
+    public Object getImplementationInstance() throws TargetException {
+        return targetInstanceFactory.getInstance();
     }
 
-    public Object getImplementationInstance(boolean notify) throws TargetException{
-        return null;
+    public Object getImplementationInstance(boolean notify) throws TargetException {
+        return getImplementationInstance();
     }
 }

Modified: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeContextImpl.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeContextImpl.java?rev=380848&r1=380847&r2=380848&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeContextImpl.java (original)
+++ incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeContextImpl.java Fri Feb 24 14:51:18 2006
@@ -56,7 +56,6 @@
 
     private final List<SCDLModelLoader> loaders;
 
-    // private final List<WireBuilder> wireBuilders;
     // the top-level wire builder in the runtime
     private final HierarchicalWireBuilder wireBuilder;
 
@@ -80,7 +79,8 @@
      * 
      * @param monitorFactory the default {@link MonitorFactory} for this runtime
      * @param builders a list of builders automatically made available; may be null
-     * @param wireBuilder the top-level hierarchical wire builder for the runtime; may be null
+     * @param wireBuilder the top-level hierarchical wire builder for the runtime; if not specified, a default
+     *        implementation will be used
      */
     public RuntimeContextImpl(MonitorFactory monitorFactory, List<SCDLModelLoader> loaders,
             List<RuntimeConfigurationBuilder> builders, HierarchicalWireBuilder wireBuilder) {
@@ -97,14 +97,15 @@
     }
 
     /**
-     * Specicalized constructor that allows the default implementations of the root and system contexts to be
+     * Specialized constructor that allows the default implementations of the root and system contexts to be
      * overridden.
      * 
      * @param monitorFactory the default {@link MonitorFactory} for this runtime
      * @param rootContext the context to use for the root of the user context tree
      * @param systemContext the context to use for the root of the system context tree
      * @param builders a list of builders automatically made available; may be null
-     * @param wireBuilder the top-level hierarchical wire builder for the runtime; may be null
+     * @param wireBuilder the top-level hierarchical wire builder for the runtime; if not specified, a default
+     *        implementation will be used
      */
     public RuntimeContextImpl(MonitorFactory monitorFactory, AggregateContext rootContext, SystemAggregateContext systemContext,
             List<SCDLModelLoader> loaders, List<RuntimeConfigurationBuilder> builders, HierarchicalWireBuilder wireBuilder) {