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:22:13 UTC

svn commit: r498467 - in /incubator/tuscany/java/sca/services/discovery/jxta/src/main/java/org/apache/tuscany/service/discovery/jxta: AdvertismentHelper.java JxtaDiscoveryService.java PipeReceiver.java

Author: meerajk
Date: Sun Jan 21 14:22:12 2007
New Revision: 498467

URL: http://svn.apache.org/viewvc?view=rev&rev=498467
Log:
Working version of a runtime creating and joining the peer 
group for the domain.

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=498467&r1=498466&r2=498467
==============================================================================
--- 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:22:12 2007
@@ -20,7 +20,6 @@
 
 import java.io.IOException;
 import java.io.InputStream;
-import java.net.URI;
 
 import net.jxta.document.AdvertisementFactory;
 import net.jxta.document.MimeMediaType;
@@ -50,14 +49,14 @@
      * @param runtimeId Runtime Id.
      * @return Pipe advertisment message.
      */
-    public static PipeAdvertisement getDomainAdvertisment(URI domain, String runtimeId) {
+    public static PipeAdvertisement getDomainAdvertisment(String 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("Domain", domain));
             root.appendChild(sd.createElement("RuntimeId", runtimeId));
             return (PipeAdvertisement)AdvertisementFactory.newAdvertisement(root);
         } catch (IOException ex) {

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=498467&r1=498466&r2=498467
==============================================================================
--- 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:22:12 2007
@@ -20,19 +20,23 @@
 
 import java.io.File;
 import java.io.IOException;
-import java.net.URI;
 
 import javax.security.cert.CertificateException;
 import javax.xml.stream.XMLStreamReader;
 
+import net.jxta.credential.AuthenticationCredential;
 import net.jxta.exception.PeerGroupException;
+import net.jxta.membership.Authenticator;
+import net.jxta.membership.MembershipService;
 import net.jxta.peergroup.NetPeerGroupFactory;
 import net.jxta.peergroup.PeerGroup;
 import net.jxta.platform.NetworkConfigurator;
+import net.jxta.protocol.ModuleImplAdvertisement;
 
 import org.apache.tuscany.host.RuntimeInfo;
 import org.apache.tuscany.spi.annotation.Autowire;
 import org.apache.tuscany.spi.services.discovery.AbstractDiscoveryService;
+import org.omg.CORBA.Any;
 
 /**
  * Discovery service implemented using Apple bonjour.
@@ -68,14 +72,10 @@
 
             // Configure the platform
             configure();
+            String domain = getRuntimeInfo().getDomain().toString();
 
-            PeerGroup netGroup = new NetPeerGroupFactory().getInterface();
-            URI domain = getRuntimeInfo().getDomain();
-            
-            // TODO Create and join the group
-            // PeerGroup domainGroup = netGroup.getParentGroup();
-            
-            pipeReceiver = PipeReceiver.newInstance(this, netGroup);
+            PeerGroup domainGroup = createAndJoinDomainGroup();            
+            pipeReceiver = PipeReceiver.newInstance(this, domainGroup);
 
             RuntimeInfo runtimeInfo = getRuntimeInfo();
             String runtimeId = runtimeInfo.getRuntimeId();
@@ -86,6 +86,8 @@
             throw new JxtaException(ex);
         } catch (IOException ex) {
             throw new JxtaException(ex);
+        } catch (Exception ex) {
+            throw new JxtaException(ex);
         }
 
     }
@@ -116,7 +118,6 @@
 
         try {
             
-            // Set the peer name to runtime id.
             configurator.setName(getRuntimeInfo().getRuntimeId());
             
             if (configurator.exists()) {
@@ -132,6 +133,33 @@
         } catch (CertificateException ex) {
             throw new JxtaException(ex);
         }
+        
+    }
+
+    /**
+     * Creates and joins the domain peer group.
+     * @return Domain peer group.
+     * @throws Exception In case of unexpected JXTA exceptions.
+     */
+    private PeerGroup createAndJoinDomainGroup() throws Exception {
+        
+        PeerGroup netGroup = new NetPeerGroupFactory().getInterface();
+            
+        ModuleImplAdvertisement implAdv = netGroup.getAllPurposePeerGroupImplAdvertisement();
+        PeerGroup domainGroup = netGroup.newGroup(null, implAdv, "JoinTest", "testing group adv");
+        domainGroup.getDiscoveryService().remotePublish(domainGroup.getPeerGroupAdvertisement());
+            
+        AuthenticationCredential authCred = new AuthenticationCredential(domainGroup, null, null);
+        MembershipService membership = domainGroup.getMembershipService();
+        Authenticator auth = membership.apply(authCred);
+                
+        if (auth.isReadyForJoin()){
+            membership.join(auth);
+        } else {
+            throw new JxtaException("Unable to join domain group");
+        }
+        return domainGroup;
+        
     }
 
 }

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=498467&r1=498466&r2=498467
==============================================================================
--- 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:22:12 2007
@@ -19,7 +19,6 @@
 package org.apache.tuscany.service.discovery.jxta;
 
 import java.io.IOException;
-import java.net.URI;
 
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamReader;
@@ -88,7 +87,7 @@
      * @param profile Profile name of the runtime.
      * @throws IOException In case of unexpected IO error.
      */
-    public void start(URI domain, String profile) throws IOException {  
+    public void start(String domain, String profile) throws IOException {  
         
         if(domain == null) {
             throw new IllegalArgumentException("Domain is null");



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