streams-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From letourn...@apache.org
Subject svn commit: r1433510 - in /incubator/streams/trunk/streams-eip-routes: ./ src/main/java/org/apache/streams/messaging/routers/ src/main/java/org/apache/streams/messaging/routers/impl/ src/main/java/org/apache/streams/messaging/rules/impl/ src/main/resou...
Date Tue, 15 Jan 2013 16:46:06 GMT
Author: letourneau
Date: Tue Jan 15 16:46:05 2013
New Revision: 1433510

URL: http://svn.apache.org/viewvc?rev=1433510&view=rev
Log:
dynamic routing with slip working

Modified:
    incubator/streams/trunk/streams-eip-routes/pom.xml
    incubator/streams/trunk/streams-eip-routes/src/main/java/org/apache/streams/messaging/routers/ActivityRouter.java
    incubator/streams/trunk/streams-eip-routes/src/main/java/org/apache/streams/messaging/routers/impl/ActivityRouterImpl.java
    incubator/streams/trunk/streams-eip-routes/src/main/java/org/apache/streams/messaging/rules/impl/SimpleRoutingRule.java
    incubator/streams/trunk/streams-eip-routes/src/main/resources/META-INF/spring/camelContext.xml
    incubator/streams/trunk/streams-eip-routes/src/main/resources/META-INF/spring/osgi-component-import.xml

Modified: incubator/streams/trunk/streams-eip-routes/pom.xml
URL: http://svn.apache.org/viewvc/incubator/streams/trunk/streams-eip-routes/pom.xml?rev=1433510&r1=1433509&r2=1433510&view=diff
==============================================================================
--- incubator/streams/trunk/streams-eip-routes/pom.xml (original)
+++ incubator/streams/trunk/streams-eip-routes/pom.xml Tue Jan 15 16:46:05 2013
@@ -69,9 +69,9 @@
                     <instructions>
                         <Bundle-SymbolicName>${bundle.symbolicName}</Bundle-SymbolicName>
                         <Bundle-Version>${pom.version}</Bundle-Version>
-                        <Export-Package>${bundle.namespace};version="${pom.version}"</Export-Package>
+                        <Export-Package>${bundle.namespace};version="${pom.version}",org.apache.streams.messaging.routers,org.apache.streams.messaging.rules</Export-Package>
                         <Private-Package>${bundle.namespace}.messaging.routers.impl.*,${bundle.namespace}.messaging.rules.impl.*</Private-Package>
-                        <Import-Package>org.apache.camel,org.springframework,org.apache.commons.logging,org.apache.streams.messaging.routers,
org.apache.streams.messaging.rules,org.apache.streams.osgi-components</Import-Package>
+                        <Import-Package>org.apache.camel.*;version="2.8.5",org.springframework.core;version="3.0.6.RELEASE",org.springframework.context;version="3.0.6.RELEASE",org.apache.commons.logging,org.apache.streams.messaging.routers,
org.apache.streams.messaging.rules,org.apache.streams.osgi.components</Import-Package>
                         <Include-Resource>src/main/resources</Include-Resource>
                     </instructions>
                 </configuration>
@@ -83,13 +83,13 @@
         <dependency>
             <groupId>org.apache.camel</groupId>
             <artifactId>camel-core</artifactId>
-            <version>2.10.3</version>
+            <version>2.8.5</version>
         </dependency>
 
         <dependency>
             <groupId>org.springframework</groupId>
             <artifactId>spring-core</artifactId>
-            <version>3.0.5.RELEASE</version>
+            <version>3.0.6.RELEASE</version>
         </dependency>
 
         <dependency>
@@ -115,7 +115,7 @@
         </dependency>
 
         <dependency>
-            <groupId>org.apache.streams.osgi-components</groupId>
+            <groupId>org.apache.streams.osgi.components</groupId>
             <artifactId>activity-publisher-registration</artifactId>
             <version>${pom.version}</version>
         </dependency>

Modified: incubator/streams/trunk/streams-eip-routes/src/main/java/org/apache/streams/messaging/routers/ActivityRouter.java
URL: http://svn.apache.org/viewvc/incubator/streams/trunk/streams-eip-routes/src/main/java/org/apache/streams/messaging/routers/ActivityRouter.java?rev=1433510&r1=1433509&r2=1433510&view=diff
==============================================================================
--- incubator/streams/trunk/streams-eip-routes/src/main/java/org/apache/streams/messaging/routers/ActivityRouter.java
(original)
+++ incubator/streams/trunk/streams-eip-routes/src/main/java/org/apache/streams/messaging/routers/ActivityRouter.java
Tue Jan 15 16:46:05 2013
@@ -2,9 +2,13 @@ package org.apache.streams.messaging.rou
 
 import java.lang.Object;
 import java.lang.String;
+import java.util.ArrayList;
 import java.util.Map;
-import org.apache.camel.Properties;
 
+import org.apache.camel.Exchange;
+import org.apache.camel.Header;
+import org.apache.camel.Properties;
+import org.apache.streams.messaging.rules.RoutingRule;
 
 
 public interface ActivityRouter {
@@ -15,7 +19,7 @@ public interface ActivityRouter {
     * @param body the message body
     * @return endpoints to go, or <tt>null</tt> to indicate the end
     */
-    String slip(String body,@Properties Map<String, Object> properties);
-    void addRoutingRules(Map<String,String> rules);
+    String slip(String body,@Header(Exchange.SLIP_ENDPOINT) String previous);
+    void addRoutingRules(ArrayList<RoutingRule> rules);
 
 }

Modified: incubator/streams/trunk/streams-eip-routes/src/main/java/org/apache/streams/messaging/routers/impl/ActivityRouterImpl.java
URL: http://svn.apache.org/viewvc/incubator/streams/trunk/streams-eip-routes/src/main/java/org/apache/streams/messaging/routers/impl/ActivityRouterImpl.java?rev=1433510&r1=1433509&r2=1433510&view=diff
==============================================================================
--- incubator/streams/trunk/streams-eip-routes/src/main/java/org/apache/streams/messaging/routers/impl/ActivityRouterImpl.java
(original)
+++ incubator/streams/trunk/streams-eip-routes/src/main/java/org/apache/streams/messaging/routers/impl/ActivityRouterImpl.java
Tue Jan 15 16:46:05 2013
@@ -1,61 +1,60 @@
 package org.apache.streams.messaging.routers.impl;
 
+
 import org.apache.streams.messaging.routers.ActivityRouter;
 
 import java.lang.String;
 import java.util.HashMap;
+import java.util.LinkedList;
 import java.util.Map;
 import java.util.ArrayList;
 import org.apache.streams.messaging.rules.RoutingRule;
 
-import org.apache.camel.Properties;
+
+import org.apache.camel.Header;
+import org.apache.camel.Exchange;
+
 import org.apache.streams.messaging.rules.impl.SimpleRoutingRule;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
 
-public class ActivityRouterImpl implements ActivityRouter {
+public class ActivityRouterImpl  implements ActivityRouter {
     private static final transient Log LOG = LogFactory.getLog(ActivityRouterImpl.class);
 
-    private ArrayList<RoutingRule> routingRules;
+    private HashMap<String, RoutingRule> routingRules;
 
     public ActivityRouterImpl(){
-        routingRules = new ArrayList<RoutingRule>();
+        routingRules = new HashMap<String, RoutingRule>();
     }
 
-    public ActivityRouterImpl(HashMap<String, String> routes){
+    public ActivityRouterImpl(ArrayList<RoutingRule> routes){
         LOG.info(">> setting up routes >>");
+        routingRules = new HashMap<String, RoutingRule>();
        addRoutingRules(routes);
     }
 
-    public String slip(String body, @Properties Map<String, Object> properties) {
 
 
-        // get the state from the exchange properties and keep track how many times
-        // we have been invoked
-        int invoked = 0;
-        Object current = properties.get("invoked");
-        if (current != null) {
-            invoked = Integer.valueOf(current.toString());
-        }
-        invoked++;
-        // and store the state back on the properties
-        properties.put("invoked", invoked);
-
-        for(RoutingRule r : routingRules){
-           if (r.isMessageRoutable(body)){
-               return r.getDestination();
-           }
-        }
+    public String slip(String body,@Header(Exchange.SLIP_ENDPOINT) String previous) {
+
+        LOG.info("previous: " + previous);
+            if (routingRules.containsKey(previous) ){
+                return routingRules.get(previous).getDestination();
+            }
+        return null;
+
 
-        // no more so return null
-        return "direct:foo";
     }
 
-    public void addRoutingRules(@Properties Map<String,String> rules){
-        for(String key : rules.keySet()){
-            LOG.info(key + ">> setting up routes >>" + rules.get(key));
-            routingRules.add(new SimpleRoutingRule(key,rules.get(key)));
+    public void addRoutingRules(ArrayList<RoutingRule> routes){
+        String previous = null;
+        //previous endpoint will be the key lookup to maintain routing order
+        for(RoutingRule r : routes){
+
+            LOG.info(previous + ">> setting up routes >>" + r.getDestination());
+            routingRules.put(previous, new SimpleRoutingRule(r.getSource(),r.getDestination()));
+            previous = r.getDestination();
         }
 
     }

Modified: incubator/streams/trunk/streams-eip-routes/src/main/java/org/apache/streams/messaging/rules/impl/SimpleRoutingRule.java
URL: http://svn.apache.org/viewvc/incubator/streams/trunk/streams-eip-routes/src/main/java/org/apache/streams/messaging/rules/impl/SimpleRoutingRule.java?rev=1433510&r1=1433509&r2=1433510&view=diff
==============================================================================
--- incubator/streams/trunk/streams-eip-routes/src/main/java/org/apache/streams/messaging/rules/impl/SimpleRoutingRule.java
(original)
+++ incubator/streams/trunk/streams-eip-routes/src/main/java/org/apache/streams/messaging/rules/impl/SimpleRoutingRule.java
Tue Jan 15 16:46:05 2013
@@ -6,6 +6,7 @@ public class SimpleRoutingRule implement
     private String source;
     private String destination;
 
+    public SimpleRoutingRule(){}
     public SimpleRoutingRule(String source, String destination){
         setSource(source);
         setDestination(destination);

Modified: incubator/streams/trunk/streams-eip-routes/src/main/resources/META-INF/spring/camelContext.xml
URL: http://svn.apache.org/viewvc/incubator/streams/trunk/streams-eip-routes/src/main/resources/META-INF/spring/camelContext.xml?rev=1433510&r1=1433509&r2=1433510&view=diff
==============================================================================
--- incubator/streams/trunk/streams-eip-routes/src/main/resources/META-INF/spring/camelContext.xml
(original)
+++ incubator/streams/trunk/streams-eip-routes/src/main/resources/META-INF/spring/camelContext.xml
Tue Jan 15 16:46:05 2013
@@ -16,17 +16,19 @@
     <camelContext xmlns="http://camel.apache.org/schema/spring">
 
         <route>
+            <from uri="direct:foo"/>
+                <bean ref="myTransform" method="transform"/>
+            <to uri="log:ExampleRouter"/>
+        </route>
+
+        <route>
             <from uri="timer://myTimer?fixedRate=true&amp;period=10000"/>
             <dynamicRouter>
                 <method ref="activityRouter" method="slip"/>
             </dynamicRouter>
         </route>
 
-        <route>
-            <from uri="direct:foo"/>
-                <bean ref="myTransform" method="transform"/>
-            <to uri="log:ExampleRouter"/>
-        </route>
+
     </camelContext>
 
 </beans>
\ No newline at end of file

Modified: incubator/streams/trunk/streams-eip-routes/src/main/resources/META-INF/spring/osgi-component-import.xml
URL: http://svn.apache.org/viewvc/incubator/streams/trunk/streams-eip-routes/src/main/resources/META-INF/spring/osgi-component-import.xml?rev=1433510&r1=1433509&r2=1433510&view=diff
==============================================================================
--- incubator/streams/trunk/streams-eip-routes/src/main/resources/META-INF/spring/osgi-component-import.xml
(original)
+++ incubator/streams/trunk/streams-eip-routes/src/main/resources/META-INF/spring/osgi-component-import.xml
Tue Jan 15 16:46:05 2013
@@ -12,9 +12,12 @@
     <bean id="activityRouter" class="org.apache.streams.messaging.routers.impl.ActivityRouterImpl">
 
         <constructor-arg>
-            <map>
-                <entry key="timer://myTimer?fixedRate=true&amp;period=10000" value="direct:foo"/>
-            </map>
+            <list>
+                <bean class="org.apache.streams.messaging.rules.impl.SimpleRoutingRule">
+                    <property name="source" value="timer://myTimer?fixedRate=true&amp;period=10000"/>
+                    <property name="destination" value="direct:foo"/>
+                </bean>
+            </list>
         </constructor-arg>
     </bean>
 



Mime
View raw message