Author: antelder
Date: Fri Oct  9 15:13:57 2009
New Revision: 823579

URL: http://svn.apache.org/viewvc?rev=823579&view=rev
Log:
Start adding support for static routes in th etribes endpoint registry

Modified:
    
tuscany/java/sca/modules/endpoint-tribes/src/main/java/org/apache/tuscany/sca/endpoint/tribes/ReplicatedEndpointRegistry.java

Modified: 
tuscany/java/sca/modules/endpoint-tribes/src/main/java/org/apache/tuscany/sca/endpoint/tribes/ReplicatedEndpointRegistry.java
URL: 
http://svn.apache.org/viewvc/tuscany/java/sca/modules/endpoint-tribes/src/main/java/org/apache/tuscany/sca/endpoint/tribes/ReplicatedEndpointRegistry.java?rev=823579&r1=823578&r2=823579&view=diff
==============================================================================
--- 
tuscany/java/sca/modules/endpoint-tribes/src/main/java/org/apache/tuscany/sca/endpoint/tribes/ReplicatedEndpointRegistry.java
 (original)
+++ 
tuscany/java/sca/modules/endpoint-tribes/src/main/java/org/apache/tuscany/sca/endpoint/tribes/ReplicatedEndpointRegistry.java
 Fri Oct  9 15:13:57 2009
@@ -19,12 +19,16 @@
 
 package org.apache.tuscany.sca.endpoint.tribes;
 
+import java.io.IOException;
 import java.net.InetAddress;
+import java.net.MalformedURLException;
 import java.net.NetworkInterface;
+import java.net.URL;
 import java.util.ArrayList;
 import java.util.Enumeration;
 import java.util.List;
 import java.util.Map;
+import java.util.StringTokenizer;
 import java.util.UUID;
 import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.logging.Level;
@@ -32,8 +36,14 @@
 
 import org.apache.catalina.tribes.Channel;
 import org.apache.catalina.tribes.ChannelException;
+import org.apache.catalina.tribes.ChannelInterceptor;
+import org.apache.catalina.tribes.Member;
+import org.apache.catalina.tribes.group.ChannelCoordinator;
 import org.apache.catalina.tribes.group.GroupChannel;
+import 
org.apache.catalina.tribes.group.interceptors.MessageDispatchInterceptor;
+import 
org.apache.catalina.tribes.group.interceptors.StaticMembershipInterceptor;
 import org.apache.catalina.tribes.membership.McastService;
+import org.apache.catalina.tribes.membership.StaticMember;
 import org.apache.tuscany.sca.assembly.Endpoint;
 import org.apache.tuscany.sca.assembly.EndpointReference;
 import org.apache.tuscany.sca.core.ExtensionPointRegistry;
@@ -65,6 +75,7 @@
 
     private ExtensionPointRegistry registry;
     private ReplicatedMap map;
+    private static List<URL> staticRoutes;
 
     private static final Channel createChannel(String address, int port, 
String bindAddress) {
 
@@ -117,6 +128,19 @@
         if (timeoutStr != null) {
             timeout = Integer.parseInt(timeoutStr);
         }
+
+        String routesStr = attributes.get("routes");
+        if (routesStr != null) {
+            StringTokenizer st = new StringTokenizer(routesStr);
+            staticRoutes = new ArrayList<URL>();
+            while (st.hasMoreElements()) {
+                try {
+                    staticRoutes.add(new URL("http://"; + st.nextToken()));
+                } catch (MalformedURLException e) {
+                    throw new RuntimeException(e);
+                }
+            }
+        }
     }
 
     public ReplicatedEndpointRegistry(String domainURI) {
@@ -137,6 +161,24 @@
         } catch (ChannelException e) {
             throw new IllegalStateException(e);
         }
+        
+        if (staticRoutes != null) {
+            StaticMembershipInterceptor smi = new 
StaticMembershipInterceptor();
+            for (URL staticRoute : staticRoutes) {
+                Member member;
+                try {
+                    member = new StaticMember(staticRoute.getHost(), 
staticRoute.getPort(), 5000);
+                } catch (IOException e) {
+                    throw new RuntimeException(e);
+                }
+                smi.addStaticMember(member);
+                logger.info("Added static route: " + staticRoute.getHost() + 
":" + staticRoute.getPort());
+            }
+            smi.setLocalMember(map.getChannel().getLocalMember(false));
+            map.getChannel().addInterceptor(smi);
+        }
+        
+        
     }
 
     public void stop() {


Reply via email to