You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by gn...@apache.org on 2008/09/16 14:45:29 UTC

svn commit: r695836 - in /servicemix/components/shared-libraries/trunk: servicemix-common/ servicemix-common/src/main/java/org/apache/servicemix/common/ servicemix-common/src/main/java/org/apache/servicemix/common/endpoints/ servicemix-common/src/main/...

Author: gnodet
Date: Tue Sep 16 05:45:27 2008
New Revision: 695836

URL: http://svn.apache.org/viewvc?rev=695836&view=rev
Log:
SM-1576: Change endpoints lifecycle to use activate / start / stop / deactivate

Added:
    servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/DefaultServiceUnit.java
    servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/endpoints/AbstractEndpoint.java
    servicemix/components/shared-libraries/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/SoapExchangeProcessor.java
Modified:
    servicemix/components/shared-libraries/trunk/servicemix-common/pom.xml
    servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/AbstractDeployer.java
    servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/AsyncBaseLifeCycle.java
    servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/BaseComponent.java
    servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/BaseServiceUnitManager.java
    servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/DefaultBootstrap.java
    servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/DefaultComponent.java
    servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/Endpoint.java
    servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/EndpointDeliveryChannel.java
    servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/ExchangeProcessor.java
    servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/Registry.java
    servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/ServiceMixComponent.java
    servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/ServiceUnit.java
    servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/endpoints/ConsumerEndpoint.java
    servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/endpoints/ProviderEndpoint.java
    servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/endpoints/SimpleEndpoint.java
    servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/osgi/EndpointTracker.java
    servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/wsdl1/AbstractWsdl1Deployer.java
    servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/XBeanServiceUnit.java
    servicemix/components/shared-libraries/trunk/servicemix-common/src/test/java/org/apache/servicemix/common/TransactionsTest.java
    servicemix/components/shared-libraries/trunk/servicemix-common/src/test/java/org/apache/servicemix/common/xbean/XBeanEndpoint.java
    servicemix/components/shared-libraries/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/SoapEndpoint.java

Modified: servicemix/components/shared-libraries/trunk/servicemix-common/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/components/shared-libraries/trunk/servicemix-common/pom.xml?rev=695836&r1=695835&r2=695836&view=diff
==============================================================================
--- servicemix/components/shared-libraries/trunk/servicemix-common/pom.xml (original)
+++ servicemix/components/shared-libraries/trunk/servicemix-common/pom.xml Tue Sep 16 05:45:27 2008
@@ -139,6 +139,18 @@
       <scope>test</scope>
     </dependency>
     <dependency>
+      <groupId>org.apache.activemq</groupId>
+      <artifactId>activemq-core</artifactId>
+      <version>${activemq-version}</version>
+      <scope>test</scope>
+      <exclusions>
+        <exclusion>
+          <groupId>org.apache.camel</groupId>
+          <artifactId>camel-core</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+    <dependency>
       <groupId>org.apache.felix</groupId>
       <artifactId>org.osgi.core</artifactId>
       <version>1.0.0</version>

Modified: servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/AbstractDeployer.java
URL: http://svn.apache.org/viewvc/servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/AbstractDeployer.java?rev=695836&r1=695835&r2=695836&view=diff
==============================================================================
--- servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/AbstractDeployer.java (original)
+++ servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/AbstractDeployer.java Tue Sep 16 05:45:27 2008
@@ -49,7 +49,7 @@
         // is shutdown but may need a cleanup.
         try {
             su.shutDown();
-        } catch (JBIException e) {
+        } catch (Exception e) {
             throw new DeploymentException("Unable to shutDown service unit", e);
         }
     }

Modified: servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/AsyncBaseLifeCycle.java
URL: http://svn.apache.org/viewvc/servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/AsyncBaseLifeCycle.java?rev=695836&r1=695835&r2=695836&view=diff
==============================================================================
--- servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/AsyncBaseLifeCycle.java (original)
+++ servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/AsyncBaseLifeCycle.java Tue Sep 16 05:45:27 2008
@@ -18,6 +18,8 @@
 
 import java.lang.reflect.Method;
 import java.util.Map;
+import java.util.Set;
+import java.util.HashSet;
 
 import javax.jbi.JBIException;
 import javax.jbi.component.ComponentContext;
@@ -81,19 +83,19 @@
 
     protected boolean workManagerCreated;
 
-    protected Map<String, ExchangeProcessor> processors;
-    
     protected ThreadLocal<String> correlationId;
     
     protected String currentState = LifeCycleMBean.UNKNOWN;
 
     protected Container container;
 
+    protected Map<String, Set<String>> knownExchanges;
+
     public AsyncBaseLifeCycle() {
         this.running = new AtomicBoolean(false);
         this.polling = new AtomicBoolean(false);
-        this.processors = new ConcurrentHashMap<String, ExchangeProcessor>();
         this.correlationId = new ThreadLocal<String>();
+        this.knownExchanges = new ConcurrentHashMap<String, Set<String>>();
     }
 
     public AsyncBaseLifeCycle(ServiceMixComponent component) {
@@ -190,12 +192,12 @@
                 // JBI implementation which throws an exception instead of
                 // return null
             }
+            container = Container.detect(context);
             doInit();
             setCurrentState(INITIALIZED);
             if (logger.isDebugEnabled()) {
                 logger.debug("Component initialized");
             }
-            container = Container.detect(context);
         } catch (JBIException e) {
             throw e;
         } catch (Exception e) {
@@ -532,44 +534,37 @@
             boolean dynamic = false;
             ServiceEndpoint endpoint = exchange.getEndpoint();
             String key = EndpointSupport.getKey(exchange.getEndpoint());
-            Endpoint ep = (Endpoint) this.component.getRegistry().getEndpoint(key);
+            Endpoint ep = this.component.getRegistry().getEndpoint(key);
             if (ep == null) {
                 if (endpoint.getServiceName().equals(getEPRServiceName())) {
                     ep = getResolvedEPR(exchange.getEndpoint());
+                    ep.activate();
+                    ep.start();
                     dynamic = true;
                 }
                 if (ep == null) {
                     throw new IllegalStateException("Endpoint not found: " + key);
                 }
             }
-            ExchangeProcessor processor = ep.getProcessor();
-            if (processor == null) {
-                throw new IllegalStateException("No processor found for endpoint: " + key);
-            }
             try {
-                doProcess(ep, processor, exchange);
+                doProcess(ep, exchange);
             } finally {
                 // If the endpoint is dynamic, deactivate it
                 if (dynamic) {
+                    ep.stop();
                     ep.deactivate();
                 }
             }
         } else {
-            ExchangeProcessor processor = null;
             Endpoint ep = null;
             if (exchange.getProperty(JbiConstants.SENDER_ENDPOINT) != null) {
                 String key = exchange.getProperty(JbiConstants.SENDER_ENDPOINT).toString();
-                ep = (Endpoint) this.component.getRegistry().getEndpoint(key);
-                if (ep != null) {
-                    processor = ep.getProcessor();
-                }
-            } else {
-                processor = processors.remove(exchange.getExchangeId());
+                ep = this.component.getRegistry().getEndpoint(key);
             }
-            if (processor == null) {
-                throw new IllegalStateException("No processor found for: " + exchange.getExchangeId());
+            if (ep == null) {
+                throw new IllegalStateException("Endpoint not found for: " + exchange.getExchangeId());
             }
-            doProcess(ep, processor, exchange);
+            doProcess(ep, exchange);
         }
 
     }
@@ -579,8 +574,9 @@
      * classloader is used where available
      * 
      */
-    private void doProcess(Endpoint ep, ExchangeProcessor processor, MessageExchange exchange) throws Exception {
+    private void doProcess(Endpoint ep, MessageExchange exchange) throws Exception {
         ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
+        boolean processed = false;
         try {
             ClassLoader cl = (ep != null) ? ep.getServiceUnit().getConfigurationClassLoader() : null;
             if (cl != null) {
@@ -596,8 +592,13 @@
                 logger.debug("Retrieved correlation id: " + correlationID);
             }
             EndpointDeliveryChannel.setEndpoint(ep);
-            processor.process(exchange);
+            handleExchange(ep, exchange, exchange.getStatus() == ExchangeStatus.ACTIVE);
+            ep.process(exchange);
+            processed = true;
         } finally {
+            if (!processed) {
+                handleExchange(ep, exchange, false);
+            }
             EndpointDeliveryChannel.setEndpoint(null);
             Thread.currentThread().setContextClassLoader(oldCl);
             // Clean the threadlocal variable
@@ -629,8 +630,7 @@
                 }
             }
             // Set the sender endpoint property
-            String key = EndpointSupport.getKey(endpoint);
-            exchange.setProperty(JbiConstants.SENDER_ENDPOINT, key);
+            exchange.setProperty(JbiConstants.SENDER_ENDPOINT, endpoint.getKey());
         }
         // Handle transaction
         if (!container.handleTransactions()) {
@@ -646,26 +646,42 @@
         }
     }
 
-    @Deprecated
-    public void sendConsumerExchange(MessageExchange exchange, ExchangeProcessor processor) throws MessagingException {
-        if (exchange.getStatus() == ExchangeStatus.ACTIVE) {
-            processors.put(exchange.getExchangeId(), processor);
+    public void prepareShutdown(Endpoint endpoint) throws InterruptedException {
+        Set<String> exchanges = getKnownExchanges(endpoint);
+        synchronized (exchanges) {
+            if (!exchanges.isEmpty()) {
+                exchanges.wait();
+            }
         }
-        channel.send(exchange);
     }
 
-    @Deprecated
-    public void prepareConsumerExchange(MessageExchange exchange, Endpoint endpoint) throws MessagingException {
-        prepareExchange(exchange, endpoint);
+    protected Set<String> getKnownExchanges(Endpoint endpoint) {
+        Set<String> exchanges = knownExchanges.get(endpoint.getKey());
+        if (exchanges == null) {
+            synchronized (knownExchanges) {
+                exchanges = knownExchanges.get(endpoint.getKey());
+                if (exchanges == null) {
+                    exchanges = new HashSet<String>();
+                    knownExchanges.put(endpoint.getKey(), exchanges);
+                }
+            }
+        }
+        return exchanges;
     }
 
-    @Deprecated
-    public void sendConsumerExchange(MessageExchange exchange, Endpoint endpoint) throws MessagingException {
-        prepareExchange(exchange, endpoint);
-        channel.send(exchange);
+    public void handleExchange(Endpoint endpoint, MessageExchange exchange, boolean add) {
+        Set<String> exchanges = getKnownExchanges(endpoint);
+        synchronized (exchanges) {
+            if (add) {
+                exchanges.add(exchange.getExchangeId());
+            } else {
+                exchanges.remove(exchange.getExchangeId());
+            }
+            exchanges.notifyAll();
+        }
     }
 
-    /**
+   /**
      * Handle an exchange sent to an EPR resolved by this component
      * 
      * @param ep the service endpoint

Modified: servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/BaseComponent.java
URL: http://svn.apache.org/viewvc/servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/BaseComponent.java?rev=695836&r1=695835&r2=695836&view=diff
==============================================================================
--- servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/BaseComponent.java (original)
+++ servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/BaseComponent.java Tue Sep 16 05:45:27 2008
@@ -203,16 +203,6 @@
         return null;
     }
 
-    @Deprecated
-    public void prepareConsumerExchange(MessageExchange exchange, Endpoint endpoint) throws MessagingException {
-        lifeCycle.prepareConsumerExchange(exchange, endpoint);
-    }
-
-    @Deprecated
-    public void sendConsumerExchange(MessageExchange exchange, Endpoint endpoint) throws MessagingException {
-        lifeCycle.sendConsumerExchange(exchange, endpoint);
-    }
-    
     public Container getContainer() {
         return lifeCycle.getContainer();
     }

Modified: servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/BaseServiceUnitManager.java
URL: http://svn.apache.org/viewvc/servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/BaseServiceUnitManager.java?rev=695836&r1=695835&r2=695836&view=diff
==============================================================================
--- servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/BaseServiceUnitManager.java (original)
+++ servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/BaseServiceUnitManager.java Tue Sep 16 05:45:27 2008
@@ -95,6 +95,7 @@
      * @see javax.jbi.component.ServiceUnitManager#init(java.lang.String, java.lang.String)
      */
     public synchronized void init(String serviceUnitName, String serviceUnitRootPath) throws DeploymentException {
+        ClassLoader cl = Thread.currentThread().getContextClassLoader();
         try {
             if (logger.isDebugEnabled()) {
                 logger.debug("Initializing service unit");
@@ -102,9 +103,10 @@
             if (serviceUnitName == null || serviceUnitName.length() == 0) {
                 throw new IllegalArgumentException("serviceUnitName should be non null and non empty");
             }
-            if (getServiceUnit(serviceUnitName) == null) {
+            ServiceUnit su = getServiceUnit(serviceUnitName);
+            if (su == null) {
                 if (!persistent) {
-                    ServiceUnit su = doDeploy(serviceUnitName, serviceUnitRootPath);
+                    su = doDeploy(serviceUnitName, serviceUnitRootPath);
                     if (su == null) {
                         throw failure("deploy", "Unable to find suitable deployer for Service Unit '" + serviceUnitName + "'", null);
                     }
@@ -113,7 +115,11 @@
                     throw failure("init", "Service Unit '" + serviceUnitName + "' is not deployed", null);
                 }
             }
-            doInit(serviceUnitName, serviceUnitRootPath);
+            if (!LifeCycleMBean.SHUTDOWN.equals(su.getCurrentState())) {
+                throw failure("init", "ServiceUnit should be in a SHUTDOWN state", null);
+            }
+            Thread.currentThread().setContextClassLoader(su.getConfigurationClassLoader());
+            su.init();
             if (logger.isDebugEnabled()) {
                 logger.debug("Service unit initialized");
             }
@@ -121,12 +127,11 @@
             throw e;
         } catch (Exception e) {
             throw failure("init", "Unable to init service unit", e);
+        } finally {
+            Thread.currentThread().setContextClassLoader(cl);
         }
     }
 
-    protected void doInit(String serviceUnitName, String serviceUnitRootPath) throws Exception {
-    }
-
     /* (non-Javadoc)
      * @see javax.jbi.component.ServiceUnitManager#start(java.lang.String)
      */
@@ -143,9 +148,8 @@
             if (su == null) {
                 throw failure("start", "Service Unit '" + serviceUnitName + "' is not deployed", null);
             }
-            if (!LifeCycleMBean.STOPPED.equals(su.getCurrentState()) &&
-                !LifeCycleMBean.SHUTDOWN.equals(su.getCurrentState())) {
-                throw failure("start", "ServiceUnit should be in a SHUTDOWN or STOPPED state", null);
+            if (!LifeCycleMBean.STOPPED.equals(su.getCurrentState())) {
+                throw failure("start", "ServiceUnit should be in a STOPPED state", null);
             }
             Thread.currentThread().setContextClassLoader(su.getConfigurationClassLoader());
             su.start();
@@ -173,12 +177,12 @@
             if (serviceUnitName == null || serviceUnitName.length() == 0) {
                 throw new IllegalArgumentException("serviceUnitName should be non null and non empty");
             }
-            ServiceUnit su = (ServiceUnit) getServiceUnit(serviceUnitName);
+            ServiceUnit su = getServiceUnit(serviceUnitName);
             if (su == null) {
                 throw failure("stop", "Service Unit '" + serviceUnitName + "' is not deployed", null);
             }
             if (!LifeCycleMBean.STARTED.equals(su.getCurrentState())) {
-                throw failure("stop", "ServiceUnit should be in a SHUTDOWN state", null);
+                throw failure("stop", "ServiceUnit should be in a STARTED state", null);
             }
             Thread.currentThread().setContextClassLoader(su.getConfigurationClassLoader());
             su.stop();
@@ -206,10 +210,13 @@
             if (serviceUnitName == null || serviceUnitName.length() == 0) {
                 throw new IllegalArgumentException("serviceUnitName should be non null and non empty");
             }
-            ServiceUnit su = (ServiceUnit) getServiceUnit(serviceUnitName);
+            ServiceUnit su = getServiceUnit(serviceUnitName);
             if (su == null) {
                 throw failure("shutDown", "Service Unit '" + serviceUnitName + "' is not deployed", null);
             }
+            if (!LifeCycleMBean.STOPPED.equals(su.getCurrentState())) {
+                throw failure("start", "ServiceUnit should be in a STOPPED state", null);
+            }
             Thread.currentThread().setContextClassLoader(su.getConfigurationClassLoader());
             su.shutDown();
             if (logger.isDebugEnabled()) {
@@ -239,7 +246,7 @@
             if (serviceUnitName == null || serviceUnitName.length() == 0) {
                 throw new IllegalArgumentException("serviceUnitName should be non null and non empty");
             }
-            ServiceUnit su = (ServiceUnit) getServiceUnit(serviceUnitName);
+            ServiceUnit su = getServiceUnit(serviceUnitName);
             if (su == null) {
                 throw failure("undeploy", "Service Unit '" + serviceUnitName + "' is not deployed", null);
             }

Modified: servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/DefaultBootstrap.java
URL: http://svn.apache.org/viewvc/servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/DefaultBootstrap.java?rev=695836&r1=695835&r2=695836&view=diff
==============================================================================
--- servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/DefaultBootstrap.java (original)
+++ servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/DefaultBootstrap.java Tue Sep 16 05:45:27 2008
@@ -27,7 +27,8 @@
  * 
  * This is a default implementation of the Bootstrap,  it is used by the 
  * Maven JBI plugin to provide a standard implementation of a Bootstrap
- * when a component does not provide one
+ * when a component does not provide one, so even it is tagged as deprecated,
+ * it should not be removed.
  * 
  * @deprecated Due to JBI classloader mechanism, component should not
  *    use this class directly, but copy it, or rely on the maven-jbi-plugin

Modified: servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/DefaultComponent.java
URL: http://svn.apache.org/viewvc/servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/DefaultComponent.java?rev=695836&r1=695835&r2=695836&view=diff
==============================================================================
--- servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/DefaultComponent.java (original)
+++ servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/DefaultComponent.java Tue Sep 16 05:45:27 2008
@@ -56,9 +56,10 @@
         setComponent(this);
         registry = createRegistry();
         serviceUnitManager = createServiceUnitManager();
-        serviceUnit = new XBeanServiceUnit();
-        serviceUnit.setName("#default#");
-        serviceUnit.setComponent(this);
+        XBeanServiceUnit su = new XBeanServiceUnit();
+        su.setName("#default#");
+        su.setComponent(this);
+        serviceUnit = su;
         registry.registerServiceUnit(serviceUnit);
     }
 
@@ -344,6 +345,7 @@
                 addEndpoint(endpoint);
             }
         }
+        serviceUnit.init();
     }
 
     /* (non-Javadoc)

Added: servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/DefaultServiceUnit.java
URL: http://svn.apache.org/viewvc/servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/DefaultServiceUnit.java?rev=695836&view=auto
==============================================================================
--- servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/DefaultServiceUnit.java (added)
+++ servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/DefaultServiceUnit.java Tue Sep 16 05:45:27 2008
@@ -0,0 +1,229 @@
+/*
+ * 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.servicemix.common;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.jbi.JBIException;
+import javax.jbi.management.DeploymentException;
+import javax.jbi.management.LifeCycleMBean;
+
+public class DefaultServiceUnit implements ServiceUnit {
+
+    protected ServiceMixComponent component;
+
+    protected String name;
+
+    protected String rootPath;
+
+    protected String status = LifeCycleMBean.SHUTDOWN;
+
+    protected Map<String, Endpoint> endpoints = new LinkedHashMap<String, Endpoint>();
+
+    public DefaultServiceUnit() {
+    }
+
+    public DefaultServiceUnit(ServiceMixComponent component) {
+        this.component = component;
+    }
+
+    public synchronized void init() throws Exception {
+        if (this.status == LifeCycleMBean.SHUTDOWN) {
+            // Activate endpoints
+            List<Endpoint> activated = new ArrayList<Endpoint>();
+            try {
+                for (Endpoint endpoint : getEndpoints()) {
+                    endpoint.activate();
+                    activated.add(endpoint);
+                }
+                this.status = LifeCycleMBean.STOPPED;
+            } catch (Exception e) {
+                // Deactivate activated endpoints
+                for (Endpoint endpoint : activated) {
+                    try {
+                        endpoint.deactivate();
+                    } catch (Exception e2) {
+                        // do nothing
+                    }
+                }
+                throw e;
+            }
+        }
+    }
+
+    public synchronized void start() throws Exception {
+        if (this.status == LifeCycleMBean.STOPPED) {
+            // Activate endpoints
+            List<Endpoint> activated = new ArrayList<Endpoint>();
+            try {
+                for (Endpoint endpoint : getEndpoints()) {
+                    endpoint.start();
+                }
+                this.status = LifeCycleMBean.STARTED;
+            } catch (Exception e) {
+                // Deactivate activated endpoints
+                for (Endpoint endpoint : activated) {
+                    try {
+                        endpoint.stop();
+                    } catch (Exception e2) {
+                        // do nothing
+                    }
+                }
+                throw e;
+            }
+        }
+    }
+
+    public synchronized void stop() throws Exception {
+        if (this.status == LifeCycleMBean.STARTED) {
+            this.status = LifeCycleMBean.STOPPED;
+            // Stop endpoints
+            Exception exception = null;
+            for (Endpoint endpoint : getEndpoints()) {
+                try {
+                    endpoint.stop();
+                } catch (Exception e) {
+                    exception = e;
+                }
+            }
+            if (exception != null) {
+                throw exception;
+            }
+        }
+    }
+
+    public synchronized void shutDown() throws Exception {
+        if (this.status == LifeCycleMBean.STARTED) {
+            stop();
+        }
+        if (this.status == LifeCycleMBean.STOPPED) {
+            this.status = LifeCycleMBean.SHUTDOWN;
+            // Deactivate endpoints
+            Exception exception = null;
+            for (Endpoint endpoint : getEndpoints()) {
+                try {
+                    // TODO: uncomment when all tests in various components work fine
+                    // TODO: we also need to find a way to not wait forever on this call
+                    //component.prepareShutdown(endpoint);
+                    endpoint.deactivate();
+                } catch (Exception e) {
+                    exception = e;
+                }
+            }
+            if (exception != null) {
+                throw exception;
+            }
+        }
+    }
+
+    public String getCurrentState() {
+        return status;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getRootPath() {
+        return rootPath;
+    }
+
+    public void setRootPath(String rootPath) {
+        this.rootPath = rootPath;
+    }
+
+    /**
+     * @return Returns the component.
+     */
+    public ServiceMixComponent getComponent() {
+        return component;
+    }
+
+    /**
+     * @param component
+     *            The component to set.
+     */
+    public void setComponent(ServiceMixComponent component) {
+        this.component = component;
+    }
+
+    public Collection<Endpoint> getEndpoints() {
+        return this.endpoints.values();
+    }
+
+    public synchronized void addEndpoint(Endpoint endpoint) throws DeploymentException {
+        String key = endpoint.getKey();
+        if (this.endpoints.put(key, endpoint) != null) {
+            throw new DeploymentException(
+                    "More than one endpoint found in the SU for key: " + key);
+        }
+        if (this.status == LifeCycleMBean.STOPPED) {
+            try {
+                endpoint.activate();
+            } catch (Exception e) {
+                throw new DeploymentException(e);
+            }
+        } else if (this.status == LifeCycleMBean.STARTED) {
+            try {
+                endpoint.activate();
+                endpoint.start();
+            } catch (Exception e) {
+                throw new DeploymentException(e);
+            }
+        }
+    }
+
+    public synchronized void removeEndpoint(Endpoint endpoint) throws DeploymentException {
+        String key = endpoint.getKey();
+        if (this.endpoints.remove(key) == null) {
+            throw new DeploymentException("Endpoint not found in the SU for key: " + EndpointSupport.getKey(endpoint));
+        }
+        if (this.status == LifeCycleMBean.STOPPED) {
+            try {
+                component.prepareShutdown(endpoint);
+                endpoint.deactivate();
+            } catch (Exception e) {
+                throw new DeploymentException(e);
+            }
+        } else if (this.status == LifeCycleMBean.STARTED) {
+            try {
+                endpoint.stop();
+                component.prepareShutdown(endpoint);
+                endpoint.deactivate();
+            } catch (Exception e) {
+                throw new DeploymentException(e);
+            }
+        }
+    }
+
+    public Endpoint getEndpoint(String key) {
+        return this.endpoints.get(key);
+    }
+
+    public ClassLoader getConfigurationClassLoader() {
+        return component.getClass().getClassLoader();
+    }
+
+}

Modified: servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/Endpoint.java
URL: http://svn.apache.org/viewvc/servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/Endpoint.java?rev=695836&r1=695835&r2=695836&view=diff
==============================================================================
--- servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/Endpoint.java (original)
+++ servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/Endpoint.java Tue Sep 16 05:45:27 2008
@@ -17,6 +17,8 @@
 package org.apache.servicemix.common;
 
 import org.apache.commons.logging.Log;
+import org.apache.servicemix.common.xbean.XBeanServiceUnit;
+
 import org.w3c.dom.Document;
 
 import javax.jbi.management.DeploymentException;
@@ -26,168 +28,72 @@
 import javax.wsdl.Definition;
 import javax.xml.namespace.QName;
 
-public abstract class Endpoint {
+public interface Endpoint {
 
-    protected QName service;
-    protected String endpoint;
-    protected QName interfaceName;
-    protected Document description;
-    protected Definition definition;
-    protected ServiceUnit serviceUnit;
-    protected Log logger;
-    private String key;
+    String getKey();
 
-    public Endpoint() {
-    }
+    QName getInterfaceName();
 
-    public Endpoint(ServiceUnit serviceUnit, QName service, String endpoint) {
-        this.serviceUnit = serviceUnit;
-        this.logger = serviceUnit.getComponent().getLogger();
-        this.service = service;
-        this.endpoint = endpoint;
-    }
+    QName getService();
 
-    /**
-     * @return Returns the endpoint.
-     */
-    public String getEndpoint() {
-        return endpoint;
-    }
+    String getEndpoint();
 
-    /**
-     * Sets the name of the endpoint.
-     * 
-     * @param endpoint a string specifiying the name of the endpoint
-     * @org.apache.xbean.Property description="the name of the endpoint"
-     */
-    public void setEndpoint(String endpoint) {
-        this.endpoint = endpoint;
-        this.key = null;
-    }
+    Document getDescription();
 
-    /**
-     * @return Returns the service.
-     */
-    public QName getService() {
-        return service;
-    }
+    Role getRole();
 
-    /**
-     * Sets the name of the service the endpoint exposes.
-     * 
-     * @param service a QName specifiying the name of the service
-     * @org.apache.xbean.Property description="the QName of the service exposed by the endpoint"
-     */
-    public void setService(QName service) {
-        this.service = service;
-        this.key = null;
-    }
+    ServiceUnit getServiceUnit();
 
-    /**
-     * @return Returns the role.
-     */
-    public abstract Role getRole();
+    void setServiceUnit(ServiceUnit serviceUnit);
 
-    /**
-     * @return Returns the description.
-     */
-    public Document getDescription() {
-        return description;
-    }
+    boolean isExchangeOkay(MessageExchange exchange);
 
     /**
-     * Associates an XML document with the endpoint. The XML document describes the endpoint and is typically found in the service
-     * unit packaging.
-     * 
-     * @param description a <code>Document</code> describing the endpoint
-     * @org.apache.xbean.Property description="an XML document describing the endpoint"
+     * Register this endpoint into the NMR and put the endpoint
+     * in a STOPPED state, where the endpoint is able to process
+     * incoming requests, but won't consume external requests such
+     * as JMS messages or HTTP requests.
+     *
+     * @throws Exception
      */
-    public void setDescription(Document description) {
-        this.description = description;
-    }
+    void activate() throws Exception;
 
     /**
-     * @return Returns the interfaceName.
+     * Start consumption of external requests.
+     *
+     * @throws Exception
      */
-    public QName getInterfaceName() {
-        return interfaceName;
-    }
+    void start() throws Exception;
 
     /**
-     * Sets the QName of the interface exposed by the endpoint.
-     * 
-     * @param interfaceName a QName specifiying the name of the interface
-     * @org.apache.xbean.Property description="the QName of the interface exposed by the endpoint"
+     * Stop consumption of external requests.
+     *
+     * @throws Exception
      */
-    public void setInterfaceName(QName interfaceName) {
-        this.interfaceName = interfaceName;
-    }
+    void stop() throws Exception;
 
     /**
-     * @return Returns the serviceUnit.
+     * Unregister this endpoint from the NMR.
+     *
+     * @throws Exception
      */
-    public ServiceUnit getServiceUnit() {
-        return serviceUnit;
-    }
+    void deactivate() throws Exception;
 
     /**
-     * Associates an endpoint with a service unit. The service unit is used by the container to manage the endpoint's lifecycle.
-     * 
-     * @param serviceUnit a <code>ServiceUnit</code> to which the endpoint will be associated
-     * @org.apache.xbean.Property description="the service unit responsible for the endpoint"
+     * Process an incoming JBI exchange.
+     *
+     * @param exchange
+     * @throws Exception
      */
-    public void setServiceUnit(ServiceUnit serviceUnit) {
-        this.serviceUnit = serviceUnit;
-        this.logger = serviceUnit.component.getLogger();
-    }
-
-    public boolean isExchangeOkay(MessageExchange exchange) {
-        // TODO: We could check the MEP here
-        return true;
-    }
-
-    public void prepareExchange(MessageExchange exchange) throws MessagingException {
-        getServiceUnit().getComponent().prepareExchange(exchange, this);
-    }
-
-    public abstract void activate() throws Exception;
-
-    public abstract void deactivate() throws Exception;
-
-    public abstract ExchangeProcessor getProcessor();
-
-    public String toString() {
-        return "Endpoint[service: " + service + ", " + "endpoint: " + endpoint + ", " + "role: "
-               + (getRole() == Role.PROVIDER ? "provider" : "consumer") + "]";
-    }
+    void process(MessageExchange exchange) throws Exception;
 
     /**
-     * Validate the endpoint at either deployment time for statically defined endpoints or at runtime for dynamic endpoints
-     * 
+     * Validation is a step which is done at deployment time to check
+     * that the endpoint definition is valid and that there is no
+     * missing properties.
+     *
      * @throws DeploymentException
      */
-    public void validate() throws DeploymentException {
-    }
-
-    public Definition getDefinition() {
-        return definition;
-    }
-
-    public void setDefinition(Definition definition) {
-        this.definition = definition;
-    }
-
-    String getKey() {
-        if (key == null) {
-            if (service == null) {
-                throw new IllegalArgumentException("Endpoint: " + this + " has no service name defined");
-            }
-            if (endpoint == null) {
-                throw new IllegalArgumentException("Endpoint: " + this + " has no endpoint name defined");
-            }
-            key = EndpointSupport.getKey(service, endpoint);
-        }
-        return key;
-    }
+    void validate() throws DeploymentException;
 
 }

Modified: servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/EndpointDeliveryChannel.java
URL: http://svn.apache.org/viewvc/servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/EndpointDeliveryChannel.java?rev=695836&r1=695835&r2=695836&view=diff
==============================================================================
--- servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/EndpointDeliveryChannel.java (original)
+++ servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/EndpointDeliveryChannel.java Tue Sep 16 05:45:27 2008
@@ -18,11 +18,10 @@
 
 import javax.jbi.component.ComponentContext;
 import javax.jbi.messaging.DeliveryChannel;
-import javax.jbi.messaging.ExchangeStatus;
 import javax.jbi.messaging.MessageExchange;
-import javax.jbi.messaging.MessageExchange.Role;
 import javax.jbi.messaging.MessageExchangeFactory;
 import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.ExchangeStatus;
 import javax.jbi.servicedesc.ServiceEndpoint;
 import javax.xml.namespace.QName;
 import javax.transaction.Transaction;
@@ -85,25 +84,46 @@
 
     public void send(MessageExchange exchange) throws MessagingException {
         prepareExchange(exchange);
+        handleExchange(exchange, exchange.getStatus() == ExchangeStatus.ACTIVE);
         channel.send(exchange);
     }
 
     public boolean sendSync(MessageExchange exchange, long timeout) throws MessagingException {
-        prepareExchange(exchange);
-        boolean ret = channel.sendSync(exchange, timeout);
-        if (ret) {
-            resumeTx(exchange);
+        boolean processed = false;
+        try {
+            prepareExchange(exchange);
+            handleExchange(exchange, exchange.getStatus() == ExchangeStatus.ACTIVE);
+            boolean ret = channel.sendSync(exchange, timeout);
+            handleExchange(exchange, exchange.getStatus() == ExchangeStatus.ACTIVE);
+            if (ret) {
+                resumeTx(exchange);
+                processed = true;
+            }
+            return ret;
+        } finally {
+            if (!processed) {
+                handleExchange(exchange, false);
+            }
         }
-        return ret;
     }
 
     public boolean sendSync(MessageExchange exchange) throws MessagingException {
-        prepareExchange(exchange);
-        boolean ret = channel.sendSync(exchange);
-        if (ret) {
-            resumeTx(exchange);
+        boolean processed = false;
+        try {
+            prepareExchange(exchange);
+            handleExchange(exchange, exchange.getStatus() == ExchangeStatus.ACTIVE);
+            boolean ret = channel.sendSync(exchange);
+            handleExchange(exchange, exchange.getStatus() == ExchangeStatus.ACTIVE);
+            if (ret) {
+                resumeTx(exchange);
+                processed = true;
+            }
+            return ret;
+        } finally {
+            if (!processed) {
+                handleExchange(exchange, false);
+            }
         }
-        return ret;
     }
 
     private void resumeTx(MessageExchange exchange) throws MessagingException {
@@ -123,7 +143,13 @@
     }
 
     protected void prepareExchange(MessageExchange exchange) throws MessagingException {
-        getEndpoint().prepareExchange(exchange);
+        Endpoint ep = getEndpoint();
+        ep.getServiceUnit().getComponent().prepareExchange(exchange, ep);
+    }
+
+    protected void handleExchange(MessageExchange exchange, boolean add) throws MessagingException {
+        Endpoint ep = getEndpoint();
+        ep.getServiceUnit().getComponent().handleExchange(ep, exchange, add);
     }
 
     protected Endpoint getEndpoint() {

Modified: servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/ExchangeProcessor.java
URL: http://svn.apache.org/viewvc/servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/ExchangeProcessor.java?rev=695836&r1=695835&r2=695836&view=diff
==============================================================================
--- servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/ExchangeProcessor.java (original)
+++ servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/ExchangeProcessor.java Tue Sep 16 05:45:27 2008
@@ -18,6 +18,7 @@
 
 import javax.jbi.messaging.MessageExchange;
 
+@Deprecated
 public interface ExchangeProcessor {
 
     void process(MessageExchange exchange) throws Exception;

Modified: servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/Registry.java
URL: http://svn.apache.org/viewvc/servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/Registry.java?rev=695836&r1=695835&r2=695836&view=diff
==============================================================================
--- servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/Registry.java (original)
+++ servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/Registry.java Tue Sep 16 05:45:27 2008
@@ -50,31 +50,29 @@
     }
     
     public void registerEndpoint(Endpoint ep) {
-        String key = EndpointSupport.getKey(ep);
+        String key = ep.getKey();
         if (this.endpoints.put(key, ep) != null) {
             throw new IllegalStateException("An endpoint is already registered for key: " + key);
         }
     }
     
     public void unregisterEndpoint(Endpoint ep) {
-        this.endpoints.remove(EndpointSupport.getKey(ep));
+        this.endpoints.remove(ep.getKey());
     }
     
     public void registerServiceUnit(ServiceUnit su) {
         this.serviceUnits.put(su.getName(), su);
-        Collection endpoints = (Collection) su.getEndpoints();
-        for (Iterator iter = endpoints.iterator(); iter.hasNext();) {
-            Endpoint ep = (Endpoint) iter.next();
-            registerEndpoint(ep);
+        Collection<Endpoint> endpoints = su.getEndpoints();
+        for (Endpoint endpoint : endpoints) {
+            registerEndpoint(endpoint);
         }
     }
     
     public void unregisterServiceUnit(ServiceUnit su) {
         this.serviceUnits.remove(su.getName());
-        Collection endpoints = (Collection) su.getEndpoints();
-        for (Iterator iter = endpoints.iterator(); iter.hasNext();) {
-            Endpoint ep = (Endpoint) iter.next();
-            unregisterEndpoint(ep);
+        Collection<Endpoint> endpoints = su.getEndpoints();
+        for (Endpoint endpoint : endpoints) {
+            unregisterEndpoint(endpoint);
         }
     }
     

Modified: servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/ServiceMixComponent.java
URL: http://svn.apache.org/viewvc/servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/ServiceMixComponent.java?rev=695836&r1=695835&r2=695836&view=diff
==============================================================================
--- servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/ServiceMixComponent.java (original)
+++ servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/ServiceMixComponent.java Tue Sep 16 05:45:27 2008
@@ -78,11 +78,24 @@
      */
     public void prepareExchange(MessageExchange exchange, Endpoint endpoint) throws MessagingException;
 
-    @Deprecated
-    public void prepareConsumerExchange(MessageExchange exchange, Endpoint endpoint) throws MessagingException;
+    /**
+     * Prepare shutting the given endpoint down by waiting for all know exchanges for
+     * this endpoint to be fully processed.
+     *
+     * @param endpoint
+     * @throws InterruptedException
+     */
+    public void prepareShutdown(Endpoint endpoint) throws InterruptedException;
 
-    @Deprecated
-    public void sendConsumerExchange(MessageExchange exchange, Endpoint endpoint) throws MessagingException;
+    /**
+     * Make the component aware of this exchange.
+     * This method needs to be called for each exchange sent or received.
+     *
+     * @param endpoint
+     * @param exchange
+     * @param add
+     */
+    public void handleExchange(Endpoint endpoint, MessageExchange exchange, boolean add);
 
     /**
      * @return the QName of the element used in EPR

Modified: servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/ServiceUnit.java
URL: http://svn.apache.org/viewvc/servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/ServiceUnit.java?rev=695836&r1=695835&r2=695836&view=diff
==============================================================================
--- servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/ServiceUnit.java (original)
+++ servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/ServiceUnit.java Tue Sep 16 05:45:27 2008
@@ -16,151 +16,117 @@
  */
 package org.apache.servicemix.common;
 
-import java.util.ArrayList;
 import java.util.Collection;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
 
-import javax.jbi.JBIException;
 import javax.jbi.management.DeploymentException;
-import javax.jbi.management.LifeCycleMBean;
 
-public class ServiceUnit {
+/**
+ * This interface defines the lifecycle and needed
+ * methods to a collection of endpoints grouped into
+ * a service unit.
+ */
+public interface ServiceUnit {
+
+    /**
+     * Retrieves the name of this service unit.
+     *
+     * @return
+     */
+    String getName();
+
+    /**
+     * Retrieves the root path of this service unit.
+     * @return
+     */
+    String getRootPath();
+
+    /**
+     * Retrieves the component where this SU is deployed.
+     *
+     * @return
+     */
+    ServiceMixComponent getComponent();
 
-    protected ServiceMixComponent component;
+    /**
+     * Retrieves the list of deployed endpoints.
+     *
+     * @return
+     */
+    Collection<Endpoint> getEndpoints();
 
-    protected String name;
+    /**
+     * Retrieve this service unit specific classloader.
+     *
+     * @return
+     */
+    ClassLoader getConfigurationClassLoader();
 
-    protected String rootPath;
-
-    protected String status = LifeCycleMBean.SHUTDOWN;
-
-    protected Map<String, Endpoint> endpoints = new LinkedHashMap<String, Endpoint>();
-
-    public ServiceUnit() {
-    }
-
-    public ServiceUnit(ServiceMixComponent component) {
-        this.component = component;
-    }
-
-    public synchronized void start() throws Exception {
-        // Activate endpoints
-        List<Endpoint> activated = new ArrayList<Endpoint>();
-        try {
-            for (Endpoint endpoint : getEndpoints()) {
-                endpoint.activate();
-                activated.add(endpoint);
-            }
-            this.status = LifeCycleMBean.STARTED;
-        } catch (Exception e) {
-            // Deactivate activated endpoints
-            for (Endpoint endpoint : activated) {
-                try {
-                    endpoint.deactivate();
-                } catch (Exception e2) {
-                    // do nothing
-                }
-            }
-            throw e;
-        }
-    }
-
-    public synchronized void stop() throws Exception {
-        this.status = LifeCycleMBean.STOPPED;
-        // Deactivate endpoints
-        Exception exception = null;
-        for (Endpoint endpoint : getEndpoints()) {
-            try {
-                endpoint.deactivate();
-            } catch (Exception e) {
-                exception = e;
-            }
-        }
-        if (exception != null) {
-            throw exception;
-        }
-    }
-
-    public synchronized void shutDown() throws JBIException {
-        this.status = LifeCycleMBean.SHUTDOWN;
-    }
-
-    public String getCurrentState() {
-        return status;
-    }
-
-    public String getName() {
-        return name;
-    }
-
-    public void setName(String name) {
-        this.name = name;
-    }
-	
-    public String getRootPath() {
-        return rootPath;
-    }
-
-    public void setRootPath(String rootPath) {
-        this.rootPath = rootPath;
-    }
-
-    /**
-     * @return Returns the component.
-     */
-    public ServiceMixComponent getComponent() {
-        return component;
-    }
-
-    /**
-     * @param component
-     *            The component to set.
-     */
-    public void setComponent(ServiceMixComponent component) {
-        this.component = component;
-    }
-
-    public Collection<Endpoint> getEndpoints() {
-        return this.endpoints.values();
-    }
-
-    public synchronized void addEndpoint(Endpoint endpoint) throws DeploymentException {
-        String key = EndpointSupport.getKey(endpoint);
-        if (this.endpoints.put(key, endpoint) != null) {
-            throw new DeploymentException(
-                    "More than one endpoint found in the SU for key: " + key);
-        }
-        if (this.status == LifeCycleMBean.STARTED) {
-            try {
-                endpoint.activate();
-            } catch (Exception e) {
-                throw new DeploymentException(e);
-            }
-        }
-    }
-
-    public synchronized void removeEndpoint(Endpoint endpoint) throws DeploymentException {
-        String key = EndpointSupport.getKey(endpoint);
-        if (this.endpoints.remove(key) == null) {
-            throw new DeploymentException("Endpoint not found in the SU for key: " + EndpointSupport.getKey(endpoint));
-        }
-        if (this.status == LifeCycleMBean.STARTED) {
-            try {
-                endpoint.deactivate();
-            } catch (Exception e) {
-                throw new DeploymentException(e);
-            }
-        }
-    }
-
-    public Endpoint getEndpoint(String key) {
-        return this.endpoints.get(key);
-    }
-
-    public ClassLoader getConfigurationClassLoader() {
-        return component.getClass().getClassLoader();
-    }
+    /**
+     * Retrieve the state of this service unit.
+     * States can be: STOPPED, STARTED or SHUTDOWN
+     *
+     * @return
+     */
+    String getCurrentState();
+
+    /**
+     * Puts the SU in a STOPPED state.
+     * This call is only valid if the service unit is in a SHUTDOWN state.
+     * It means it is able to process incoming exchange but will not
+     * initiate new exchanges. The process of initializing a service unit
+     * should activate all endpoints, but not start them.
+     *
+     * @throws Exception
+     * @see Endpoint#start()
+     */
+    void init() throws Exception;
+
+    /**
+     * Transition this service unit into the STARTED state.
+     * This call is only valid if the service unit is in a STOPPED state.
+     * Start consumption of external requests by starting all
+     * the endpoints.
+     *
+     * @throws Exception
+     * @see Endpoint#start()
+     */
+    void start() throws Exception;
+
+    /**
+     * Transition this service unit to a STOPPED state.
+     * This call is only valid if the service unit is in a STARTED state.
+     *
+     * @throws Exception
+     * @see Endpoint#stop()
+     */
+    void stop() throws Exception;
+
+    /**
+     * Transition this service unit into the SHUTDOWN state.
+     * This call is only valid if the service unit is in a STOPPED state.
+
+     * @throws Exception
+     * @see Endpoint#deactivate()
+     */
+    void shutDown() throws Exception;
+
+    /**
+     * Adds an endpoint to this service unit.
+     * Adding an endpoint will transition this endpoint into a state
+     * which is consistent with this service unit state.
+     *
+     * @param ep
+     * @throws DeploymentException
+     */
+    void addEndpoint(Endpoint ep) throws DeploymentException;
+
+    /**
+     * Removes an endpoint from this service unit.
+     * Removing an endpoint will transition it into the SHUTDOWN state.
+     *
+     * @param ep
+     * @throws DeploymentException
+     */
+    void removeEndpoint(Endpoint ep) throws DeploymentException;
 
 }

Added: servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/endpoints/AbstractEndpoint.java
URL: http://svn.apache.org/viewvc/servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/endpoints/AbstractEndpoint.java?rev=695836&view=auto
==============================================================================
--- servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/endpoints/AbstractEndpoint.java (added)
+++ servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/endpoints/AbstractEndpoint.java Tue Sep 16 05:45:27 2008
@@ -0,0 +1,201 @@
+/*
+ * 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.servicemix.common.endpoints;
+
+import org.apache.commons.logging.Log;
+import org.apache.servicemix.common.ServiceUnit;
+import org.apache.servicemix.common.Endpoint;
+import org.apache.servicemix.common.EndpointSupport;
+
+import org.w3c.dom.Document;
+
+import javax.jbi.management.DeploymentException;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.MessageExchange.Role;
+import javax.wsdl.Definition;
+import javax.xml.namespace.QName;
+
+public abstract class AbstractEndpoint implements Endpoint {
+
+    protected QName service;
+    protected String endpoint;
+    protected QName interfaceName;
+    protected Document description;
+    protected Definition definition;
+    protected ServiceUnit serviceUnit;
+    protected Log logger;
+    private String key;
+
+    public AbstractEndpoint() {
+    }
+
+    public AbstractEndpoint(ServiceUnit serviceUnit, QName service, String endpoint) {
+        this.serviceUnit = serviceUnit;
+        this.logger = serviceUnit.getComponent().getLogger();
+        this.service = service;
+        this.endpoint = endpoint;
+    }
+
+    /**
+     * @return Returns the endpoint.
+     */
+    public String getEndpoint() {
+        return endpoint;
+    }
+
+    /**
+     * Sets the name of the endpoint.
+     *
+     * @param endpoint a string specifiying the name of the endpoint
+     * @org.apache.xbean.Property description="the name of the endpoint"
+     */
+    public void setEndpoint(String endpoint) {
+        this.endpoint = endpoint;
+        this.key = null;
+    }
+
+    /**
+     * @return Returns the service.
+     */
+    public QName getService() {
+        return service;
+    }
+
+    /**
+     * Sets the name of the service the endpoint exposes.
+     *
+     * @param service a QName specifiying the name of the service
+     * @org.apache.xbean.Property description="the QName of the service exposed by the endpoint"
+     */
+    public void setService(QName service) {
+        this.service = service;
+        this.key = null;
+    }
+
+    /**
+     * @return Returns the role.
+     */
+    public abstract Role getRole();
+
+    /**
+     * @return Returns the description.
+     */
+    public Document getDescription() {
+        return description;
+    }
+
+    /**
+     * Associates an XML document with the endpoint. The XML document describes the endpoint and is typically found in the service
+     * unit packaging.
+     *
+     * @param description a <code>Document</code> describing the endpoint
+     * @org.apache.xbean.Property description="an XML document describing the endpoint"
+     */
+    public void setDescription(Document description) {
+        this.description = description;
+    }
+
+    /**
+     * @return Returns the interfaceName.
+     */
+    public QName getInterfaceName() {
+        return interfaceName;
+    }
+
+    /**
+     * Sets the QName of the interface exposed by the endpoint.
+     *
+     * @param interfaceName a QName specifiying the name of the interface
+     * @org.apache.xbean.Property description="the QName of the interface exposed by the endpoint"
+     */
+    public void setInterfaceName(QName interfaceName) {
+        this.interfaceName = interfaceName;
+    }
+
+    /**
+     * @return Returns the serviceUnit.
+     */
+    public ServiceUnit getServiceUnit() {
+        return serviceUnit;
+    }
+
+    /**
+     * Associates an endpoint with a service unit. The service unit is used by the container to manage the endpoint's lifecycle.
+     *
+     * @param serviceUnit a <code>ServiceUnit</code> to which the endpoint will be associated
+     * @org.apache.xbean.Property description="the service unit responsible for the endpoint"
+     */
+    public void setServiceUnit(ServiceUnit serviceUnit) {
+        this.serviceUnit = serviceUnit;
+        this.logger = serviceUnit.getComponent().getLogger();
+    }
+
+    public boolean isExchangeOkay(MessageExchange exchange) {
+        // TODO: We could check the MEP here
+        return true;
+    }
+
+    public void prepareExchange(MessageExchange exchange) throws MessagingException {
+        getServiceUnit().getComponent().prepareExchange(exchange, this);
+    }
+
+    public abstract void activate() throws Exception;
+
+    public abstract void start() throws Exception;
+
+    public abstract void stop() throws Exception;
+
+    public abstract void deactivate() throws Exception;
+
+    public abstract void process(MessageExchange exchange) throws Exception;
+
+    public String toString() {
+        return "Endpoint[service: " + service + ", " + "endpoint: " + endpoint + ", " + "role: "
+               + (getRole() == Role.PROVIDER ? "provider" : "consumer") + "]";
+    }
+
+    /**
+     * Validate the endpoint at either deployment time for statically defined endpoints or at runtime for dynamic endpoints
+     *
+     * @throws DeploymentException
+     */
+    public void validate() throws DeploymentException {
+    }
+
+    public Definition getDefinition() {
+        return definition;
+    }
+
+    public void setDefinition(Definition definition) {
+        this.definition = definition;
+    }
+
+    public String getKey() {
+        if (key == null) {
+            if (service == null) {
+                throw new IllegalArgumentException("Endpoint: " + this + " has no service name defined");
+            }
+            if (endpoint == null) {
+                throw new IllegalArgumentException("Endpoint: " + this + " has no endpoint name defined");
+            }
+            key = EndpointSupport.getKey(service, endpoint);
+        }
+        return key;
+    }
+
+}

Modified: servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/endpoints/ConsumerEndpoint.java
URL: http://svn.apache.org/viewvc/servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/endpoints/ConsumerEndpoint.java?rev=695836&r1=695835&r2=695836&view=diff
==============================================================================
--- servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/endpoints/ConsumerEndpoint.java (original)
+++ servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/endpoints/ConsumerEndpoint.java Tue Sep 16 05:45:27 2008
@@ -53,7 +53,8 @@
         return Role.CONSUMER;
     }
 
-    public synchronized void start() throws Exception {
+    public synchronized void activate() throws Exception {
+        super.activate();
         ServiceMixComponent component = getServiceUnit().getComponent();
         ComponentContext ctx = component.getComponentContext();
         activated = new ExternalEndpoint(component.getEPRElementName(), getLocationURI(), getService(),
@@ -61,7 +62,7 @@
         ctx.registerExternalEndpoint(activated);
     }
 
-    public synchronized void stop() throws Exception {
+    public synchronized void deactivate() throws Exception {
         ServiceMixComponent component = getServiceUnit().getComponent();
         ComponentContext ctx = component.getComponentContext();
         if (activated != null) {
@@ -69,6 +70,7 @@
             activated = null;
             ctx.deregisterExternalEndpoint(se);
         }
+        super.deactivate();
     }
 
     /**

Modified: servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/endpoints/ProviderEndpoint.java
URL: http://svn.apache.org/viewvc/servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/endpoints/ProviderEndpoint.java?rev=695836&r1=695835&r2=695836&view=diff
==============================================================================
--- servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/endpoints/ProviderEndpoint.java (original)
+++ servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/endpoints/ProviderEndpoint.java Tue Sep 16 05:45:27 2008
@@ -53,12 +53,13 @@
         return Role.PROVIDER;
     }
 
-    public void start() throws Exception {
+    public void activate() throws Exception {
+        super.activate();
         ComponentContext ctx = getServiceUnit().getComponent().getComponentContext();
         activated = ctx.activateEndpoint(service, endpoint);
     }
 
-    public void stop() throws Exception {
+    public void deactivate() throws Exception {
         if (activated == null) {
             throw new IllegalStateException("Endpoint not activated: " + this);
         }
@@ -66,6 +67,7 @@
         activated = null;
         ComponentContext ctx = getServiceUnit().getComponent().getComponentContext();
         ctx.deactivateEndpoint(ep);
+        super.deactivate();
     }
 
     /**

Modified: servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/endpoints/SimpleEndpoint.java
URL: http://svn.apache.org/viewvc/servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/endpoints/SimpleEndpoint.java?rev=695836&r1=695835&r2=695836&view=diff
==============================================================================
--- servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/endpoints/SimpleEndpoint.java (original)
+++ servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/endpoints/SimpleEndpoint.java Tue Sep 16 05:45:27 2008
@@ -28,10 +28,9 @@
 import org.apache.servicemix.common.DefaultComponent;
 import org.apache.servicemix.common.Endpoint;
 import org.apache.servicemix.common.EndpointComponentContext;
-import org.apache.servicemix.common.ExchangeProcessor;
 import org.apache.servicemix.common.ServiceUnit;
 
-public abstract class SimpleEndpoint extends Endpoint implements ExchangeProcessor {
+public abstract class SimpleEndpoint extends AbstractEndpoint {
 
     private DeliveryChannel channel;
     private MessageExchangeFactory exchangeFactory;
@@ -52,15 +51,15 @@
         context = new EndpointComponentContext(this);
         channel = context.getDeliveryChannel();
         exchangeFactory = channel.createExchangeFactory();
-        start();
     }
 
     public synchronized void deactivate() throws Exception {
-        stop();
     }
-    
-    public ExchangeProcessor getProcessor() {
-        return this;
+
+    public synchronized void start() throws Exception {
+    }
+
+    public synchronized void stop() throws Exception {
     }
 
     protected void send(MessageExchange me) throws MessagingException {

Modified: servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/osgi/EndpointTracker.java
URL: http://svn.apache.org/viewvc/servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/osgi/EndpointTracker.java?rev=695836&r1=695835&r2=695836&view=diff
==============================================================================
--- servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/osgi/EndpointTracker.java (original)
+++ servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/osgi/EndpointTracker.java Tue Sep 16 05:45:27 2008
@@ -24,6 +24,7 @@
 import org.apache.servicemix.common.Endpoint;
 import org.apache.servicemix.common.DefaultComponent;
 import org.apache.servicemix.common.ServiceUnit;
+import org.apache.servicemix.common.DefaultServiceUnit;
 import org.apache.servicemix.id.IdGenerator;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -92,7 +93,7 @@
         }
     }
 
-    public static class OsgiServiceUnit extends ServiceUnit {
+    public static class OsgiServiceUnit extends DefaultServiceUnit {
         private static final IdGenerator idGenerator = new IdGenerator();
         private final Endpoint endpoint;
         private final ClassLoader classLoader;

Modified: servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/wsdl1/AbstractWsdl1Deployer.java
URL: http://svn.apache.org/viewvc/servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/wsdl1/AbstractWsdl1Deployer.java?rev=695836&r1=695835&r2=695836&view=diff
==============================================================================
--- servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/wsdl1/AbstractWsdl1Deployer.java (original)
+++ servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/wsdl1/AbstractWsdl1Deployer.java Tue Sep 16 05:45:27 2008
@@ -17,9 +17,11 @@
 package org.apache.servicemix.common.wsdl1;
 
 import org.apache.servicemix.common.AbstractDeployer;
-import org.apache.servicemix.common.Endpoint;
 import org.apache.servicemix.common.ServiceMixComponent;
 import org.apache.servicemix.common.ServiceUnit;
+import org.apache.servicemix.common.DefaultServiceUnit;
+import org.apache.servicemix.common.endpoints.AbstractEndpoint;
+
 import org.w3c.dom.Document;
 
 import javax.jbi.management.DeploymentException;
@@ -66,10 +68,7 @@
         if (wsdls == null || wsdls.length == 0) {
             throw failure("deploy", "No wsdl found", null);
         }
-        ServiceUnit su = createServiceUnit();
-        su.setComponent(component);
-        su.setName(serviceUnitName);
-        su.setRootPath(serviceUnitRootPath);
+        ServiceUnit su = createServiceUnit(serviceUnitName, serviceUnitRootPath);
         for (int i = 0; i < wsdls.length; i++) {
             initFromWsdl(su, wsdls[i]);
         }
@@ -128,7 +127,7 @@
                     if (bindingElement == null) {
                         throw failure("deploy", "Invalid wsdl " + wsdl + ": no matching binding element found", null);
                     }
-                    Endpoint ep = createEndpoint(portElement, bindingElement, jbiEndpoint);
+                    AbstractEndpoint ep = createEndpoint(portElement, bindingElement, jbiEndpoint);
                     if (ep != null) {
                         ep.setServiceUnit(su);
                         ep.setDescription(description);
@@ -158,11 +157,15 @@
         JbiExtension.register(registry);
     }
 
-    protected ServiceUnit createServiceUnit() {
-        return new ServiceUnit();
+    protected ServiceUnit createServiceUnit(String name, String rootPath) {
+        DefaultServiceUnit su = new DefaultServiceUnit();
+        su.setComponent(component);
+        su.setName(name);
+        su.setRootPath(rootPath);
+        return su;
     }
     
-    protected abstract Endpoint createEndpoint(ExtensibilityElement portElement,
+    protected abstract AbstractEndpoint createEndpoint(ExtensibilityElement portElement,
                                                ExtensibilityElement bindingElement,
                                                JbiEndpoint jbiEndpoint);
     

Modified: servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/XBeanServiceUnit.java
URL: http://svn.apache.org/viewvc/servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/XBeanServiceUnit.java?rev=695836&r1=695835&r2=695836&view=diff
==============================================================================
--- servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/XBeanServiceUnit.java (original)
+++ servicemix/components/shared-libraries/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/XBeanServiceUnit.java Tue Sep 16 05:45:27 2008
@@ -19,9 +19,10 @@
 import javax.jbi.JBIException;
 
 import org.apache.servicemix.common.ServiceUnit;
+import org.apache.servicemix.common.DefaultServiceUnit;
 import org.springframework.context.support.AbstractXmlApplicationContext;
 
-public class XBeanServiceUnit extends ServiceUnit {
+public class XBeanServiceUnit extends DefaultServiceUnit {
 
     private ClassLoader classLoader;
     private AbstractXmlApplicationContext applicationContext;
@@ -37,7 +38,7 @@
     /* (non-Javadoc)
      * @see org.apache.servicemix.common.ServiceUnit#shutDown()
      */
-    public void shutDown() throws JBIException {
+    public void shutDown() throws Exception {
         super.shutDown();
         classLoader = null;
         try {

Modified: servicemix/components/shared-libraries/trunk/servicemix-common/src/test/java/org/apache/servicemix/common/TransactionsTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/shared-libraries/trunk/servicemix-common/src/test/java/org/apache/servicemix/common/TransactionsTest.java?rev=695836&r1=695835&r2=695836&view=diff
==============================================================================
--- servicemix/components/shared-libraries/trunk/servicemix-common/src/test/java/org/apache/servicemix/common/TransactionsTest.java (original)
+++ servicemix/components/shared-libraries/trunk/servicemix-common/src/test/java/org/apache/servicemix/common/TransactionsTest.java Tue Sep 16 05:45:27 2008
@@ -171,17 +171,17 @@
             super();
         }
         protected void doInit() throws Exception {
-            super.doInit();
             TestEndpoint ep = new TestEndpoint();
             ep.setService(new QName("service"));
             ep.setEndpoint("endpoint");
             addEndpoint(ep);
+            super.doInit();
         }
         protected boolean exceptionShouldRollbackTx(Exception e) {
             return exceptionShouldRollback;
         }
 
-        protected class TestEndpoint extends ProviderEndpoint implements ExchangeProcessor {
+        protected class TestEndpoint extends ProviderEndpoint {
             protected ServiceEndpoint activated;
             public void process(MessageExchange exchange) throws Exception {
                 if (exceptionToThrow != null) {

Modified: servicemix/components/shared-libraries/trunk/servicemix-common/src/test/java/org/apache/servicemix/common/xbean/XBeanEndpoint.java
URL: http://svn.apache.org/viewvc/servicemix/components/shared-libraries/trunk/servicemix-common/src/test/java/org/apache/servicemix/common/xbean/XBeanEndpoint.java?rev=695836&r1=695835&r2=695836&view=diff
==============================================================================
--- servicemix/components/shared-libraries/trunk/servicemix-common/src/test/java/org/apache/servicemix/common/xbean/XBeanEndpoint.java (original)
+++ servicemix/components/shared-libraries/trunk/servicemix-common/src/test/java/org/apache/servicemix/common/xbean/XBeanEndpoint.java Tue Sep 16 05:45:27 2008
@@ -17,11 +17,11 @@
 package org.apache.servicemix.common.xbean;
 
 import javax.jbi.messaging.MessageExchange.Role;
+import javax.jbi.messaging.MessageExchange;
 
-import org.apache.servicemix.common.Endpoint;
-import org.apache.servicemix.common.ExchangeProcessor;
+import org.apache.servicemix.common.endpoints.AbstractEndpoint;
 
-public class XBeanEndpoint extends Endpoint {
+public class XBeanEndpoint extends AbstractEndpoint {
 
     private String prop;
     
@@ -42,11 +42,16 @@
     public void activate() throws Exception {
     }
 
+    public void start() throws Exception {
+    }
+
+    public void stop() throws Exception {
+    }
+
     public void deactivate() throws Exception {
     }
 
-    public ExchangeProcessor getProcessor() {
-        return null;
+    public void process(MessageExchange exchange) throws Exception {
     }
 
     public Role getRole() {

Modified: servicemix/components/shared-libraries/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/SoapEndpoint.java
URL: http://svn.apache.org/viewvc/servicemix/components/shared-libraries/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/SoapEndpoint.java?rev=695836&r1=695835&r2=695836&view=diff
==============================================================================
--- servicemix/components/shared-libraries/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/SoapEndpoint.java (original)
+++ servicemix/components/shared-libraries/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/SoapEndpoint.java Tue Sep 16 05:45:27 2008
@@ -25,6 +25,7 @@
 
 import javax.jbi.component.ComponentContext;
 import javax.jbi.messaging.MessageExchange.Role;
+import javax.jbi.messaging.MessageExchange;
 import javax.jbi.servicedesc.ServiceEndpoint;
 import javax.wsdl.Definition;
 import javax.wsdl.Import;
@@ -39,9 +40,8 @@
 import javax.wsdl.xml.WSDLWriter;
 import javax.xml.namespace.QName;
 
-import org.apache.servicemix.common.Endpoint;
-import org.apache.servicemix.common.ExchangeProcessor;
 import org.apache.servicemix.common.JbiConstants;
+import org.apache.servicemix.common.endpoints.AbstractEndpoint;
 import org.apache.servicemix.common.security.KeystoreManager;
 import org.apache.servicemix.common.security.AuthenticationService;
 import org.apache.servicemix.common.wsdl1.JbiExtension;
@@ -51,10 +51,10 @@
 
 import com.ibm.wsdl.Constants;
 
-public abstract class SoapEndpoint extends Endpoint {
+public abstract class SoapEndpoint extends AbstractEndpoint {
 
     protected ServiceEndpoint activated;
-    protected ExchangeProcessor processor;
+    protected SoapExchangeProcessor processor;
     protected Role role;
     protected URI defaultMep = JbiConstants.IN_OUT;
     protected boolean soap;
@@ -66,11 +66,17 @@
     protected String targetEndpoint;
     protected List policies;
     protected Map wsdls = new HashMap();
+    protected boolean dynamic;
     
     public SoapEndpoint() {
         policies = Collections.singletonList(new AddressingHandler());
     }
-    
+
+    public SoapEndpoint(boolean dynamic) {
+        this();
+        this.dynamic = dynamic;
+    }
+
     public AuthenticationService getAuthenticationService() {
         return null;
     }
@@ -325,42 +331,47 @@
     }
     
     /* (non-Javadoc)
-     * @see org.apache.servicemix.common.Endpoint#getProcessor()
-     */
-    public ExchangeProcessor getProcessor() {
-        return this.processor;
-    }
-
-    /* (non-Javadoc)
      * @see org.servicemix.common.Endpoint#activate()
      */
     public void activate() throws Exception {
-        ComponentContext ctx = this.serviceUnit.getComponent().getComponentContext();
-        loadWsdl();
-        if (getRole() == Role.PROVIDER) {
-            activated = ctx.activateEndpoint(service, endpoint);
-            processor = createProviderProcessor();
+        if (dynamic) {
+            if (getRole() == Role.PROVIDER) {
+                processor = createProviderProcessor();
+            } else {
+                processor = createConsumerProcessor();
+            }
         } else {
-            activated = createExternalEndpoint();
-            ctx.registerExternalEndpoint(activated);
-            processor = createConsumerProcessor();
+            ComponentContext ctx = this.serviceUnit.getComponent().getComponentContext();
+            loadWsdl();
+            if (getRole() == Role.PROVIDER) {
+                activated = ctx.activateEndpoint(service, endpoint);
+                processor = createProviderProcessor();
+            } else {
+                activated = createExternalEndpoint();
+                ctx.registerExternalEndpoint(activated);
+                processor = createConsumerProcessor();
+            }
         }
-        processor.start();
+        processor.init();
     }
     
-    public void activateDynamic() throws Exception {
-        if (getRole() == Role.PROVIDER) {
-            processor = createProviderProcessor();
-        } else {
-            processor = createConsumerProcessor();
-        }
+    public void start() throws Exception {
         processor.start();
     }
 
+    public void stop() throws Exception {
+        processor.stop();
+    }
+
+    public void process(MessageExchange exchange) throws Exception {
+        processor.process(exchange);
+    }
+
     /* (non-Javadoc)
      * @see org.servicemix.common.Endpoint#deactivate()
      */
     public void deactivate() throws Exception {
+        processor.shutdown();
         if (activated != null) {
             ComponentContext ctx = this.serviceUnit.getComponent().getComponentContext();
             if (getRole() == Role.PROVIDER) {
@@ -373,14 +384,13 @@
                 ctx.deregisterExternalEndpoint(ep);
             }
         }
-        processor.stop();
     }
 
     protected abstract void overrideDefinition(Definition def) throws Exception;
     
-    protected abstract ExchangeProcessor createProviderProcessor();
+    protected abstract SoapExchangeProcessor createProviderProcessor();
     
-    protected abstract ExchangeProcessor createConsumerProcessor();
+    protected abstract SoapExchangeProcessor createConsumerProcessor();
     
     protected abstract ServiceEndpoint createExternalEndpoint();
 

Added: servicemix/components/shared-libraries/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/SoapExchangeProcessor.java
URL: http://svn.apache.org/viewvc/servicemix/components/shared-libraries/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/SoapExchangeProcessor.java?rev=695836&view=auto
==============================================================================
--- servicemix/components/shared-libraries/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/SoapExchangeProcessor.java (added)
+++ servicemix/components/shared-libraries/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/SoapExchangeProcessor.java Tue Sep 16 05:45:27 2008
@@ -0,0 +1,33 @@
+/*
+ * 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.servicemix.soap;
+
+import javax.jbi.messaging.MessageExchange;
+
+public interface SoapExchangeProcessor {
+
+    void process(MessageExchange exchange) throws Exception;
+
+    void init() throws Exception;
+
+    void start() throws Exception;
+
+    void stop() throws Exception;
+
+    void shutdown() throws Exception;
+
+}