You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by rf...@apache.org on 2009/10/14 18:20:24 UTC
svn commit: r825179 -
/tuscany/java/sca/modules/endpoint-tribes/src/main/java/org/apache/tuscany/sca/endpoint/tribes/ReplicatedEndpointRegistry.java
Author: rfeng
Date: Wed Oct 14 16:20:24 2009
New Revision: 825179
URL: http://svn.apache.org/viewvc?rev=825179&view=rev
Log:
Use URI over URL
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=825179&r1=825178&r2=825179&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 Wed Oct 14 16:20:24 2009
@@ -22,10 +22,8 @@
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.InetAddress;
-import java.net.MalformedURLException;
import java.net.NetworkInterface;
import java.net.URI;
-import java.net.URL;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Enumeration;
@@ -74,8 +72,8 @@
private ExtensionPointRegistry registry;
private ReplicatedMap map;
- private static List<URL> staticRoutes;
-
+ private static List<URI> staticRoutes;
+
private String id;
private static final Channel createChannel(String address, int port, String bindAddress) {
@@ -106,14 +104,21 @@
this.registry = registry;
this.domainURI = domainURI;
this.id = "[" + System.identityHashCode(this) + "]";
- getParameters(domainRegistryURI);
+ getParameters(attributes, domainRegistryURI);
}
-
- private Map<String, String> getParameters(String domainRegistryURI) {
+
+ private Map<String, String> getParameters(Map<String, String> attributes, String domainRegistryURI) {
Map<String, String> map = new HashMap<String, String>();
+ if (attributes != null) {
+ map.putAll(attributes);
+ }
URI uri = URI.create(domainRegistryURI);
- map.put("address", uri.getHost());
- map.put("port", String.valueOf(uri.getPort()));
+ if (uri.getHost() != null) {
+ map.put("address", uri.getHost());
+ }
+ if (uri.getPort() != -1) {
+ map.put("port", String.valueOf(uri.getPort()));
+ }
int index = domainRegistryURI.indexOf('?');
if (index == -1) {
setConfig(map);
@@ -157,13 +162,9 @@
String routesStr = attributes.get("routes");
if (routesStr != null) {
StringTokenizer st = new StringTokenizer(routesStr);
- staticRoutes = new ArrayList<URL>();
+ staticRoutes = new ArrayList<URI>();
while (st.hasMoreElements()) {
- try {
- staticRoutes.add(new URL("http://" + st.nextToken()));
- } catch (MalformedURLException e) {
- throw new RuntimeException(e);
- }
+ staticRoutes.add(URI.create("tcp://" + st.nextToken()));
}
}
}
@@ -179,7 +180,7 @@
if (staticRoutes != null) {
StaticMembershipInterceptor smi = new StaticMembershipInterceptor();
- for (URL staticRoute : staticRoutes) {
+ for (URI staticRoute : staticRoutes) {
Member member;
try {
member = new StaticMember(staticRoute.getHost(), staticRoute.getPort(), 5000);
@@ -192,13 +193,13 @@
smi.setLocalMember(map.getChannel().getLocalMember(false));
map.getChannel().addInterceptor(smi);
}
-
+
try {
map.getChannel().start(Channel.DEFAULT);
} catch (ChannelException e) {
throw new IllegalStateException(e);
}
-
+
}
public void stop() {
@@ -338,7 +339,7 @@
public void removeListener(EndpointListener listener) {
listeners.remove(listener);
}
-
+
public void replicate(boolean complete) {
map.replicate(complete);
}