You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by rf...@apache.org on 2008/02/28 18:18:59 UTC

svn commit: r632064 - in /incubator/tuscany/java/sca/modules: core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/ core-spi/src/main/java/org/apache/tuscany/sca/invocation/ core/src/main/java/org/apache/tuscany/sca/core/assembly...

Author: rfeng
Date: Thu Feb 28 09:18:51 2008
New Revision: 632064

URL: http://svn.apache.org/viewvc?rev=632064&view=rev
Log:
Add phase-based ordering for invokers/interceptors in an invocation chain

Added:
    incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/Phase.java   (with props)
    incubator/tuscany/java/sca/modules/core/src/test/java/org/apache/tuscany/sca/core/invocation/PhaseManagerTestCase.java   (with props)
    incubator/tuscany/java/sca/modules/core/src/test/resources/
    incubator/tuscany/java/sca/modules/core/src/test/resources/META-INF/
    incubator/tuscany/java/sca/modules/core/src/test/resources/META-INF/services/
    incubator/tuscany/java/sca/modules/core/src/test/resources/META-INF/services/org.apache.tuscany.sca.invocation.PhaseTest
Removed:
    incubator/tuscany/java/sca/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.invocation.PhaseManager
Modified:
    incubator/tuscany/java/sca/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataBindingRuntimeWireProcessor.java
    incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/InvocationChain.java
    incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeWireImpl.java
    incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/InvocationChainImpl.java
    incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/PhaseManager.java
    incubator/tuscany/java/sca/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/InvocationChainImplTestCase.java
    incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaCallbackRuntimeWireProcessor.java
    incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaPolicyHandlingRuntimeWireProcessor.java
    incubator/tuscany/java/sca/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/TransactionRuntimeWireProcessor.java

Modified: incubator/tuscany/java/sca/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataBindingRuntimeWireProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataBindingRuntimeWireProcessor.java?rev=632064&r1=632063&r2=632064&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataBindingRuntimeWireProcessor.java (original)
+++ incubator/tuscany/java/sca/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataBindingRuntimeWireProcessor.java Thu Feb 28 09:18:51 2008
@@ -21,6 +21,7 @@
 
 import java.util.List;
 
+import org.apache.tuscany.sca.assembly.ComponentReference;
 import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint;
 import org.apache.tuscany.sca.databinding.Mediator;
 import org.apache.tuscany.sca.interfacedef.DataType;
@@ -29,6 +30,7 @@
 import org.apache.tuscany.sca.interfacedef.Operation;
 import org.apache.tuscany.sca.invocation.Interceptor;
 import org.apache.tuscany.sca.invocation.InvocationChain;
+import org.apache.tuscany.sca.invocation.Phase;
 import org.apache.tuscany.sca.runtime.RuntimeWire;
 import org.apache.tuscany.sca.runtime.RuntimeWireProcessor;
 
@@ -158,7 +160,10 @@
                 }
             }
             if (interceptor != null) {
-                chain.addInterceptor(0, interceptor);
+                String phase =
+                    (wire.getSource().getContract() instanceof ComponentReference) ? Phase.REFERENCE_INTERFACE
+                        : Phase.SERVICE_INTERFACE;
+                chain.addInterceptor(phase, interceptor);
             }
         }
 

Modified: incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/InvocationChain.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/InvocationChain.java?rev=632064&r1=632063&r2=632064&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/InvocationChain.java (original)
+++ incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/InvocationChain.java Thu Feb 28 09:18:51 2008
@@ -52,7 +52,8 @@
     Operation getSourceOperation();
 
     /**
-     * Adds an interceptor to the chain
+     * Adds an interceptor to the chain. For reference side, it will be added to
+     * Phase.REFERENCE. For service side, it will be added to Phase.SERVICE 
      *
      * @param interceptor The interceptor to add
      */
@@ -73,24 +74,39 @@
     Invoker getHeadInvoker();
 
     /**
+     * @deprecated This method is not used
      * Returns the last invoker in the chain.
      *
      * @return The last invoker in the chain
      */
+    @Deprecated
     Invoker getTailInvoker();
 
     /**
+     * @deprecated Please use <code>void addInterceptor(String phase, Interceptor interceptor);</code>
      * Adds an interceptor at the given position in the interceptor stack
      *
      * @param index       The position in the interceptor stack to add the interceptor
      * @param interceptor The interceptor to add
      */
+    @Deprecated
     void addInterceptor(int index, Interceptor interceptor);
     
     /**
+     * Add an interceptor to the given phase
+     * @param phase
+     * @param interceptor
+     */
+    void addInterceptor(String phase, Interceptor interceptor);
+    
+    /**
      * Indicate if the data can be passed in by reference as they won't be mutated.
      * @return true if pass-by-reference is allowed
      */
     boolean allowsPassByReference();
+    /**
+     * Force the invocation to allow pass-by-reference
+     * @param allowsPBR
+     */
     void setAllowsPassByReference(boolean allowsPBR);
 }

Added: incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/Phase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/Phase.java?rev=632064&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/Phase.java (added)
+++ incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/Phase.java Thu Feb 28 09:18:51 2008
@@ -0,0 +1,59 @@
+/*
+ * 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.sca.invocation;
+
+/**
+ * Tuscany built-in phases for the invocation chain
+ * 
+ * @version $Rev$ $Date$
+ */
+public interface Phase {
+    // The fisrt phase for outgoing invocations via a reference
+    String REFERENCE = "component.reference";
+
+    // data transformation and validation
+    String REFERENCE_INTERFACE = "reference.interface";
+
+    // reference policy handling
+    String REFERENCE_POLICY = "reference.policy";
+
+    // reference binding invoker
+    String REFERENCE_BINDING = "reference.binding";
+
+    // The first phase for incoming invocations via a service
+    String SERVICE_BINDING = "service.binding";
+
+    // service policy handling
+    String SERVICE_POLICY = "service.policy";
+
+    // data validation and transformation
+    String SERVICE_INTERFACE = "service.interface";
+
+    // TODO: not sure if we need to have this face
+    String SERVICE = "component.service";
+
+    // implementation policy handling
+    String IMPLEMENTATION_POLICY = "implementation.policy";
+
+    // implementation invoker
+    String IMPLEMENTATION = "component.implementation";
+
+    // String getName();
+}

Propchange: incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/Phase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/Phase.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeWireImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeWireImpl.java?rev=632064&r1=632063&r2=632064&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeWireImpl.java (original)
+++ incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeWireImpl.java Thu Feb 28 09:18:51 2008
@@ -39,6 +39,7 @@
 import org.apache.tuscany.sca.invocation.Invoker;
 import org.apache.tuscany.sca.invocation.Message;
 import org.apache.tuscany.sca.invocation.MessageFactory;
+import org.apache.tuscany.sca.invocation.Phase;
 import org.apache.tuscany.sca.provider.ImplementationProvider;
 import org.apache.tuscany.sca.provider.ReferenceBindingProvider;
 import org.apache.tuscany.sca.provider.ServiceBindingProvider;
@@ -156,7 +157,7 @@
                         + "#"
                         + reference.getName());
                 }
-                InvocationChain chain = new InvocationChainImpl(operation, targetOperation);
+                InvocationChain chain = new InvocationChainImpl(operation, targetOperation, true);
                 if (operation.isNonBlocking()) {
                     addNonBlockingInterceptor(reference, refBinding, chain);
                 }
@@ -177,7 +178,7 @@
                         + "#"
                         + service.getName());
                 }
-                InvocationChain chain = new InvocationChainImpl(operation, targetOperation);
+                InvocationChain chain = new InvocationChainImpl(operation, targetOperation, false);
                 if (operation.isNonBlocking()) {
                     addNonBlockingInterceptor(service, serviceBinding, chain);
                 }
@@ -244,7 +245,7 @@
         if (provider != null) {
             boolean supportsOneWayInvocation = provider.supportsOneWayInvocation();
             if (!supportsOneWayInvocation) {
-                chain.addInterceptor(new NonBlockingInterceptor(workScheduler));
+                chain.addInterceptor(Phase.REFERENCE, new NonBlockingInterceptor(workScheduler));
             }
         }
     }
@@ -260,7 +261,7 @@
         ServiceBindingProvider provider = ((RuntimeComponentService)service).getBindingProvider(binding);
         if (provider != null) {
             if (!provider.supportsOneWayInvocation()) {
-                chain.addInterceptor(new NonBlockingInterceptor(workScheduler));
+                chain.addInterceptor(Phase.SERVICE_BINDING, new NonBlockingInterceptor(workScheduler));
             }
         }
     }

Modified: incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/InvocationChainImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/InvocationChainImpl.java?rev=632064&r1=632063&r2=632064&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/InvocationChainImpl.java (original)
+++ incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/InvocationChainImpl.java Thu Feb 28 09:18:51 2008
@@ -20,12 +20,14 @@
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.ListIterator;
 
 import org.apache.tuscany.sca.interfacedef.Operation;
 import org.apache.tuscany.sca.invocation.Interceptor;
 import org.apache.tuscany.sca.invocation.InvocationChain;
 import org.apache.tuscany.sca.invocation.Invoker;
 import org.apache.tuscany.sca.invocation.PassByValueAware;
+import org.apache.tuscany.sca.invocation.Phase;
 
 /**
  * Default implementation of an invocation chain
@@ -35,20 +37,19 @@
 public class InvocationChainImpl implements InvocationChain {
     private Operation sourceOperation;
     private Operation targetOperation;
-    private List<Invoker> invokers = new ArrayList<Invoker>();
-    private boolean allowsPassByReference;
+    private List<Node> nodes = new ArrayList<Node>();
 
-    public InvocationChainImpl(Operation operation) {
-        assert operation != null;
-        this.targetOperation = operation;
-        this.sourceOperation = operation;
-    }
+    // FIXME: Not a good practice to use static reference
+    private final static PhaseManager phaseManager = new PhaseManager();
+    private boolean forReference;
+    private boolean allowsPassByReference;
 
-    public InvocationChainImpl(Operation sourceOperation, Operation targetOperation) {
+    public InvocationChainImpl(Operation sourceOperation, Operation targetOperation, boolean forReference) {
         assert sourceOperation != null;
         assert targetOperation != null;
         this.targetOperation = targetOperation;
         this.sourceOperation = sourceOperation;
+        this.forReference = forReference;
     }
 
     public Operation getTargetOperation() {
@@ -60,33 +61,21 @@
     }
 
     public void addInterceptor(Interceptor interceptor) {
-        invokers.add(interceptor);
-        int index = invokers.size() - 1;
-        if (index - 1 >= 0) {
-            Invoker before = invokers.get(index - 1);
-            if (before instanceof Interceptor) {
-                ((Interceptor)before).setNext(interceptor);
-            }
-        }
+        String phase = forReference ? Phase.REFERENCE : Phase.SERVICE;
+        addInterceptor(phase, interceptor);
     }
 
     public void addInvoker(Invoker invoker) {
-        invokers.add(invoker);
-        int index = invokers.size() - 1;
-        if (index - 1 >= 0) {
-            Invoker before = invokers.get(index - 1);
-            if (before instanceof Interceptor) {
-                ((Interceptor)before).setNext(invoker);
-            }
-        }
+        String phase = forReference ? Phase.REFERENCE_BINDING : Phase.IMPLEMENTATION;
+        addInvoker(phase, invoker);
     }
 
     public Invoker getHeadInvoker() {
-        return invokers.isEmpty() ? null : invokers.get(0);
+        return nodes.isEmpty() ? null : nodes.get(0).getInvoker();
     }
 
     public Invoker getTailInvoker() {
-        return invokers.isEmpty() ? null : invokers.get(invokers.size() - 1);
+        return nodes.isEmpty() ? null : nodes.get(nodes.size() - 1).getInvoker();
     }
 
     /**
@@ -104,29 +93,64 @@
     }
 
     public void addInterceptor(int index, Interceptor interceptor) {
-        invokers.add(index, interceptor);
-        if (index - 1 >= 0) {
-            Invoker before = invokers.get(index - 1);
-            if (before instanceof Interceptor) {
-                ((Interceptor)before).setNext(interceptor);
+        addInterceptor(interceptor);
+    }
+
+    public void addInterceptor(String phase, Interceptor interceptor) {
+        addInvoker(phase, interceptor);
+    }
+
+    private void addInvoker(String phase, Invoker invoker) {
+        int index = phaseManager.getAllPhases().indexOf(phase);
+        if (index == -1) {
+            throw new IllegalArgumentException("Invalid phase name: " + phase);
+        }
+        Node node = new Node(index, invoker);
+        ListIterator<Node> li = nodes.listIterator();
+        Node before = null, after = null;
+        boolean found = false;
+        while (li.hasNext()) {
+            before = after;
+            after = li.next();
+            if (after.getPhaseIndex() > index) {
+                // Move back
+                li.previous();
+                li.add(node);
+                found = true;
+                break;
+            }
+        }
+        if (!found) {
+            // Add to the end
+            nodes.add(node);
+            before = after;
+            after = null;
+        }
+
+        // Relink the interceptors
+        if (before != null) {
+            if (before.getInvoker() instanceof Interceptor) {
+                ((Interceptor)before.getInvoker()).setNext(invoker);
             }
         }
-        if (index + 1 < invokers.size()) {
-            Invoker after = invokers.get(index + 1);
-            interceptor.setNext(after);
+        if (after != null) {
+            if (invoker instanceof Interceptor) {
+                ((Interceptor)invoker).setNext(after.getInvoker());
+            }
         }
+
     }
 
     public boolean allowsPassByReference() {
-        if(allowsPassByReference) {
+        if (allowsPassByReference) {
             // No need to check the invokers
             return true;
         }
         // Check if any of the invokers allows pass-by-reference
         boolean allowsPBR = false;
-        for (Invoker i : invokers) {
-            if (i instanceof PassByValueAware) {
-                if (((PassByValueAware)i).allowsPassByReference()) {
+        for (Node i : nodes) {
+            if (i.getInvoker() instanceof PassByValueAware) {
+                if (((PassByValueAware)i.getInvoker()).allowsPassByReference()) {
                     allowsPBR = true;
                     break;
                 }
@@ -137,6 +161,29 @@
 
     public void setAllowsPassByReference(boolean allowsPBR) {
         this.allowsPassByReference = allowsPBR;
+    }
+
+    private static class Node {
+        private int phaseIndex;
+        private Invoker invoker;
+
+        public Node(int phaseIndex, Invoker invoker) {
+            super();
+            this.phaseIndex = phaseIndex;
+            this.invoker = invoker;
+        }
+
+        public int getPhaseIndex() {
+            return phaseIndex;
+        }
+
+        public Invoker getInvoker() {
+            return invoker;
+        }
+
+        public String toString() {
+            return "(" + phaseIndex + ")" + invoker;
+        }
     }
 
 }

Modified: incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/PhaseManager.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/PhaseManager.java?rev=632064&r1=632063&r2=632064&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/PhaseManager.java (original)
+++ incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/PhaseManager.java Thu Feb 28 09:18:51 2008
@@ -32,6 +32,7 @@
 
 import org.apache.tuscany.sca.contribution.util.ServiceDeclaration;
 import org.apache.tuscany.sca.contribution.util.ServiceDiscovery;
+import org.apache.tuscany.sca.invocation.Phase;
 import org.osoa.sca.ServiceRuntimeException;
 
 /**
@@ -43,9 +44,17 @@
     public static final String STAGE_REFERENCE = "reference";
     public static final String STAGE_SERVICE = "service";
     public static final String STAGE_IMPLEMENTATION = "implementation";
-    private static final String[] STAGES = new String[] {STAGE_REFERENCE, STAGE_SERVICE, STAGE_IMPLEMENTATION};
+    private final static String[] SYSTEM_REFERENCE_PHASES =
+        {Phase.REFERENCE, Phase.REFERENCE_INTERFACE, Phase.REFERENCE_POLICY, Phase.REFERENCE_BINDING};
 
+    private final static String[] SYSTEM_SERVICE_PHASES =
+        {Phase.SERVICE_BINDING, Phase.SERVICE_POLICY, Phase.SERVICE_INTERFACE, Phase.SERVICE};
+
+    private final static String[] SYSTEM_IMPLEMENTATION_PHASES = {Phase.IMPLEMENTATION_POLICY, Phase.IMPLEMENTATION};
+
+    private String pattern = Phase.class.getName();
     private Map<String, Stage> stages;
+    private List<String> phases;
 
     public class Stage {
         private String name;
@@ -84,29 +93,51 @@
         }
     }
 
-    public PhaseManager() {
+    // For unit test purpose
+    PhaseManager(String pattern) {
+        super();
+        this.pattern = pattern;
     }
 
-    public static void main(String[] args) {
-        System.out.println(new PhaseManager().getStages());
+    public PhaseManager() {
     }
 
-    public List<String> getPhases(String stage) {
+    private List<String> getPhases(String stage) {
         Stage s = getStages().get(stage);
         return s == null ? null : s.getPhases();
     }
 
+    public List<String> getReferencePhases() {
+        return getPhases(STAGE_REFERENCE);
+    }
+
+    public List<String> getServicePhases() {
+        return getPhases(STAGE_SERVICE);
+    }
+
+    public List<String> getImplementationPhases() {
+        return getPhases(STAGE_IMPLEMENTATION);
+    }
+
+    public List<String> getAllPhases() {
+        if (phases == null) {
+            phases = new ArrayList<String>();
+            phases.addAll(getReferencePhases());
+            phases.addAll(getServicePhases());
+            phases.addAll(getImplementationPhases());
+        }
+        return phases;
+    }
+
     public synchronized Map<String, Stage> getStages() {
         if (stages != null) {
             return stages;
         }
-        stages = new HashMap<String, Stage>();
-        for (String s : STAGES) {
-            stages.put(s, new Stage(s));
-        }
+        init();
+
         Set<ServiceDeclaration> services;
         try {
-            services = ServiceDiscovery.getInstance().getServiceDeclarations(PhaseManager.class);
+            services = ServiceDiscovery.getInstance().getServiceDeclarations(pattern);
         } catch (IOException e) {
             throw new ServiceRuntimeException(e);
         }
@@ -155,16 +186,22 @@
                 }
             }
             graph.addVertext(name);
+            if(firstSet.size()>1) {
+                log.warning("More than one phases are declared to be first: "+firstSet);
+            }
             for (String s : firstSet) {
                 for (String v : new HashSet<String>(graph.getVertices().keySet())) {
-                    if (!v.equals(s)) {
+                    if (!firstSet.contains(v)) {
                         graph.addEdge(s, v);
                     }
                 }
             }
+            if(lastSet.size()>1) {
+                log.warning("More than one phases are declared to be the last: "+lastSet);
+            }
             for (String s : lastSet) {
                 for (String v : new HashSet<String>(graph.getVertices().keySet())) {
-                    if (!v.equals(s)) {
+                    if (!lastSet.contains(v)) {
                         graph.addEdge(v, s);
                     }
                 }
@@ -183,4 +220,28 @@
         return stages;
     }
 
+    private void init() {
+        stages = new HashMap<String, Stage>();
+
+        Stage referenceStage = new Stage(STAGE_REFERENCE);
+        for (int i = 1; i < SYSTEM_REFERENCE_PHASES.length; i++) {
+            referenceStage.getSorter().addEdge(SYSTEM_REFERENCE_PHASES[i - 1], SYSTEM_REFERENCE_PHASES[i]);
+        }
+        referenceStage.getLastSet().add(Phase.REFERENCE_BINDING);
+        stages.put(referenceStage.getName(), referenceStage);
+
+        Stage serviceStage = new Stage(STAGE_SERVICE);
+        for (int i = 1; i < SYSTEM_SERVICE_PHASES.length; i++) {
+            serviceStage.getSorter().addEdge(SYSTEM_SERVICE_PHASES[i - 1], SYSTEM_SERVICE_PHASES[i]);
+        }
+        stages.put(serviceStage.getName(), serviceStage);
+
+        Stage implementationStage = new Stage(STAGE_IMPLEMENTATION);
+        for (int i = 1; i < SYSTEM_IMPLEMENTATION_PHASES.length; i++) {
+            implementationStage.getSorter().addEdge(SYSTEM_IMPLEMENTATION_PHASES[i - 1],
+                                                    SYSTEM_IMPLEMENTATION_PHASES[i]);
+        }
+        implementationStage.getLastSet().add(Phase.IMPLEMENTATION);
+        stages.put(implementationStage.getName(), implementationStage);
+    }
 }

Added: incubator/tuscany/java/sca/modules/core/src/test/java/org/apache/tuscany/sca/core/invocation/PhaseManagerTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core/src/test/java/org/apache/tuscany/sca/core/invocation/PhaseManagerTestCase.java?rev=632064&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/core/src/test/java/org/apache/tuscany/sca/core/invocation/PhaseManagerTestCase.java (added)
+++ incubator/tuscany/java/sca/modules/core/src/test/java/org/apache/tuscany/sca/core/invocation/PhaseManagerTestCase.java Thu Feb 28 09:18:51 2008
@@ -0,0 +1,51 @@
+/*
+ * 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.sca.core.invocation;
+
+import java.util.List;
+
+import junit.framework.Assert;
+
+import org.junit.Test;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class PhaseManagerTestCase {
+
+    @Test
+    public void testDiscovery() {
+        PhaseManager pm = new PhaseManager("org.apache.tuscany.sca.invocation.PhaseTest");
+        List<String> phases = pm.getAllPhases();
+        System.out.println(phases.size());
+        System.out.println(phases);
+        Assert.assertEquals(15, phases.size());
+        Assert.assertEquals("reference.first", phases.get(0));
+
+        int rt = phases.indexOf("reference.transaction");
+        Assert.assertTrue(rt > phases.indexOf("reference.interface"));
+
+        int st = phases.indexOf("service.transaction");
+        Assert.assertTrue(st > phases.indexOf("service.binding"));
+
+        int it = phases.indexOf("implementation.transaction");
+        Assert.assertTrue(it < phases.indexOf("implementation.policies"));
+    }
+}

Propchange: incubator/tuscany/java/sca/modules/core/src/test/java/org/apache/tuscany/sca/core/invocation/PhaseManagerTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/core/src/test/java/org/apache/tuscany/sca/core/invocation/PhaseManagerTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/tuscany/java/sca/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/InvocationChainImplTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/InvocationChainImplTestCase.java?rev=632064&r1=632063&r2=632064&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/InvocationChainImplTestCase.java (original)
+++ incubator/tuscany/java/sca/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/InvocationChainImplTestCase.java Thu Feb 28 09:18:51 2008
@@ -27,6 +27,7 @@
 import org.apache.tuscany.sca.invocation.InvocationChain;
 import org.apache.tuscany.sca.invocation.Invoker;
 import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.invocation.Phase;
 
 /**
  * @version $Rev$ $Date$
@@ -34,7 +35,8 @@
 public class InvocationChainImplTestCase extends TestCase {
 
     public void testInsertAtEnd() throws Exception {
-        InvocationChain chain = new InvocationChainImpl(newOperation("foo"));
+        Operation op = newOperation("foo");
+        InvocationChain chain = new InvocationChainImpl(op, op, true);
         Interceptor inter2 = new MockInterceptor();
         Interceptor inter1 = new MockInterceptor();
         chain.addInterceptor(inter1);
@@ -44,6 +46,25 @@
         assertEquals(inter2, head.getNext());
         assertEquals(inter2, chain.getTailInvoker());
 
+    }
+
+    public void testAddByPhase() throws Exception {
+        Operation op = newOperation("foo");
+        InvocationChain chain = new InvocationChainImpl(op, op, false);
+        Interceptor inter1 = new MockInterceptor();
+        Interceptor inter2 = new MockInterceptor();
+        Interceptor inter3 = new MockInterceptor();
+        Interceptor inter4 = new MockInterceptor();
+        chain.addInterceptor(inter3); // SERVICE
+        chain.addInterceptor(Phase.IMPLEMENTATION_POLICY, inter4);
+        chain.addInterceptor(Phase.SERVICE_POLICY, inter2);
+        chain.addInterceptor(Phase.SERVICE_BINDING, inter1);
+        Interceptor head = (Interceptor)chain.getHeadInvoker();
+        assertEquals(inter1, head);
+        assertEquals(inter2, inter1.getNext());
+        assertEquals(inter3, inter2.getNext());
+        assertEquals(inter4, inter3.getNext());
+        assertEquals(inter4, chain.getTailInvoker());
     }
 
     private class MockInterceptor implements Interceptor {

Added: incubator/tuscany/java/sca/modules/core/src/test/resources/META-INF/services/org.apache.tuscany.sca.invocation.PhaseTest
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core/src/test/resources/META-INF/services/org.apache.tuscany.sca.invocation.PhaseTest?rev=632064&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/core/src/test/resources/META-INF/services/org.apache.tuscany.sca.invocation.PhaseTest (added)
+++ incubator/tuscany/java/sca/modules/core/src/test/resources/META-INF/services/org.apache.tuscany.sca.invocation.PhaseTest Thu Feb 28 09:18:51 2008
@@ -0,0 +1,5 @@
+name=implementation.last, stage=implementation, after=*
+name=reference.first, stage=reference, before=*
+name=reference.transaction, stage=reference, after=reference.interface
+name=service.transaction, stage=service, after=service.binding
+name=implementation.transaction, stage=implementation, before=implementation.policies
\ No newline at end of file

Modified: incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaCallbackRuntimeWireProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaCallbackRuntimeWireProcessor.java?rev=632064&r1=632063&r2=632064&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaCallbackRuntimeWireProcessor.java (original)
+++ incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaCallbackRuntimeWireProcessor.java Thu Feb 28 09:18:51 2008
@@ -32,6 +32,7 @@
 import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
 import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
 import org.apache.tuscany.sca.invocation.InvocationChain;
+import org.apache.tuscany.sca.invocation.Phase;
 import org.apache.tuscany.sca.runtime.EndpointReference;
 import org.apache.tuscany.sca.runtime.RuntimeComponent;
 import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
@@ -78,7 +79,7 @@
             if (!supportsCallbackInterface(iface, javaImpl)) {
                 // callback to this impl is not possible, so ensure a callback object is set
                 for (InvocationChain chain : wire.getInvocationChains()) {
-                    chain.addInterceptor(0, new CallbackInterfaceInterceptor());
+                    chain.addInterceptor(Phase.REFERENCE, new CallbackInterfaceInterceptor());
                 }
             }
         }

Modified: incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaPolicyHandlingRuntimeWireProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaPolicyHandlingRuntimeWireProcessor.java?rev=632064&r1=632063&r2=632064&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaPolicyHandlingRuntimeWireProcessor.java (original)
+++ incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaPolicyHandlingRuntimeWireProcessor.java Thu Feb 28 09:18:51 2008
@@ -22,12 +22,12 @@
 import java.util.ArrayList;
 import java.util.List;
 
+import org.apache.tuscany.sca.assembly.ComponentReference;
 import org.apache.tuscany.sca.assembly.ConfiguredOperation;
 import org.apache.tuscany.sca.assembly.OperationsConfigurator;
 import org.apache.tuscany.sca.implementation.java.JavaImplementation;
-import org.apache.tuscany.sca.invocation.Interceptor;
 import org.apache.tuscany.sca.invocation.InvocationChain;
-import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.invocation.Phase;
 import org.apache.tuscany.sca.policy.PolicySet;
 import org.apache.tuscany.sca.policy.PolicySetAttachPoint;
 import org.apache.tuscany.sca.policy.util.PolicyHandler;
@@ -103,16 +103,12 @@
                         }
                         
                         if ( !applicablePolicyHandlers.isEmpty() ) {
-                            int index = 0;
-                            Invoker invoker = chain.getHeadInvoker();
-                            while ( invoker != chain.getTailInvoker()) {
-                                if ( invoker instanceof Interceptor ) {
-                                    invoker = ((Interceptor)invoker).getNext();
-                                    ++index;
-                                }
-                            }
-                            chain.addInterceptor(index, new PolicyHandlingInterceptor(chain.getTargetOperation(),
-                                                                                  applicablePolicyHandlers));
+                            String phase =
+                                (wire.getSource().getContract() instanceof ComponentReference)
+                                    ? Phase.REFERENCE_POLICY : Phase.SERVICE_POLICY;
+
+                            chain.addInterceptor(phase, new PolicyHandlingInterceptor(chain.getTargetOperation(),
+                                                                                      applicablePolicyHandlers));
                         }
                     }
                 } catch ( Exception e ) {

Modified: incubator/tuscany/java/sca/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/TransactionRuntimeWireProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/TransactionRuntimeWireProcessor.java?rev=632064&r1=632063&r2=632064&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/TransactionRuntimeWireProcessor.java (original)
+++ incubator/tuscany/java/sca/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/TransactionRuntimeWireProcessor.java Thu Feb 28 09:18:51 2008
@@ -21,9 +21,10 @@
 
 import org.apache.tuscany.sca.assembly.Binding;
 import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.ComponentReference;
 import org.apache.tuscany.sca.assembly.Reference;
-import org.apache.tuscany.sca.interfacedef.Operation;
 import org.apache.tuscany.sca.invocation.InvocationChain;
+import org.apache.tuscany.sca.invocation.Phase;
 import org.apache.tuscany.sca.policy.PolicySet;
 import org.apache.tuscany.sca.policy.PolicySetAttachPoint;
 import org.apache.tuscany.sca.runtime.RuntimeWire;
@@ -66,11 +67,15 @@
             }
         }
         for (InvocationChain chain : wire.getInvocationChains()) {
-            Operation operation = chain.getSourceOperation();
+            // Operation operation = chain.getSourceOperation();
 
             TransactionInterceptor interceptor =
                 new TransactionInterceptor(helper, outbound, interactionPolicy, implementationPolicy);
-            chain.addInterceptor(0, interceptor);
+            String phase =
+                (wire.getSource().getContract() instanceof ComponentReference) ? Phase.REFERENCE_POLICY
+                    : Phase.SERVICE_POLICY;
+
+            chain.addInterceptor(phase, interceptor);
         }
 
     }



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