tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rf...@apache.org
Subject svn commit: r782800 - in /tuscany/java/sca/modules/endpoint-tribes: ./ META-INF/ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/tuscany/ src/main/java/org/apache/tuscany/sca/ src/main/java/org/apache...
Date Mon, 08 Jun 2009 21:44:15 GMT
Author: rfeng
Date: Mon Jun  8 21:44:14 2009
New Revision: 782800

URL: http://svn.apache.org/viewvc?rev=782800&view=rev
Log:
Start to add an Apache Tomcat Tribes based replicated EndpointRegistry

Added:
    tuscany/java/sca/modules/endpoint-tribes/   (with props)
    tuscany/java/sca/modules/endpoint-tribes/META-INF/
    tuscany/java/sca/modules/endpoint-tribes/META-INF/MANIFEST.MF
    tuscany/java/sca/modules/endpoint-tribes/pom.xml
    tuscany/java/sca/modules/endpoint-tribes/src/
    tuscany/java/sca/modules/endpoint-tribes/src/main/
    tuscany/java/sca/modules/endpoint-tribes/src/main/java/
    tuscany/java/sca/modules/endpoint-tribes/src/main/java/org/
    tuscany/java/sca/modules/endpoint-tribes/src/main/java/org/apache/
    tuscany/java/sca/modules/endpoint-tribes/src/main/java/org/apache/tuscany/
    tuscany/java/sca/modules/endpoint-tribes/src/main/java/org/apache/tuscany/sca/
    tuscany/java/sca/modules/endpoint-tribes/src/main/java/org/apache/tuscany/sca/endpoint/
    tuscany/java/sca/modules/endpoint-tribes/src/main/java/org/apache/tuscany/sca/endpoint/tribes/
    tuscany/java/sca/modules/endpoint-tribes/src/main/java/org/apache/tuscany/sca/endpoint/tribes/ReplicatedEndpointRegistry.java
    tuscany/java/sca/modules/endpoint-tribes/src/main/resources/
    tuscany/java/sca/modules/endpoint-tribes/src/main/resources/META-INF/
    tuscany/java/sca/modules/endpoint-tribes/src/main/resources/META-INF/services/
    tuscany/java/sca/modules/endpoint-tribes/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.EndpointRegistry

Propchange: tuscany/java/sca/modules/endpoint-tribes/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Jun  8 21:44:14 2009
@@ -0,0 +1,20 @@
+target
+work
+dojo
+*.iws
+*.ipr
+*.iml
+derby.log
+maven.log
+maven-eclipse.xml
+build.xml
+build-dependency.xml
+velocity.log*
+junit*.properties
+surefire*.properties
+.project
+.classpath
+.settings
+.deployables
+.wtpmodules
+.externalToolBuilders

Added: tuscany/java/sca/modules/endpoint-tribes/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/endpoint-tribes/META-INF/MANIFEST.MF?rev=782800&view=auto
==============================================================================
--- tuscany/java/sca/modules/endpoint-tribes/META-INF/MANIFEST.MF (added)
+++ tuscany/java/sca/modules/endpoint-tribes/META-INF/MANIFEST.MF Mon Jun  8 21:44:14 2009
@@ -0,0 +1,17 @@
+Manifest-Version: 1.0
+Private-Package: org.apache.tuscany.sca.xsd.impl;version="2.0.0"
+Tool: Bnd-0.0.255
+Bundle-Name: Apache Tuscany SCA Tomcat Tribes Based EndPoint Registry
+Created-By: 1.6.0_07 (Sun Microsystems Inc.)
+Bundle-Vendor: The Apache Software Foundation
+Bundle-Version: 2.0.0
+Bnd-LastModified: 1225397174343
+Bundle-ManifestVersion: 2
+Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt
+Bundle-Description: Apache Tuscany SCA XSD Model
+Bundle-SymbolicName: org.apache.tuscany.sca.endpoint.tribes
+Bundle-DocURL: http://www.apache.org/
+Bundle-RequiredExecutionEnvironment: J2SE-1.5,JavaSE-1.6
+Import-Package: org.apache.tuscany.sca.assembly;version="2.0.0",
+ org.apache.tuscany.sca.policy;version="2.0.0",
+ org.apache.tuscany.sca.runtime;version="2.0.0"

Added: tuscany/java/sca/modules/endpoint-tribes/pom.xml
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/endpoint-tribes/pom.xml?rev=782800&view=auto
==============================================================================
--- tuscany/java/sca/modules/endpoint-tribes/pom.xml (added)
+++ tuscany/java/sca/modules/endpoint-tribes/pom.xml Mon Jun  8 21:44:14 2009
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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.
+-->
+<project>
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.tuscany.sca</groupId>
+        <artifactId>tuscany-modules</artifactId>
+        <version>2.0-SNAPSHOT</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+    <artifactId>tuscany-endpoint-tribes</artifactId>
+    <name>Apache Tuscany SCA Tomcat Tribes Based EndPoint Registry</name>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.tomcat</groupId>
+            <artifactId>tribes</artifactId>
+            <version>6.0.18</version>
+            <scope>compile</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.tuscany.sca</groupId>
+            <artifactId>tuscany-core-spi</artifactId>
+            <version>2.0-SNAPSHOT</version>
+            <scope>compile</scope>
+        </dependency>
+    </dependencies>
+
+</project>

Added: 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=782800&view=auto
==============================================================================
--- tuscany/java/sca/modules/endpoint-tribes/src/main/java/org/apache/tuscany/sca/endpoint/tribes/ReplicatedEndpointRegistry.java
(added)
+++ tuscany/java/sca/modules/endpoint-tribes/src/main/java/org/apache/tuscany/sca/endpoint/tribes/ReplicatedEndpointRegistry.java
Mon Jun  8 21:44:14 2009
@@ -0,0 +1,211 @@
+/*
+ * 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.tuscany.sca.endpoint.tribes;
+
+import java.net.InetAddress;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.logging.Logger;
+
+import org.apache.catalina.tribes.Channel;
+import org.apache.catalina.tribes.ChannelException;
+import org.apache.catalina.tribes.group.GroupChannel;
+import org.apache.catalina.tribes.membership.McastService;
+import org.apache.catalina.tribes.tipis.AbstractReplicatedMap;
+import org.apache.catalina.tribes.tipis.ReplicatedMap;
+import org.apache.tuscany.sca.assembly.Endpoint2;
+import org.apache.tuscany.sca.assembly.EndpointReference2;
+import org.apache.tuscany.sca.runtime.EndpointListener;
+import org.apache.tuscany.sca.runtime.EndpointRegistry;
+
+public class ReplicatedEndpointRegistry implements EndpointRegistry {
+    private final static Logger logger = Logger.getLogger(ReplicatedEndpointRegistry.class.getName());
+    private static final String MULTICAST_ADDRESS = "228.0.0.100";
+    private static final int MULTICAST_PORT = 50000;
+    private String domainURI;
+
+    private List<EndpointReference2> endpointreferences = new CopyOnWriteArrayList<EndpointReference2>();
+    private List<EndpointListener> listeners = new CopyOnWriteArrayList<EndpointListener>();
+
+    private ReplicatedMap map;
+
+    private static final Channel createChannel(String address, int port, String bindAddress)
{
+
+        //create a channel
+        GroupChannel channel = new GroupChannel();
+        McastService mcastService = (McastService)channel.getMembershipService();
+        mcastService.setPort(port);
+        mcastService.setAddress(address);
+
+        // REVIEW: In my case, there are multiple IP addresses
+        // One for the WIFI and the other one for VPN. For some reason the VPN one doesn't
support
+        // Multicast
+        if (bindAddress != null) {
+            mcastService.setBind(bindAddress);
+        }
+
+        try {
+            channel.start(Channel.DEFAULT);
+        } catch (ChannelException e) {
+            throw new IllegalStateException(e);
+        }
+        return channel;
+    }
+
+    public ReplicatedEndpointRegistry(String domainURI) {
+        this.domainURI = domainURI;
+        map =
+            new ReplicatedMap(null, createChannel(MULTICAST_ADDRESS, MULTICAST_PORT, null),
50, domainURI,
+                              new ClassLoader[] {ReplicatedEndpointRegistry.class.getClassLoader()});
+    }
+
+    public void addEndpoint(Endpoint2 endpoint) {
+        map.put(getURI(endpoint), endpoint);
+        for (EndpointListener listener : listeners) {
+            listener.endpointAdded(endpoint);
+        }
+        logger.info("EndpointRegistry: Add endpoint - " + endpoint);
+    }
+
+    public void addEndpointReference(EndpointReference2 endpointReference) {
+        endpointreferences.add(endpointReference);
+        logger.info("EndpointRegistry: Add endpoint reference - " + endpointReference);
+    }
+
+    public void addListener(EndpointListener listener) {
+        listeners.add(listener);
+    }
+
+    public List<Endpoint2> findEndpoint(EndpointReference2 endpointReference) {
+        List<Endpoint2> foundEndpoints = new ArrayList<Endpoint2>();
+
+        logger.info("EndpointRegistry: Find endpoint for reference - " + endpointReference);
+
+        if (endpointReference.getReference() != null) {
+            Endpoint2 targetEndpoint = endpointReference.getTargetEndpoint();
+            for (Object v : map.values()) {
+                Endpoint2 endpoint = (Endpoint2)v;
+                // TODO: implement more complete matching
+                if (endpoint.getComponentName().equals(targetEndpoint.getComponentName()))
{
+                    if ((targetEndpoint.getServiceName() != null) && (endpoint.getServiceName().equals(targetEndpoint
+                        .getServiceName()))) {
+                        foundEndpoints.add(endpoint);
+                        logger.info("EndpointRegistry: Found endpoint with matching service
 - " + endpoint);
+                    } else if (targetEndpoint.getServiceName() == null) {
+                        foundEndpoints.add(endpoint);
+                        logger.info("EndpointRegistry: Found endpoint with matching component
 - " + endpoint);
+                    }
+                    // else the service name doesn't match
+                }
+            }
+        }
+        return foundEndpoints;
+    }
+
+    public List<EndpointReference2> findEndpointReference(Endpoint2 endpoint) {
+        return endpointreferences;
+    }
+
+    public Endpoint2 getEndpoint(String uri) {
+        return (Endpoint2)map.get(uri);
+    }
+
+    public List<EndpointReference2> getEndpointRefereneces() {
+        return endpointreferences;
+    }
+
+    public List<Endpoint2> getEndpoints() {
+        return new ArrayList<Endpoint2>(map.values());
+    }
+
+    public List<EndpointListener> getListeners() {
+        return listeners;
+    }
+
+    private String getURI(Endpoint2 ep) {
+        String bindingName = ep.getBinding().getName();
+        if (bindingName == null) {
+            bindingName = ep.getService().getName();
+        }
+        String epURI = ep.getComponent().getURI() + "#" + ep.getService().getName() + "/"
+ bindingName;
+        return epURI;
+    }
+
+    public void removeEndpoint(Endpoint2 endpoint) {
+        map.remove(getURI(endpoint));
+        for (EndpointListener listener : listeners) {
+            listener.endpointRemoved(endpoint);
+        }
+        logger.info("EndpointRegistry: Remove endpoint - " + endpoint);
+    }
+
+    public void removeEndpointReference(EndpointReference2 endpointReference) {
+        endpointreferences.remove(endpointReference);
+        logger.info("EndpointRegistry: Remove endpoint reference - " + endpointReference);
+    }
+
+    public void removeListener(EndpointListener listener) {
+        listeners.remove(listener);
+    }
+
+    public void updateEndpoint(String uri, Endpoint2 endpoint) {
+        Endpoint2 oldEndpoint = getEndpoint(uri);
+        if (oldEndpoint == null) {
+            throw new IllegalArgumentException("Endpoint is not found: " + uri);
+        }
+        map.put(getURI(endpoint), endpoint);
+        for (EndpointListener listener : listeners) {
+            listener.endpointUpdated(oldEndpoint, endpoint);
+        }
+    }
+
+    public static void main(String[] args) throws Exception {
+        //create a channel
+        GroupChannel channel = new GroupChannel();
+        McastService mcastService = (McastService)channel.getMembershipService();
+        mcastService.setPort(MULTICAST_PORT);
+        mcastService.setAddress(MULTICAST_ADDRESS);
+
+        InetAddress localhost = InetAddress.getLocalHost();
+
+        // REVIEW: In my case, there are multiple IP addresses
+        // One for the WIFI and the other one for VPN. For some reason the VPN one doesn't
support
+        // Multicast
+        mcastService.setBind("192.168.1.100");
+        channel.start(Channel.DEFAULT);
+        ReplicatedMap map = new ReplicatedMap(null, channel, 50, "01", null);
+        map.put(UUID.randomUUID().toString(), localhost.getHostAddress());
+        for (int i = 0; i < 5; i++) {
+            Thread.sleep(2000);
+            System.out.println(localhost + ": " + map.keySet());
+        }
+        for(Object e: map.entrySetFull()) {
+            Map.Entry en = (Map.Entry) e;
+            AbstractReplicatedMap.MapEntry entry = (AbstractReplicatedMap.MapEntry) en.getValue();
+            entry.isPrimary();
+        }
+        map.breakdown();
+        channel.stop(Channel.DEFAULT);
+    }
+
+}

Added: tuscany/java/sca/modules/endpoint-tribes/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.EndpointRegistry
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/endpoint-tribes/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.EndpointRegistry?rev=782800&view=auto
==============================================================================
--- tuscany/java/sca/modules/endpoint-tribes/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.EndpointRegistry
(added)
+++ tuscany/java/sca/modules/endpoint-tribes/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.EndpointRegistry
Mon Jun  8 21:44:14 2009
@@ -0,0 +1,17 @@
+# 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.
+org.apache.tuscany.sca.endpoint.tribes.ReplicatedEndpointRegistry
\ No newline at end of file



Mime
View raw message