You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by me...@apache.org on 2007/01/21 23:01:53 UTC

svn commit: r498465 - in /incubator/tuscany/java/sca/services/discovery/jxta/src: main/java/org/apache/tuscany/service/discovery/jxta/ main/resources/ test/java/org/ test/java/org/apache/ test/java/org/apache/tuscany/ test/java/org/apache/tuscany/servi...

Author: meerajk
Date: Sun Jan 21 14:01:52 2007
New Revision: 498465

URL: http://svn.apache.org/viewvc?view=rev&rev=498465
Log:
Intermediate checkin.

Added:
    incubator/tuscany/java/sca/services/discovery/jxta/src/main/resources/pipe.adv
    incubator/tuscany/java/sca/services/discovery/jxta/src/test/java/org/
    incubator/tuscany/java/sca/services/discovery/jxta/src/test/java/org/apache/
    incubator/tuscany/java/sca/services/discovery/jxta/src/test/java/org/apache/tuscany/
    incubator/tuscany/java/sca/services/discovery/jxta/src/test/java/org/apache/tuscany/service/
    incubator/tuscany/java/sca/services/discovery/jxta/src/test/java/org/apache/tuscany/service/discovery/
    incubator/tuscany/java/sca/services/discovery/jxta/src/test/java/org/apache/tuscany/service/discovery/jxta/
    incubator/tuscany/java/sca/services/discovery/jxta/src/test/java/org/apache/tuscany/service/discovery/jxta/JxtaDiscoveryServiceTest.java   (with props)
Modified:
    incubator/tuscany/java/sca/services/discovery/jxta/src/main/java/org/apache/tuscany/service/discovery/jxta/AdvertismentHelper.java
    incubator/tuscany/java/sca/services/discovery/jxta/src/main/java/org/apache/tuscany/service/discovery/jxta/JxtaDiscoveryService.java
    incubator/tuscany/java/sca/services/discovery/jxta/src/main/java/org/apache/tuscany/service/discovery/jxta/PipeReceiver.java

Modified: incubator/tuscany/java/sca/services/discovery/jxta/src/main/java/org/apache/tuscany/service/discovery/jxta/AdvertismentHelper.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/discovery/jxta/src/main/java/org/apache/tuscany/service/discovery/jxta/AdvertismentHelper.java?view=diff&rev=498465&r1=498464&r2=498465
==============================================================================
--- incubator/tuscany/java/sca/services/discovery/jxta/src/main/java/org/apache/tuscany/service/discovery/jxta/AdvertismentHelper.java (original)
+++ incubator/tuscany/java/sca/services/discovery/jxta/src/main/java/org/apache/tuscany/service/discovery/jxta/AdvertismentHelper.java Sun Jan 21 14:01:52 2007
@@ -18,9 +18,15 @@
  */
 package org.apache.tuscany.service.discovery.jxta;
 
+import java.io.IOException;
+import java.io.InputStream;
 import java.net.URI;
 
 import net.jxta.document.AdvertisementFactory;
+import net.jxta.document.MimeMediaType;
+import net.jxta.document.StructuredDocument;
+import net.jxta.document.StructuredDocumentFactory;
+import net.jxta.document.XMLElement;
 import net.jxta.protocol.PipeAdvertisement;
 
 /**
@@ -30,32 +36,42 @@
  *
  */
 public abstract class AdvertismentHelper {
-    
+
     /**
      * Utility class constructor.
      */
     private AdvertismentHelper() {
     }
-    
+
     /**
      * Creates a pipe advertisment message for the domain.
      * 
      * @param domain Domain URI.
-     * @param profile Runtime profile.
+     * @param runtimeId Runtime Id.
      * @return Pipe advertisment message.
      */
-    public static PipeAdvertisement getDomainAdvertisment(URI domain, String profile) {
-        
-        StringBuffer sb = new StringBuffer("<jxta:PipeAdvertisement xmlns:jxta=\"http://jxta.org\">");
-        sb.append("<Domain>");
-        sb.append(domain);
-        sb.append("</Domain>");
-        sb.append("<Profile>");
-        sb.append(profile);
-        sb.append("</Profile>");
-        sb.append("</jxta:PipeAdvertisement");
+    public static PipeAdvertisement getDomainAdvertisment(URI domain, String runtimeId) {
+
+        InputStream in = null;
+        try {
+            in = AdvertismentHelper.class.getClassLoader().getResourceAsStream("pipe.adv");
+            StructuredDocument sd = StructuredDocumentFactory.newStructuredDocument(MimeMediaType.XMLUTF8, in);
+            XMLElement root = (XMLElement) sd.getRoot();
+            root.appendChild(sd.createElement("Domain", domain.toString()));
+            root.appendChild(sd.createElement("RuntimeId", runtimeId));
+            return (PipeAdvertisement)AdvertisementFactory.newAdvertisement(root);
+        } catch (IOException ex) {
+            throw new JxtaException(ex);
+        } finally {
+            try {
+                if (in != null) {
+                    in.close();
+                }
+            } catch (IOException ex) {
+                throw new JxtaException(ex);
+            }
+        }
         
-        return (PipeAdvertisement)AdvertisementFactory.newAdvertisement(sb.toString());
     }
-    
-}
\ No newline at end of file
+
+}

Modified: incubator/tuscany/java/sca/services/discovery/jxta/src/main/java/org/apache/tuscany/service/discovery/jxta/JxtaDiscoveryService.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/discovery/jxta/src/main/java/org/apache/tuscany/service/discovery/jxta/JxtaDiscoveryService.java?view=diff&rev=498465&r1=498464&r2=498465
==============================================================================
--- incubator/tuscany/java/sca/services/discovery/jxta/src/main/java/org/apache/tuscany/service/discovery/jxta/JxtaDiscoveryService.java (original)
+++ incubator/tuscany/java/sca/services/discovery/jxta/src/main/java/org/apache/tuscany/service/discovery/jxta/JxtaDiscoveryService.java Sun Jan 21 14:01:52 2007
@@ -26,6 +26,8 @@
 import javax.xml.stream.XMLStreamReader;
 
 import net.jxta.exception.PeerGroupException;
+import net.jxta.peergroup.NetPeerGroupFactory;
+import net.jxta.peergroup.PeerGroup;
 import net.jxta.platform.NetworkConfigurator;
 
 import org.apache.tuscany.host.RuntimeInfo;
@@ -66,11 +68,16 @@
 
             // Configure the platform
             configure();
+
+            PeerGroup netGroup = new NetPeerGroupFactory().getInterface();
+            URI domain = getRuntimeInfo().getDomain();
+            
+            // TODO Create and join the group
+            // PeerGroup domainGroup = netGroup.getParentGroup();
             
-            pipeReceiver = PipeReceiver.newInstance(this);
+            pipeReceiver = PipeReceiver.newInstance(this, netGroup);
 
             RuntimeInfo runtimeInfo = getRuntimeInfo();
-            URI domain = runtimeInfo.getDomain();
             String runtimeId = runtimeInfo.getRuntimeId();
 
             pipeReceiver.start(domain, runtimeId);
@@ -108,13 +115,18 @@
     private void configure() {
 
         try {
-            if (!configurator.exists()) {
-                configurator.save();
-            } else {
+            
+            // Set the peer name to runtime id.
+            configurator.setName(getRuntimeInfo().getRuntimeId());
+            
+            if (configurator.exists()) {
                 File pc = new File(configurator.getHome(), "PlatformConfig");
                 configurator.load(pc.toURI());
                 configurator.save();
+            } else {
+                configurator.save();
             }
+            
         } catch (IOException ex) {
             throw new JxtaException(ex);
         } catch (CertificateException ex) {

Modified: incubator/tuscany/java/sca/services/discovery/jxta/src/main/java/org/apache/tuscany/service/discovery/jxta/PipeReceiver.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/discovery/jxta/src/main/java/org/apache/tuscany/service/discovery/jxta/PipeReceiver.java?view=diff&rev=498465&r1=498464&r2=498465
==============================================================================
--- incubator/tuscany/java/sca/services/discovery/jxta/src/main/java/org/apache/tuscany/service/discovery/jxta/PipeReceiver.java (original)
+++ incubator/tuscany/java/sca/services/discovery/jxta/src/main/java/org/apache/tuscany/service/discovery/jxta/PipeReceiver.java Sun Jan 21 14:01:52 2007
@@ -26,7 +26,6 @@
 
 import net.jxta.exception.PeerGroupException;
 import net.jxta.peergroup.PeerGroup;
-import net.jxta.peergroup.PeerGroupFactory;
 import net.jxta.pipe.InputPipe;
 import net.jxta.pipe.PipeMsgEvent;
 import net.jxta.pipe.PipeMsgListener;
@@ -46,9 +45,6 @@
     /** Discovery service. */
     private JxtaDiscoveryService discoveryService;
     
-    /** Net peer group. */
-    private PeerGroup peerGroup;
-    
     /** Pipe service. */
     private PipeService pipeService;
     
@@ -59,14 +55,13 @@
      * Initializes the message listener.
      * 
      * @param discoveryService JXTA discovery service.
+     * @param domainGroup Domain peer group for this service.
      * @throws PeerGroupException If unable to create Peer group.
      */
-    private PipeReceiver(JxtaDiscoveryService discoveryService) throws PeerGroupException {
+    private PipeReceiver(JxtaDiscoveryService discoveryService, PeerGroup domainGroup) throws PeerGroupException {
         
         this.discoveryService = discoveryService;
-
-        peerGroup = PeerGroupFactory.newNetPeerGroup();
-        pipeService = peerGroup.getPipeService();
+        pipeService = domainGroup.getPipeService();
         
     }
     
@@ -75,14 +70,15 @@
      * 
      * @param discoveryService JXTA discovery service.
      * @throws PeerGroupException If unable to create Peer group.
+     * @throws PeerGroupException If unable to create Peer group.
      */
-    public static PipeReceiver newInstance(JxtaDiscoveryService discoveryService) throws PeerGroupException {
+    public static PipeReceiver newInstance(JxtaDiscoveryService discoveryService, PeerGroup domainGroup) throws PeerGroupException {
         
         if(discoveryService == null) {
             throw new IllegalArgumentException("Discovery service is null");
         }
         
-        return new PipeReceiver(discoveryService);
+        return new PipeReceiver(discoveryService, domainGroup);
         
     }
     

Added: incubator/tuscany/java/sca/services/discovery/jxta/src/main/resources/pipe.adv
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/discovery/jxta/src/main/resources/pipe.adv?view=auto&rev=498465
==============================================================================
--- incubator/tuscany/java/sca/services/discovery/jxta/src/main/resources/pipe.adv (added)
+++ incubator/tuscany/java/sca/services/discovery/jxta/src/main/resources/pipe.adv Sun Jan 21 14:01:52 2007
@@ -0,0 +1,6 @@
+<!DOCTYPE jxta:PipeAdvertisement>
+<jxta:PipeAdvertisement xmlns:jxta="http://jxta.org">
+    <Id>urn:jxta:uuid-59616261646162614A757874614D504725184FBC4E5D498AA0919F662E40028B04</Id>
+	<Type>JxtaUnicast</Type>
+	<Name>TuscanyPipe</Name>
+</jxta:PipeAdvertisement>
\ No newline at end of file

Added: incubator/tuscany/java/sca/services/discovery/jxta/src/test/java/org/apache/tuscany/service/discovery/jxta/JxtaDiscoveryServiceTest.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/discovery/jxta/src/test/java/org/apache/tuscany/service/discovery/jxta/JxtaDiscoveryServiceTest.java?view=auto&rev=498465
==============================================================================
--- incubator/tuscany/java/sca/services/discovery/jxta/src/test/java/org/apache/tuscany/service/discovery/jxta/JxtaDiscoveryServiceTest.java (added)
+++ incubator/tuscany/java/sca/services/discovery/jxta/src/test/java/org/apache/tuscany/service/discovery/jxta/JxtaDiscoveryServiceTest.java Sun Jan 21 14:01:52 2007
@@ -0,0 +1,85 @@
+/*
+ * 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.service.discovery.jxta;
+
+import java.io.File;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+
+import net.jxta.platform.NetworkConfigurator;
+
+import org.apache.tuscany.host.RuntimeInfo;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Revision$ $Date$
+ *
+ */
+public class JxtaDiscoveryServiceTest extends TestCase {
+
+    public JxtaDiscoveryServiceTest(String name) {
+        super(name);
+    }
+
+    protected void setUp() throws Exception {
+    }
+
+    protected void tearDown() throws Exception {
+    }
+
+    public void testStartAndStop() {
+        
+        JxtaDiscoveryService discoveryService = new JxtaDiscoveryService();
+        RuntimeInfo runtimeInfo = new RuntimeInfo() {
+            public File getApplicationRootDirectory() {
+                return null;
+            }
+            public URL getBaseURL() {
+                return null;
+            }
+            public URI getDomain() {
+                try {
+                    return new URI("test-domain");
+                } catch (URISyntaxException ex) {
+                    throw new RuntimeException(ex);
+                }
+            }
+            public String getRuntimeId() {
+                return "test-runtime";
+            }
+            public boolean isOnline() {
+                return false;
+            }
+            
+        };
+        discoveryService.setRuntimeInfo(runtimeInfo);
+        
+        NetworkConfigurator configurator = new NetworkConfigurator();
+        configurator.setPrincipal("test-user");
+        configurator.setPassword("test-password");
+        
+        discoveryService.setConfigurator(configurator);
+        discoveryService.start();
+        discoveryService.stop();
+        
+    }
+
+}

Propchange: incubator/tuscany/java/sca/services/discovery/jxta/src/test/java/org/apache/tuscany/service/discovery/jxta/JxtaDiscoveryServiceTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/services/discovery/jxta/src/test/java/org/apache/tuscany/service/discovery/jxta/JxtaDiscoveryServiceTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org