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 2007/08/27 23:51:29 UTC

svn commit: r570255 - in /incubator/servicemix/branches/servicemix-4.0: api/ api/src/main/java/org/apache/servicemix/api/ api/src/main/java/org/apache/servicemix/api/event/ api/src/main/java/org/apache/servicemix/api/internal/ api/src/main/java/org/apa...

Author: gnodet
Date: Mon Aug 27 14:51:27 2007
New Revision: 570255

URL: http://svn.apache.org/viewvc?rev=570255&view=rev
Log:
A few changes to the API (introduce event package, flows and internal api). Begin implementing it.

Added:
    incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/EndpointRegistry.java
    incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/NMR.java
    incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/event/
    incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/event/EndpointListener.java
    incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/event/ExchangeListener.java
    incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/event/Listener.java
    incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/event/ListenerRegistry.java
    incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/event/package.html
    incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/internal/
    incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/internal/Flow.java
    incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/internal/FlowRegistry.java
    incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/internal/InternalChannel.java
    incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/internal/InternalEndpoint.java
    incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/internal/InternalExchange.java
    incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/internal/InternalReference.java
    incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/internal/package.html
    incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/service/
    incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/service/ServiceRegistry.java
    incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/service/package.html
    incubator/servicemix/branches/servicemix-4.0/core/src/main/java/org/apache/servicemix/core/ChannelImpl.java
    incubator/servicemix/branches/servicemix-4.0/core/src/main/java/org/apache/servicemix/core/ClientChannel.java
    incubator/servicemix/branches/servicemix-4.0/core/src/main/java/org/apache/servicemix/core/EndpointRegistryImpl.java
    incubator/servicemix/branches/servicemix-4.0/core/src/main/java/org/apache/servicemix/core/FlowRegistryImpl.java
    incubator/servicemix/branches/servicemix-4.0/core/src/main/java/org/apache/servicemix/core/InternalEndpointWrapper.java
    incubator/servicemix/branches/servicemix-4.0/core/src/main/java/org/apache/servicemix/core/ListenerRegistryImpl.java
    incubator/servicemix/branches/servicemix-4.0/core/src/main/java/org/apache/servicemix/core/ReferenceImpl.java
    incubator/servicemix/branches/servicemix-4.0/core/src/main/java/org/apache/servicemix/core/ServiceMix.java
    incubator/servicemix/branches/servicemix-4.0/core/src/main/java/org/apache/servicemix/core/ServiceRegistryImpl.java
    incubator/servicemix/branches/servicemix-4.0/core/src/main/java/org/apache/servicemix/core/StraightThroughFlow.java
Removed:
    incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/EndpointConstants.java
    incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/Registry.java
    incubator/servicemix/branches/servicemix-4.0/core/src/main/java/org/apache/servicemix/core/AbstractEndpoint.java
Modified:
    incubator/servicemix/branches/servicemix-4.0/api/pom.xml
    incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/Channel.java
    incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/Endpoint.java
    incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/Exchange.java
    incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/Message.java
    incubator/servicemix/branches/servicemix-4.0/api/src/test/java/org/apache/servicemix/api/OsgiExample.java
    incubator/servicemix/branches/servicemix-4.0/core/pom.xml
    incubator/servicemix/branches/servicemix-4.0/core/src/main/java/org/apache/servicemix/core/ExchangeImpl.java

Modified: incubator/servicemix/branches/servicemix-4.0/api/pom.xml
URL: http://svn.apache.org/viewvc/incubator/servicemix/branches/servicemix-4.0/api/pom.xml?rev=570255&r1=570254&r2=570255&view=diff
==============================================================================
--- incubator/servicemix/branches/servicemix-4.0/api/pom.xml (original)
+++ incubator/servicemix/branches/servicemix-4.0/api/pom.xml Mon Aug 27 14:51:27 2007
@@ -37,13 +37,13 @@
 	<dependency>
 	  <groupId>junit</groupId>
 	  <artifactId>junit</artifactId>
-	  <version>4.3.1</version>
+	  <version>4.4</version>
 	  <scope>test</scope>
 	</dependency>
     <dependency>
       <groupId>org.apache.felix</groupId>
       <artifactId>org.osgi.core</artifactId>
-      <version>0.9.0-incubator-SNAPSHOT</version>
+      <version>1.0.0</version>
       <scope>test</scope>
     </dependency>
   </dependencies>

Modified: incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/Channel.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/Channel.java?rev=570255&r1=570254&r2=570255&view=diff
==============================================================================
--- incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/Channel.java (original)
+++ incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/Channel.java Mon Aug 27 14:51:27 2007
@@ -18,13 +18,13 @@
 
 /**
  * Creates a channel to perform invocations through the NMR.
- * Channels are created by the {@link Registry}.  They are used
+ * Channels are created by the {@link NMR}.  They are used
  * by {@link Endpoint}s to communicate with the NMR, but they
  * can also be used by external clients.  In such a case, the
  * Channel must be closed using the {@link #close()} method
  * after use.
  *
- * @see org.apache.servicemix.api.Registry#createChannel()
+ * @see org.apache.servicemix.api.NMR#createChannel()
  * @version $Revision: $
  * @since 4.0
  */

Modified: incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/Endpoint.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/Endpoint.java?rev=570255&r1=570254&r2=570255&view=diff
==============================================================================
--- incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/Endpoint.java (original)
+++ incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/Endpoint.java Mon Aug 27 14:51:27 2007
@@ -28,6 +28,14 @@
  */
 public interface Endpoint {
 
+    String ID = "ID";
+
+    String SERVICE_NAME = "SERVICE_NAME";
+
+    String ENDPOINT_NAME = "ENDPOINT_NAME";
+
+    String WSDL_URL = "WSDL_URL";
+
     /**
      * Set the channel so that the endpoint can send exchanges back
      * when they are processed or act as a consumer itself.
@@ -35,7 +43,7 @@
      * Such a channel does not need to be closed as the NMR will close it
      * automatically when the endpoint is unregistered.
      *
-     * @see Registry#register(Endpoint, java.util.Map)
+     * @see EndpointRegistry#register(Endpoint, java.util.Map)
      * @param channel the channel that this endpoint can use
      */
     void setChannel(Channel channel);

Added: incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/EndpointRegistry.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/EndpointRegistry.java?rev=570255&view=auto
==============================================================================
--- incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/EndpointRegistry.java (added)
+++ incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/EndpointRegistry.java Mon Aug 27 14:51:27 2007
@@ -0,0 +1,72 @@
+/*
+ * 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.api;
+
+import org.apache.servicemix.api.service.ServiceRegistry;
+
+import org.w3c.dom.Document;
+
+import java.util.Map;
+
+/**
+ * The Registry is used to register endpoints, unregister them, query endpoints
+ * and create a Channel to interfact with them.
+ *
+ * @version $Revision: $
+ * @since 4.0
+ */
+public interface EndpointRegistry extends ServiceRegistry<Endpoint> {
+
+    /**
+     * Register the given endpoint in the registry.
+     * In an OSGi world, this would be performed automatically by a ServiceTracker.
+     * Upon registration, a {@link Channel} will be injected onto the Endpoint using
+     * the {@link Endpoint#setChannel(Channel)} method.
+     *
+     * @param endpoint the endpoint to register
+     * @param properties the metadata associated with this endpoint
+     */
+    void register(Endpoint endpoint, Map<String, ?> properties);
+
+    /**
+     * Unregister a previously register enpoint.
+     * In an OSGi world, this would be performed automatically by a ServiceTracker.
+     *
+     * @param endpoint the endpoint to unregister
+     */
+    void unregister(Endpoint endpoint);
+
+    /**
+     * From a given amount of metadata which could include interface name, service name
+     * policy data and so forth, choose an available endpoint reference to use
+     * for invocations.
+     *
+     * This could return actual endpoints, or a dynamic proxy to a number of endpoints
+     */
+    Reference lookup(Map<String, ?> properties);
+
+    /**
+     * This methods creates a Reference from its xml representation.
+     *
+     * @see Reference#toXml()
+     * @param xml the xml document describing this reference
+     * @return a new Reference
+     */
+    Reference lookup(Document xml);
+
+}
+

Modified: incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/Exchange.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/Exchange.java?rev=570255&r1=570254&r2=570255&view=diff
==============================================================================
--- incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/Exchange.java (original)
+++ incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/Exchange.java Mon Aug 27 14:51:27 2007
@@ -238,15 +238,34 @@
     void setError(Exception error);
 
     /**
+     * Copy the given exchange to this one
+     * @param exchange the exchange to copy from
+     */
+    void copyFrom(Exchange exchange);
+
+    /**
+     * Duplicates this exchange and returns a new copy
+     *
+     * @return a copy of this exchange
+     */
+    Exchange copy();
+
+    /**
      * Make sure that all streams contained in the content and in
      * attachments are transformed to re-readable sources.
      * This method will be called by the framework when persisting
      * the exchange or when displaying it
+     *
+     * TODO: do we really need that?
      */
     void ensureReReadable();
 
-    void copyFrom(Exchange exchange);
-    Exchange copy();
+    /**
+     * TODO: is toString() sufficient 
+     *
+     * @param displayContent
+     * @return
+     */
     String display(boolean displayContent);
 
 

Modified: incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/Message.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/Message.java?rev=570255&r1=570254&r2=570255&view=diff
==============================================================================
--- incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/Message.java (original)
+++ incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/Message.java Mon Aug 27 14:51:27 2007
@@ -188,9 +188,12 @@
      * Make sure that all streams contained in the content and in
      * attachments are transformed to re-readable sources.
      * This method will be called by the framework when persisting
-     * the message or when displaying it
+     * the message or when displaying it.
+     *
+     * TODO: do we really need this method
      */
     void        ensureReReadable();
 
+    // TODO: is toString() sufficient ?
     String      display(boolean displayContent);
 }

Added: incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/NMR.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/NMR.java?rev=570255&view=auto
==============================================================================
--- incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/NMR.java (added)
+++ incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/NMR.java Mon Aug 27 14:51:27 2007
@@ -0,0 +1,54 @@
+/*
+ * 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.api;
+
+import org.apache.servicemix.api.internal.FlowRegistry;
+import org.apache.servicemix.api.event.ListenerRegistry;
+
+/**
+ * 
+ */
+public interface NMR {
+
+    /**
+     * Access the endpoint registry.
+     *
+     * @return the endpoint registry
+     */
+    EndpointRegistry getEndpointRegistry();
+
+    /**
+     * Access the listener registry.
+     *
+     * @return the listener registry
+     */
+    ListenerRegistry getListenerRegistry();
+
+    /**
+     * Access the flow registry.
+     *
+     * @return the flow registry
+     */
+    FlowRegistry getFlowRegistry();
+
+    /**
+     * Create a channel to interact with the NMR without exposing an endpoint.
+     * @return a channel
+     */
+    Channel createChannel();
+
+}

Added: incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/event/EndpointListener.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/event/EndpointListener.java?rev=570255&view=auto
==============================================================================
--- incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/event/EndpointListener.java (added)
+++ incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/event/EndpointListener.java Mon Aug 27 14:51:27 2007
@@ -0,0 +1,28 @@
+/*
+ * 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.api.event;
+
+import org.apache.servicemix.api.Endpoint;
+
+
+public interface EndpointListener extends Listener {
+
+    void endpointRegistered(Endpoint endpoint);
+    
+    void endpointUnregistered(Endpoint endpoint);
+    
+}

Added: incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/event/ExchangeListener.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/event/ExchangeListener.java?rev=570255&view=auto
==============================================================================
--- incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/event/ExchangeListener.java (added)
+++ incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/event/ExchangeListener.java Mon Aug 27 14:51:27 2007
@@ -0,0 +1,44 @@
+/*
+ * 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.api.event;
+
+import org.apache.servicemix.api.Exchange;
+
+
+/**
+ * Listener interface for exchanges send troughout the bus.
+ * Such a listener will be called each time an exchange is sent
+ * or delivered to an endpoint.
+ *
+ */
+public interface ExchangeListener extends Listener {
+
+    /**
+     * Method called each time an exchange is sent
+     *
+     * @param exchange the exchange sent
+     */
+    void exchangeSent(Exchange exchange);
+
+    /**
+     * Method called each time an exchange is delivered
+     *
+     * @param exchange the delivered exchange
+     */
+    void exchangeDelivered(Exchange exchange);
+    
+}

Added: incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/event/Listener.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/event/Listener.java?rev=570255&view=auto
==============================================================================
--- incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/event/Listener.java (added)
+++ incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/event/Listener.java Mon Aug 27 14:51:27 2007
@@ -0,0 +1,27 @@
+/*
+ * 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.api.event;
+
+/**
+ *
+ * Marker interface for all listeners that can be registered.
+ *
+ * @version $Revision: $
+ * @since 4.0
+ */
+public interface Listener {
+}

Added: incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/event/ListenerRegistry.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/event/ListenerRegistry.java?rev=570255&view=auto
==============================================================================
--- incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/event/ListenerRegistry.java (added)
+++ incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/event/ListenerRegistry.java Mon Aug 27 14:51:27 2007
@@ -0,0 +1,53 @@
+/*
+ * 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.api.event;
+
+import org.apache.servicemix.api.service.ServiceRegistry;
+
+import java.util.Map;
+
+/**
+ * A registry of listeners.
+ */
+public interface ListenerRegistry extends ServiceRegistry<Listener> {
+
+    /**
+     * Add a listener to the registry.
+     * In an OSGi world, listeners would be automatically added by a ServiceTracker.
+     *
+     * @param listener the listener to add
+     * @param properties metadata associated with this listener. It may include data used for filtering events.
+     */
+    void register(Listener listener, Map<String, ?> properties);
+
+    /**
+     * Remove a listener.
+     * In an OSGi world, this would be performed automatically by a ServiceTracker.
+     *
+     * @param listener the listener to remove
+     */
+    void unregister(Listener listener);
+
+    /**
+     * Retrieve an iterator of listeners of a certain type
+     *
+     * @param type the type of listeners
+     * @return an iterator over the registered listeners
+     */
+    <T extends Listener> Iterable<T> getListeners(Class<T> type);
+
+}

Added: incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/event/package.html
URL: http://svn.apache.org/viewvc/incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/event/package.html?rev=570255&view=auto
==============================================================================
--- incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/event/package.html (added)
+++ incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/event/package.html Mon Aug 27 14:51:27 2007
@@ -0,0 +1,30 @@
+<!--
+    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.
+-->
+<html>
+<head>
+</head>
+<body>
+
+Defines the listeners that can be registered inside ServiceMix to be notified of events.
+These events includes:
+<ul>
+    <li><b>Endpoints</b> registered and unregistered</li>
+    <li><b>Exchanges</b> sent and delivered to endpoints</li>    
+</ul>
+
+</body>
+</html>

Added: incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/internal/Flow.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/internal/Flow.java?rev=570255&view=auto
==============================================================================
--- incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/internal/Flow.java (added)
+++ incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/internal/Flow.java Mon Aug 27 14:51:27 2007
@@ -0,0 +1,40 @@
+/*
+ * 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.api.internal;
+
+/**
+ * @version $Revision: $
+ * @since 4.0
+ */
+public interface Flow {
+
+    /**
+     * Check if this flow can be used to dispatch the given Exchange
+     *
+     * @param exchange the exchange to check
+     * @param endpoint the endpoint where the exchange is to be dispatched
+     * @return <code>true</code> if the flow can be used, <code>false</code> otherwise
+     */
+    boolean canDispatch(InternalExchange exchange, InternalEndpoint endpoint);
+
+    /**
+     * Dispatch the Exchange using this flow.
+     *
+     * @param exchange the exchange to dispatch
+     */
+    void dispatch(InternalExchange exchange);
+}

Added: incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/internal/FlowRegistry.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/internal/FlowRegistry.java?rev=570255&view=auto
==============================================================================
--- incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/internal/FlowRegistry.java (added)
+++ incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/internal/FlowRegistry.java Mon Aug 27 14:51:27 2007
@@ -0,0 +1,27 @@
+/*
+ * 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.api.internal;
+
+import org.apache.servicemix.api.service.ServiceRegistry;
+
+/**
+ * @version $Revision: $
+ * @since 4.0
+ */
+public interface FlowRegistry extends Flow, ServiceRegistry<Flow> {
+
+}

Added: incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/internal/InternalChannel.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/internal/InternalChannel.java?rev=570255&view=auto
==============================================================================
--- incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/internal/InternalChannel.java (added)
+++ incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/internal/InternalChannel.java Mon Aug 27 14:51:27 2007
@@ -0,0 +1,39 @@
+/*
+ * 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.api.internal;
+
+import org.apache.servicemix.api.Channel;
+
+/**
+ * InternalChannel is the private contract for channels.
+ *
+ * The {@link #deliver(InternalExchange)} method
+ * is to be used by {@link Flow}s implementations so that they can
+ * hand exchanges to the channels.
+ *
+ * @version $Revision: $
+ * @since 4.0
+ */
+public interface InternalChannel extends Channel {
+
+    /**
+     * Deliver an exchange to the endpoint using this channel
+     *
+     * @param exchange the exchange to delivery
+     */
+    void deliver(InternalExchange exchange);
+}

Added: incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/internal/InternalEndpoint.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/internal/InternalEndpoint.java?rev=570255&view=auto
==============================================================================
--- incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/internal/InternalEndpoint.java (added)
+++ incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/internal/InternalEndpoint.java Mon Aug 27 14:51:27 2007
@@ -0,0 +1,29 @@
+/*
+ * 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.api.internal;
+
+import org.apache.servicemix.api.Endpoint;
+
+/**
+ * @version $Revision: $
+ * @since 4.0
+ */
+public interface InternalEndpoint extends Endpoint {
+
+    InternalChannel getChannel();
+
+}

Added: incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/internal/InternalExchange.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/internal/InternalExchange.java?rev=570255&view=auto
==============================================================================
--- incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/internal/InternalExchange.java (added)
+++ incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/internal/InternalExchange.java Mon Aug 27 14:51:27 2007
@@ -0,0 +1,64 @@
+/*
+ * 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.api.internal;
+
+import org.apache.servicemix.api.Exchange;
+
+/**
+ * 
+ *
+ * @version $Revision: $
+ * @since 4.0
+ */
+public interface InternalExchange extends Exchange {
+
+    /**
+     * Retrieve the source endpoint. I.e. the one that created the exchange.
+     * This information will be set by the NMR when the exchange is sent
+     * using one of {@link org.apache.servicemix.api.Channel#send(Exchange)},
+     * {@link org.apache.servicemix.api.Channel#sendSync(Exchange)} or
+     * {@link org.apache.servicemix.api.Channel#sendSync(Exchange, long)}
+     *
+     * @return the endpoint that sent the exchange
+     */
+    InternalEndpoint getSource();
+
+    /**
+     * Set the source endpoint.  This method should be called by the
+     * {@link org.apache.servicemix.api.Channel}
+     *
+     * @param source the source endpoint
+     */
+    void setSource(InternalEndpoint source);
+
+    /**
+     * Retrieve the destination endpoint, i.e. the one that receive the exchange.
+     * This information will be set by the {@link InternalChannel#deliver(InternalExchange)}
+     * method, just before calling the listeners and actually delegating to the Endpoint for processing.
+     *
+     * @return the destination endpoint
+     */
+    InternalEndpoint getDestination();
+
+    /**
+     * Set the destination endpoint. This method should be called by the
+     * {@link InternalChannel#deliver(InternalExchange)}
+     *
+     * @param destination the destination endpoint
+     */
+    void setDestination(InternalEndpoint destination);
+}

Added: incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/internal/InternalReference.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/internal/InternalReference.java?rev=570255&view=auto
==============================================================================
--- incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/internal/InternalReference.java (added)
+++ incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/internal/InternalReference.java Mon Aug 27 14:51:27 2007
@@ -0,0 +1,38 @@
+/*
+ * 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.api.internal;
+
+import org.apache.servicemix.api.Reference;
+
+/**
+ * @version $Revision: $
+ * @since 4.0
+ */
+public interface InternalReference extends Reference {
+
+    /**
+     * Creates an iterator to be used for choosing the physical target for an exchange.
+     *
+     * When dispatching an exchange, the NMR will select the first endpoint and choose a
+     * flow that can handle it. If no flow can be used, try the next endpoint until
+     * no more endpoints can be used.
+     *
+     * @return an iterator on matching endpoints
+     */
+    Iterable<InternalEndpoint> choose();
+
+}

Added: incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/internal/package.html
URL: http://svn.apache.org/viewvc/incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/internal/package.html?rev=570255&view=auto
==============================================================================
--- incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/internal/package.html (added)
+++ incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/internal/package.html Mon Aug 27 14:51:27 2007
@@ -0,0 +1,25 @@
+<!--
+    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.
+-->
+<html>
+<head>
+</head>
+<body>
+
+Defines the internal API
+
+</body>
+</html>

Added: incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/service/ServiceRegistry.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/service/ServiceRegistry.java?rev=570255&view=auto
==============================================================================
--- incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/service/ServiceRegistry.java (added)
+++ incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/service/ServiceRegistry.java Mon Aug 27 14:51:27 2007
@@ -0,0 +1,62 @@
+/*
+ * 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.api.service;
+
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Templated registry to hold services and their associated metadata.
+ * In an OSGi environment, services would be registered and unregistered
+ * automatically using a service tracker.
+ *
+ * @version $Revision: $
+ * @since 4.0
+ */
+public interface ServiceRegistry<T> {
+
+    /**
+     * Register a service with the given metadata.
+     *
+     * @param service the service to register
+     * @param properties the associated metadata
+     */
+    void register(T service, Map<String, ?> properties);
+
+    /**
+     * Unregister a previously registered service.
+     *
+     * @param service the service to unregister
+     */
+    void unregister(T service);
+
+    /**
+     * Get a set of registered services.
+     *
+     * @return the registered services
+     */
+    Set<T> getServices();
+
+    /**
+     * Retrieve the metadata associated to a registered service.
+     *
+     * @param service the service for which to retrieve metadata
+     * @return the metadata associated with the service
+     */
+    Map<String, ?> getProperties(T service);
+
+}

Added: incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/service/package.html
URL: http://svn.apache.org/viewvc/incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/service/package.html?rev=570255&view=auto
==============================================================================
--- incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/service/package.html (added)
+++ incubator/servicemix/branches/servicemix-4.0/api/src/main/java/org/apache/servicemix/api/service/package.html Mon Aug 27 14:51:27 2007
@@ -0,0 +1,25 @@
+<!--
+    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.
+-->
+<html>
+<head>
+</head>
+<body>
+
+Defines the ServiceRegistry
+
+</body>
+</html>

Modified: incubator/servicemix/branches/servicemix-4.0/api/src/test/java/org/apache/servicemix/api/OsgiExample.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/branches/servicemix-4.0/api/src/test/java/org/apache/servicemix/api/OsgiExample.java?rev=570255&r1=570254&r2=570255&view=diff
==============================================================================
--- incubator/servicemix/branches/servicemix-4.0/api/src/test/java/org/apache/servicemix/api/OsgiExample.java (original)
+++ incubator/servicemix/branches/servicemix-4.0/api/src/test/java/org/apache/servicemix/api/OsgiExample.java Mon Aug 27 14:51:27 2007
@@ -48,10 +48,10 @@
         // registering an endpoint
         Endpoint e = new MyEndpoint();
         Dictionary<String, Object> props = new Hashtable<String, Object>();
-        props.put(EndpointConstants.ID, "my-endpoint");
-        props.put(EndpointConstants.SERVICE_NAME, new QName("urn:namesapce", "service"));
-        props.put(EndpointConstants.ENDPOINT_NAME, "foo");
-        props.put(EndpointConstants.WSDL_URL, "file:my.wsdl");
+        props.put(Endpoint.ID, "my-endpoint");
+        props.put(Endpoint.SERVICE_NAME, new QName("urn:namesapce", "service"));
+        props.put(Endpoint.ENDPOINT_NAME, "foo");
+        props.put(Endpoint.WSDL_URL, "file:my.wsdl");
 
         bundleContext.registerService(Endpoint.class.getName(), e, props);
     }
@@ -59,23 +59,29 @@
     public void testFindRegistry() {
         BundleContext bundleContext = null;
 
-        ServiceReference ref = bundleContext.getServiceReference(Registry.class.getName());
-        Registry reg = (Registry) bundleContext.getService(ref);
+        // Direct retrieval
+        ServiceReference ref = bundleContext.getServiceReference(EndpointRegistry.class.getName());
+        EndpointRegistry reg = (EndpointRegistry) bundleContext.getService(ref);
+
+        // Retrieval using the NMR
+        ref = bundleContext.getServiceReference(NMR.class.getName());
+        NMR nmr = (NMR) bundleContext.getService(ref);
+        reg = nmr.getEndpointRegistry();
     }
 
     public void testLookupReference() throws InvalidSyntaxException {
-        Registry reg = null;
+        EndpointRegistry reg = null;
 
         Map<String, Object> props = new HashMap<String, Object>();
-        props.put(EndpointConstants.ID, "myEndpoint");
+        props.put(Endpoint.ID, "myEndpoint");
         Reference target = reg.lookup(props);
     }
 
     public void testSendExchange() {
-        Registry reg = null;
+        NMR nmr = null;
         Reference target = null;
 
-        Channel channel = reg.createChannel();
+        Channel channel = nmr.createChannel();
         try {
             Exchange e = channel.createExchange(Pattern.InOnly);
             e.setTarget(target);

Modified: incubator/servicemix/branches/servicemix-4.0/core/pom.xml
URL: http://svn.apache.org/viewvc/incubator/servicemix/branches/servicemix-4.0/core/pom.xml?rev=570255&r1=570254&r2=570255&view=diff
==============================================================================
--- incubator/servicemix/branches/servicemix-4.0/core/pom.xml (original)
+++ incubator/servicemix/branches/servicemix-4.0/core/pom.xml Mon Aug 27 14:51:27 2007
@@ -42,7 +42,7 @@
 	<dependency>
 	  <groupId>junit</groupId>
 	  <artifactId>junit</artifactId>
-	  <version>4.3.1</version>
+	  <version>4.4</version>
 	  <scope>test</scope>
 	</dependency>
   </dependencies>

Added: incubator/servicemix/branches/servicemix-4.0/core/src/main/java/org/apache/servicemix/core/ChannelImpl.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/branches/servicemix-4.0/core/src/main/java/org/apache/servicemix/core/ChannelImpl.java?rev=570255&view=auto
==============================================================================
--- incubator/servicemix/branches/servicemix-4.0/core/src/main/java/org/apache/servicemix/core/ChannelImpl.java (added)
+++ incubator/servicemix/branches/servicemix-4.0/core/src/main/java/org/apache/servicemix/core/ChannelImpl.java Mon Aug 27 14:51:27 2007
@@ -0,0 +1,143 @@
+/*
+ * 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.core;
+
+import org.apache.servicemix.api.Exchange;
+import org.apache.servicemix.api.NMR;
+import org.apache.servicemix.api.Pattern;
+import org.apache.servicemix.api.event.ExchangeListener;
+import org.apache.servicemix.api.internal.InternalChannel;
+import org.apache.servicemix.api.internal.InternalEndpoint;
+import org.apache.servicemix.api.internal.InternalExchange;
+
+import java.util.concurrent.Executor;
+
+/**
+ * @version $Revision: $
+ * @since 4.0
+ */
+public class ChannelImpl implements InternalChannel {
+
+    private final InternalEndpoint endpoint;
+    private final Executor executor;
+    private final NMR nmr;
+    
+
+    public ChannelImpl(InternalEndpoint endpoint, Executor executor, NMR nmr) {
+        this.endpoint = endpoint;
+        this.executor = executor;
+        this.nmr = nmr;
+    }
+
+    /**
+     * Creates a new exchange.
+     *
+     * @param pattern specify the InOnly / InOut / RobustInOnly / RobustInOut
+     * @return a new exchange of the given pattern
+     */
+    public Exchange createExchange(Pattern pattern) {
+        return new ExchangeImpl(pattern);
+    }
+
+    /**
+     * An asynchronous invocation of the service
+     *
+     * @param exchange the exchange to send
+     */
+    public void send(Exchange exchange) {
+        InternalExchange e = (InternalExchange) exchange;
+        dispatch(e);
+    }
+
+    /**
+     * Synchronously send the exchange, blocking until the exchange is returned.
+     *
+     * @param exchange the exchange to send
+     * @return <code>true</code> if the exchange has been processed succesfully
+     */
+    public boolean sendSync(Exchange exchange) {
+        // TODO
+        return false;  //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    /**
+     * Synchronously send the exchange
+     *
+     * @param exchange the exchange to send
+     * @param timeout  time to wait in milliseconds
+     * @return <code>true</code> if the exchange has been processed succesfully
+     */
+    public boolean sendSync(Exchange exchange, long timeout) {
+        // TODO
+        return false;  //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    /**
+     * Closes the channel, freeing up any resources (like sockets, threads etc).
+     * Channel that are injected onto Endpoints will be closed automatically by
+     * the NMR.
+     */
+    public void close() {
+        // TODO
+    }
+
+    /**
+     * Deliver an exchange to the endpoint using this channel
+     *
+     * @param exchange the exchange to delivery
+     */
+    public void deliver(final InternalExchange exchange) {
+        // Delegate processing to the executor
+        this.executor.execute(new Runnable() {
+            public void run() {
+                process(exchange);
+            }
+        });
+    }
+
+    /**
+     * Processes the exchange.  Delegate to the endpoint for actual processing.
+     *
+     * @param exchange the exchange to process
+     */
+    protected void process(InternalExchange exchange) {
+        // Set destination endpoint
+        exchange.setDestination(endpoint);
+        // Call listeners
+        for (ExchangeListener l : nmr.getListenerRegistry().getListeners(ExchangeListener.class)) {
+            l.exchangeDelivered(exchange);
+        }
+        // Process exchange
+        endpoint.process(exchange);
+    }
+
+    /**
+     * Dispatch the exchange to the NMR
+     *
+     * @param exchange the exchange to dispatch
+     */
+    protected void dispatch(InternalExchange exchange) {
+        // Set source endpoint
+        exchange.setSource(endpoint);
+        // Call listeners
+        for (ExchangeListener l : nmr.getListenerRegistry().getListeners(ExchangeListener.class)) {
+            l.exchangeSent(exchange);
+        }
+        // Dispatch in NMR
+        nmr.getFlowRegistry().dispatch(exchange);
+    }
+}

Added: incubator/servicemix/branches/servicemix-4.0/core/src/main/java/org/apache/servicemix/core/ClientChannel.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/branches/servicemix-4.0/core/src/main/java/org/apache/servicemix/core/ClientChannel.java?rev=570255&view=auto
==============================================================================
--- incubator/servicemix/branches/servicemix-4.0/core/src/main/java/org/apache/servicemix/core/ClientChannel.java (added)
+++ incubator/servicemix/branches/servicemix-4.0/core/src/main/java/org/apache/servicemix/core/ClientChannel.java Mon Aug 27 14:51:27 2007
@@ -0,0 +1,53 @@
+/*
+ * 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.core;
+
+import org.apache.servicemix.api.Channel;
+import org.apache.servicemix.api.Exchange;
+import org.apache.servicemix.api.NMR;
+import org.apache.servicemix.api.internal.InternalChannel;
+import org.apache.servicemix.api.internal.InternalEndpoint;
+
+import java.util.concurrent.Executors;
+
+/**
+ *
+ */
+public class ClientChannel extends ChannelImpl implements Channel {
+
+    public ClientChannel(NMR nmr) {
+        super(new ClientEndpoint(), Executors.newCachedThreadPool(), nmr);
+    }
+
+    protected static class ClientEndpoint implements InternalEndpoint {
+
+        private InternalChannel channel;
+
+        public void setChannel(Channel channel) {
+            this.channel = (InternalChannel) channel;   
+        }
+
+        public InternalChannel getChannel() {
+            return channel;
+        }
+
+        public void process(Exchange exchange) {
+            throw new IllegalStateException();
+        }
+
+    }
+}

Added: incubator/servicemix/branches/servicemix-4.0/core/src/main/java/org/apache/servicemix/core/EndpointRegistryImpl.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/branches/servicemix-4.0/core/src/main/java/org/apache/servicemix/core/EndpointRegistryImpl.java?rev=570255&view=auto
==============================================================================
--- incubator/servicemix/branches/servicemix-4.0/core/src/main/java/org/apache/servicemix/core/EndpointRegistryImpl.java (added)
+++ incubator/servicemix/branches/servicemix-4.0/core/src/main/java/org/apache/servicemix/core/EndpointRegistryImpl.java Mon Aug 27 14:51:27 2007
@@ -0,0 +1,130 @@
+/*
+ * 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.core;
+
+import org.apache.servicemix.api.Endpoint;
+import org.apache.servicemix.api.EndpointRegistry;
+import org.apache.servicemix.api.NMR;
+import org.apache.servicemix.api.Reference;
+import org.apache.servicemix.api.internal.InternalEndpoint;
+import org.apache.servicemix.api.service.ServiceRegistry;
+import org.w3c.dom.Document;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.Executor;
+import java.util.concurrent.Executors;
+
+/**
+ * @version $Revision: $
+ * @since 4.0
+ */
+public class EndpointRegistryImpl implements EndpointRegistry {
+
+    private NMR nmr;
+    private Map<Endpoint, InternalEndpoint> endpoints = new ConcurrentHashMap<Endpoint, InternalEndpoint>();
+    private ServiceRegistry<InternalEndpoint> registry = new ServiceRegistryImpl<InternalEndpoint>();
+
+    /**
+     * Register the given endpoint in the registry.
+     * In an OSGi world, this would be performed automatically by a ServiceTracker.
+     * Upon registration, a {@link org.apache.servicemix.api.Channel} will be injected onto the Endpoint using
+     * the {@link org.apache.servicemix.api.Endpoint#setChannel(org.apache.servicemix.api.Channel)} method.
+     *
+     * @param endpoint   the endpoint to register
+     * @param properties the metadata associated with this endpoint
+     * @see org.apache.servicemix.api.Endpoint
+     */
+    public void register(Endpoint endpoint, Map<String, ?> properties) {
+        Executor executor = Executors.newCachedThreadPool();
+        InternalEndpointWrapper wrapper = new InternalEndpointWrapper(endpoint);
+        ChannelImpl channel = new ChannelImpl(wrapper, executor, nmr);
+        wrapper.setChannel(channel);
+        endpoints.put(endpoint, wrapper);
+        registry.register(wrapper, properties);
+    }
+
+    /**
+     * Unregister a previously register enpoint.
+     * In an OSGi world, this would be performed automatically by a ServiceTracker.
+     *
+     * @param endpoint the endpoint to unregister
+     */
+    public void unregister(Endpoint endpoint) {
+        InternalEndpoint wrapper = endpoints.remove(endpoint);
+        registry.unregister(wrapper);
+    }
+
+    /**
+     * Get a set of registered services.
+     *
+     * @return the registered services
+     */
+    public Set<Endpoint> getServices() {
+        return null;  // TODO
+    }
+
+    /**
+     * Retrieve the metadata associated to a registered service.
+     *
+     * @param service the service for which to retrieve metadata
+     * @return the metadata associated with the service
+     */
+    public Map<String, ?> getProperties(Endpoint service) {
+        return null;  // TODO
+    }
+
+    /**
+     * From a given amount of metadata which could include interface name, service name
+     * policy data and so forth, choose an available endpoint reference to use
+     * for invocations.
+     * <p/>
+     * This could return actual endpoints, or a dynamic proxy to a number of endpoints
+     */
+    public Reference lookup(Map<String, ?> properties) {
+        List<InternalEndpoint> endpoints = new ArrayList<InternalEndpoint>();
+        for (InternalEndpoint e : registry.getServices()) {
+            boolean match = true;
+            for (String name : properties.keySet()) {
+                if (!properties.get(name).equals(registry.getProperties(e).get(name))) {
+                    match = false;
+                    break;
+                }
+            }
+            if (match) {
+                endpoints.add(e);
+            }
+        }
+        return new ReferenceImpl(endpoints);
+    }
+
+    /**
+     * This methods creates a Reference from its xml representation.
+     *
+     * @param xml the xml document describing this reference
+     * @return a new Reference
+     * @see org.apache.servicemix.api.Reference#toXml()
+     */
+    public synchronized Reference lookup(Document xml) {
+        // TODO: implement
+        return null;
+    }
+
+}

Modified: incubator/servicemix/branches/servicemix-4.0/core/src/main/java/org/apache/servicemix/core/ExchangeImpl.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/branches/servicemix-4.0/core/src/main/java/org/apache/servicemix/core/ExchangeImpl.java?rev=570255&r1=570254&r2=570255&view=diff
==============================================================================
--- incubator/servicemix/branches/servicemix-4.0/core/src/main/java/org/apache/servicemix/core/ExchangeImpl.java (original)
+++ incubator/servicemix/branches/servicemix-4.0/core/src/main/java/org/apache/servicemix/core/ExchangeImpl.java Mon Aug 27 14:51:27 2007
@@ -16,13 +16,9 @@
  */
 package org.apache.servicemix.core;
 
-import org.apache.servicemix.api.Exchange;
-import org.apache.servicemix.api.Message;
-import org.apache.servicemix.api.Pattern;
-import org.apache.servicemix.api.Reference;
-import org.apache.servicemix.api.Role;
-import org.apache.servicemix.api.Status;
-import org.apache.servicemix.api.Type;
+import org.apache.servicemix.api.*;
+import org.apache.servicemix.api.internal.InternalExchange;
+import org.apache.servicemix.api.internal.InternalEndpoint;
 
 import javax.xml.namespace.QName;
 import java.io.IOException;
@@ -34,7 +30,7 @@
  * @version $Revision: $
  * @since 4.0
  */
-public class ExchangeImpl implements Exchange {
+public class ExchangeImpl implements InternalExchange {
 
 	/**
 	 * Generated serial version UID 
@@ -52,6 +48,8 @@
     private Message out;
     private Message fault;
     private Exception error;
+    private InternalEndpoint source;
+    private InternalEndpoint destination;
 
     /**
      * Creates and exchange of the given pattern
@@ -360,5 +358,21 @@
 	public String toString() {
 		return display(true);
 	}
+
+    public InternalEndpoint getSource() {
+        return source;
+    }
+
+    public void setSource(InternalEndpoint source) {
+        this.source = source;
+    }
+
+    public InternalEndpoint getDestination() {
+        return destination;
+    }
+
+    public void setDestination(InternalEndpoint destination) {
+        this.destination = destination;
+    }
 
 }

Added: incubator/servicemix/branches/servicemix-4.0/core/src/main/java/org/apache/servicemix/core/FlowRegistryImpl.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/branches/servicemix-4.0/core/src/main/java/org/apache/servicemix/core/FlowRegistryImpl.java?rev=570255&view=auto
==============================================================================
--- incubator/servicemix/branches/servicemix-4.0/core/src/main/java/org/apache/servicemix/core/FlowRegistryImpl.java (added)
+++ incubator/servicemix/branches/servicemix-4.0/core/src/main/java/org/apache/servicemix/core/FlowRegistryImpl.java Mon Aug 27 14:51:27 2007
@@ -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.servicemix.core;
+
+import org.apache.servicemix.api.ServiceMixException;
+import org.apache.servicemix.api.internal.*;
+
+/**
+ * The default implementation of FlowRegistry.
+ * 
+ * @version $Revision: $
+ * @since 4.0
+ */
+public class FlowRegistryImpl extends ServiceRegistryImpl<Flow> implements FlowRegistry {
+
+    public boolean canDispatch(InternalExchange exchange, InternalEndpoint endpoint) {
+        for (Flow flow : getServices()) {
+            if (flow.canDispatch(exchange, endpoint)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    public void dispatch(InternalExchange exchange) {
+        InternalReference target = (InternalReference) exchange.getTarget();
+        for (InternalEndpoint endpoint : target.choose()) {
+            for (Flow flow : getServices()) {
+                if (flow.canDispatch(exchange, endpoint)) {
+                    flow.dispatch(exchange);
+                    return;
+                }
+            }
+            throw new ServiceMixException("Could not dispatch exchange. No flow can handle it.");
+        }
+    }
+}

Added: incubator/servicemix/branches/servicemix-4.0/core/src/main/java/org/apache/servicemix/core/InternalEndpointWrapper.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/branches/servicemix-4.0/core/src/main/java/org/apache/servicemix/core/InternalEndpointWrapper.java?rev=570255&view=auto
==============================================================================
--- incubator/servicemix/branches/servicemix-4.0/core/src/main/java/org/apache/servicemix/core/InternalEndpointWrapper.java (added)
+++ incubator/servicemix/branches/servicemix-4.0/core/src/main/java/org/apache/servicemix/core/InternalEndpointWrapper.java Mon Aug 27 14:51:27 2007
@@ -0,0 +1,69 @@
+/*
+ * 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.core;
+
+import org.apache.servicemix.api.Endpoint;
+import org.apache.servicemix.api.Channel;
+import org.apache.servicemix.api.Exchange;
+import org.apache.servicemix.api.internal.InternalEndpoint;
+import org.apache.servicemix.api.internal.InternalChannel;
+
+/**
+ *
+ */
+public class InternalEndpointWrapper implements InternalEndpoint {
+
+    private final Endpoint endpoint;
+    private InternalChannel channel;
+
+    public InternalEndpointWrapper(Endpoint endpoint) {
+        this.endpoint = endpoint;
+    }
+
+    public InternalChannel getChannel() {
+        return channel;
+    }
+
+    /**
+     * Set the channel so that the endpoint can send exchanges back
+     * when they are processed or act as a consumer itself.
+     * This method will be called by the NMR while the endpoint is registered.
+     * Such a channel does not need to be closed as the NMR will close it
+     * automatically when the endpoint is unregistered.
+     *
+     * @param channel the channel that this endpoint can use
+     * @see org.apache.servicemix.api.EndpointRegistry#register(org.apache.servicemix.api.Endpoint,java.util.Map)
+     */
+    public void setChannel(Channel channel) {
+        this.channel = (InternalChannel) channel;
+        endpoint.setChannel(channel);
+    }
+
+    /**
+     * Process the given exchange.  The processing can occur in the current thread
+     * or asynchronously.
+     * If an endpoint has sent an exchange asynchronously to another endpoint,
+     * it will receive the exchange back using this method.  An endpoint can
+     * recognized such exchanges by checking the role of the exchange.
+     *
+     * @param exchange the exchange to process
+     */
+    public void process(Exchange exchange) {
+        endpoint.process(exchange);
+    }
+
+}

Added: incubator/servicemix/branches/servicemix-4.0/core/src/main/java/org/apache/servicemix/core/ListenerRegistryImpl.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/branches/servicemix-4.0/core/src/main/java/org/apache/servicemix/core/ListenerRegistryImpl.java?rev=570255&view=auto
==============================================================================
--- incubator/servicemix/branches/servicemix-4.0/core/src/main/java/org/apache/servicemix/core/ListenerRegistryImpl.java (added)
+++ incubator/servicemix/branches/servicemix-4.0/core/src/main/java/org/apache/servicemix/core/ListenerRegistryImpl.java Mon Aug 27 14:51:27 2007
@@ -0,0 +1,88 @@
+/*
+ * 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.core;
+
+import org.apache.servicemix.api.event.Listener;
+import org.apache.servicemix.api.event.ListenerRegistry;
+
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+/**
+ *
+ */
+public class    ListenerRegistryImpl extends ServiceRegistryImpl<Listener> implements ListenerRegistry {
+
+    /**
+     * Retrieve an iterator of listeners of a certain type
+     *
+     * @param type the type of listeners
+     * @return an iterator over the registered listeners
+     */
+    public <T extends Listener> Iterable<T> getListeners(final Class<T> type) {
+        return new Iterable<T>() {
+            public Iterator<T> iterator() {
+                return new FilterIterator(type, getServices().iterator());
+            }
+        };
+    }
+
+    /**
+     * A filtered iterator that will only return elements of a certain type
+     */
+    private static class FilterIterator<U, T extends U> implements Iterator<T> {
+
+        private Iterator<U> iter;
+        private Class<T> type;
+        private T next;
+
+        public FilterIterator(Class<T> type, Iterator<U> iter) {
+            this.iter = iter;
+            this.type = type;
+            advance();
+        }
+
+        private void advance() {
+            while (iter.hasNext()) {
+                U elt = iter.next();
+                if (type.isInstance(elt)) {
+                    next = (T) elt;
+                    return;
+                }
+            }
+            next = null;
+        }
+
+        public boolean hasNext() {
+            return next != null;
+        }
+
+        public T next() {
+            if (next == null) {
+                throw new NoSuchElementException();
+            }
+            T o = next;
+            advance();
+            return o;
+        }
+
+        public void remove() {
+            throw new UnsupportedOperationException();
+        }
+    }
+
+}

Added: incubator/servicemix/branches/servicemix-4.0/core/src/main/java/org/apache/servicemix/core/ReferenceImpl.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/branches/servicemix-4.0/core/src/main/java/org/apache/servicemix/core/ReferenceImpl.java?rev=570255&view=auto
==============================================================================
--- incubator/servicemix/branches/servicemix-4.0/core/src/main/java/org/apache/servicemix/core/ReferenceImpl.java (added)
+++ incubator/servicemix/branches/servicemix-4.0/core/src/main/java/org/apache/servicemix/core/ReferenceImpl.java Mon Aug 27 14:51:27 2007
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.core;
+
+import org.apache.servicemix.api.Reference;
+import org.apache.servicemix.api.Endpoint;
+import org.apache.servicemix.api.internal.InternalEndpoint;
+import org.w3c.dom.Document;
+
+import java.util.List;
+import java.util.Iterator;
+
+/**
+ * @version $Revision: $
+ * @since 4.0
+ */
+public class ReferenceImpl implements Reference {
+
+    private final List<InternalEndpoint> endpoints;
+
+    public ReferenceImpl(List<InternalEndpoint> endpoints) {
+        this.endpoints = endpoints;
+    }
+
+    /**
+     * Get the list of matching endpoints
+     *
+     * @return the list of matching endpoints
+     */
+    public List<InternalEndpoint> getEndpoints() {
+        return endpoints;
+    }
+
+    /**
+     * Obtains an xml document describing this endpoint reference.
+     *
+     * @return
+     */
+    public Document toXml() {
+        // TODO: implement
+        return null;
+    }
+
+    /**
+     * Choose an Endpoint to be used as the target for an exchange
+     *
+     * @return an endpoint that will be used as the physical target
+     */
+    public Iterator<Endpoint> choose() {
+        return new EndpointIterator(endpoints.iterator());
+    }
+    
+    protected static class EndpointIterator implements Iterator<Endpoint> {
+
+        private final Iterator<InternalEndpoint> iterator;
+
+        public EndpointIterator(Iterator<InternalEndpoint> iterator) {
+            this.iterator = iterator;
+        }
+
+        public boolean hasNext() {
+            return iterator.hasNext();
+        }
+
+        public Endpoint next() {
+            return iterator.next();
+        }
+
+        public void remove() {
+            throw new IllegalStateException();
+        }
+    }
+}

Added: incubator/servicemix/branches/servicemix-4.0/core/src/main/java/org/apache/servicemix/core/ServiceMix.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/branches/servicemix-4.0/core/src/main/java/org/apache/servicemix/core/ServiceMix.java?rev=570255&view=auto
==============================================================================
--- incubator/servicemix/branches/servicemix-4.0/core/src/main/java/org/apache/servicemix/core/ServiceMix.java (added)
+++ incubator/servicemix/branches/servicemix-4.0/core/src/main/java/org/apache/servicemix/core/ServiceMix.java Mon Aug 27 14:51:27 2007
@@ -0,0 +1,69 @@
+/*
+ * 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.core;
+
+import org.apache.servicemix.api.Channel;
+import org.apache.servicemix.api.EndpointRegistry;
+import org.apache.servicemix.api.NMR;
+import org.apache.servicemix.api.event.ListenerRegistry;
+import org.apache.servicemix.api.internal.FlowRegistry;
+
+/**
+ *
+ */
+public class ServiceMix implements NMR {
+
+    private EndpointRegistry endpoints;
+    private ListenerRegistry listeners;
+    private FlowRegistry flows;
+
+    /**
+     * Access the endpoint registry.
+     *
+     * @return the endpoint registry
+     */
+    public EndpointRegistry getEndpointRegistry() {
+        return endpoints;
+    }
+
+    /**
+     * Access the listener registry.
+     *
+     * @return the listener registry
+     */
+    public ListenerRegistry getListenerRegistry() {
+        return listeners;
+    }
+
+    /**
+     * Access the flow registry.
+     *
+     * @return the flow registry
+     */
+    public FlowRegistry getFlowRegistry() {
+        return flows;
+    }
+
+    /**
+     * Create a channel to interact with the NMR without exposing an endpoint.
+     *
+     * @return a channel
+     */
+    public Channel createChannel() {
+        return new ClientChannel(this);
+    }
+}

Added: incubator/servicemix/branches/servicemix-4.0/core/src/main/java/org/apache/servicemix/core/ServiceRegistryImpl.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/branches/servicemix-4.0/core/src/main/java/org/apache/servicemix/core/ServiceRegistryImpl.java?rev=570255&view=auto
==============================================================================
--- incubator/servicemix/branches/servicemix-4.0/core/src/main/java/org/apache/servicemix/core/ServiceRegistryImpl.java (added)
+++ incubator/servicemix/branches/servicemix-4.0/core/src/main/java/org/apache/servicemix/core/ServiceRegistryImpl.java Mon Aug 27 14:51:27 2007
@@ -0,0 +1,35 @@
+package org.apache.servicemix.core;
+
+import org.apache.servicemix.api.service.ServiceRegistry;
+
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: gnodet
+ * Date: Aug 27, 2007
+ * Time: 12:43:36 PM
+ * To change this template use File | Settings | File Templates.
+ */
+public class ServiceRegistryImpl<T> implements ServiceRegistry<T> {
+
+    private Map<T, Map<String, ?>> registry = new ConcurrentHashMap<T, Map<String, ?>>();
+
+    public void register(T service, Map<String, ?> properties) {
+        registry.put(service, properties);
+    }
+
+    public void unregister(T service) {
+        registry.remove(service);
+    }
+
+    public Set<T> getServices() {
+        return registry.keySet();
+    }
+
+    public Map<String, ?> getProperties(T service) {
+        return registry.get(service);
+    }
+}

Added: incubator/servicemix/branches/servicemix-4.0/core/src/main/java/org/apache/servicemix/core/StraightThroughFlow.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/branches/servicemix-4.0/core/src/main/java/org/apache/servicemix/core/StraightThroughFlow.java?rev=570255&view=auto
==============================================================================
--- incubator/servicemix/branches/servicemix-4.0/core/src/main/java/org/apache/servicemix/core/StraightThroughFlow.java (added)
+++ incubator/servicemix/branches/servicemix-4.0/core/src/main/java/org/apache/servicemix/core/StraightThroughFlow.java Mon Aug 27 14:51:27 2007
@@ -0,0 +1,54 @@
+/*
+ * 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.core;
+
+import org.apache.servicemix.api.internal.Flow;
+import org.apache.servicemix.api.internal.InternalEndpoint;
+import org.apache.servicemix.api.internal.InternalExchange;
+
+
+/**
+ * The StraightThrough flow is the simpliest possible flow.
+ * It will just put the exchange to its destination endpoint's
+ * channel by calling:
+ * <code><pre>
+ *     exchange.getDestination().getChannel().deliver(exchange);
+ * </pre></code>
+ *
+ * @version $Revision: $
+ * @since 4.0
+ */
+public class StraightThroughFlow implements Flow {
+    /**
+     * Check if this flow can be used to dispatch the given Exchange
+     *
+     * @param exchange the exchange to check
+     * @return <code>true</code> if the flow can be used, <code>false</code> otherwise
+     */
+    public boolean canDispatch(InternalExchange exchange, InternalEndpoint endpoint) {
+        return true;
+    }
+
+    /**
+     * Dispatch the Exchange using this flow.
+     *
+     * @param exchange the exchange to dispatch
+     */
+    public void dispatch(InternalExchange exchange) {
+        exchange.getDestination().getChannel().deliver(exchange);
+    }
+}