⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rootws.java

📁 jxme的一些相关程序,主要是手机上程序开发以及手机和计算机通信的一些程序资料,程序编译需要Ant支持
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package net.jxta.impl.satellaws.rootpeers;

import net.jxta.platform.*;
import net.jxta.document.*;
import net.jxta.id.IDFactory;
import net.jxta.peergroup.*;
import net.jxta.exception.*;
import net.jxta.endpoint.*;
import net.jxta.pipe.*;
import net.jxta.protocol.*;
import net.jxta.discovery.*;
import net.jxta.credential.AuthenticationCredential;
import net.jxta.membership.Authenticator;
import net.jxta.membership.MembershipService;

// The impl imports should not be needed.  These imports indicate
// omissions from the JXTA API.
import net.jxta.impl.peergroup.Platform;
import net.jxta.impl.peergroup.GenericPeerGroup;

import net.jxta.impl.id.UUID.UUID;
import net.jxta.impl.id.UUID.UUIDFactory;

import java.util.*;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;


public class RootWS  {
    
    private PeerGroup  originalGroup, satellaGroup;
    private static RootWS satellaRoot;

    /** Creates new RootWS */
    public RootWS() {
        Hashtable loginAndPasswd;
        PeerGroup satellaGroup;
        loginAndPasswd=new Hashtable();
        
        // Starts the JXTA Platform (thanks IP2P for the method)
        originalGroup=this.startJxta();

        // Create the accounts
        // This is the 3 Peer Group Accounts that are created for the Satella 
        // Peer Group
        // For instance, user login is rootpeers and passwd is RULE

        loginAndPasswd.put ("rootpeers", "ROCK");
        loginAndPasswd.put ("guests", "WHATEVER");
        loginAndPasswd.put ("datapeers", "SHARE");
        
        // Create Peer Group Satella from Scratch.
        satellaGroup=createSatellaGroup (originalGroup, loginAndPasswd);
        
        // Join the Satella Group
        this.joinSatellaGroup(satellaGroup);
        
    }
    
    private PeerGroup startJxta() {
        PeerGroup platformGroup = null;
        PeerGroup netPeerGroup  = null;

        try {
            // start the netpeergroup
            netPeerGroup = PeerGroupFactory.newNetPeerGroup();

        } catch ( PeerGroupException e) {
            // could not instanciate the group, print the stack and exit
            System.out.println("fatal error : group creation failure");
            e.printStackTrace();
            System.exit(1);
        }
        return netPeerGroup;
    }
    
    public static void main (String args[]) {
    satellaRoot = new RootWS();
    }
 
    private PeerGroup createSatellaGroup (PeerGroup parentGroup, 
    Hashtable userPasswdHashtable) {
        PeerGroupAdvertisement parentGroupAdv, satellaGroupAdv=null;
        PeerGroup satellaPeerGroup ;
    
        //Create the satella Peer Group
        satellaPeerGroup=PeerGroupFactory.newPeerGroup();
        if (satellaPeerGroup == null) 
            System.err.println("SatellaRoot: SatellaPeerGroup is null");
        
        // Get the Adeertisement of the parentGroup
        parentGroupAdv=parentGroup.getPeerGroupAdvertisement();

        // Create the satella Peer Group Advertisement
        satellaGroupAdv=createSatellaGroupAdvertisement (parentGroupAdv, userPasswdHashtable);
        if (satellaGroupAdv == null) 
            System.err.println("SatellaRoot: SatellaGroupAdv is null");
        
        // Associate the Satella Peer Group with the Satella Peer Group
        // Advertisement
        try {
              satellaPeerGroup.init(parentGroup,satellaGroupAdv);
        } catch (Exception e){
              e.printStackTrace();
              System.err.println("SatellaRoot: Could not init Peer Group from Advertisement");
        }

        // Publish it locally.
        // Remote Publishing is done already by the init() method
        // Thanks Seb for the clarification 
        DiscoveryService disco = parentGroup.getDiscoveryService();
        try {
            disco.publish(satellaGroupAdv, DiscoveryService.GROUP);
        } catch (Exception e) {
            e.printStackTrace();
            System.err.println("SatellaRoot: Could not locally publish Satella Group advertisement");
        }

        System.out.println("Satella Group Created");
        return (satellaPeerGroup);
    }
    

    private PeerGroupAdvertisement createSatellaGroupAdvertisement ( 
                           PeerGroupAdvertisement parentPeerGroupAdvertisement,
                           Hashtable userPasswdHashtable) {
        
        PeerGroupAdvertisement satellaGroupAdv=null;
        PeerGroupID satellaPeerGroupId;

        // As mentionned, Peer Group Advertisement is build from scratch
        try {
              satellaGroupAdv= (PeerGroupAdvertisement) 
                                AdvertisementFactory.newAdvertisement(
                                PeerGroupAdvertisement.getAdvertisementType());
        }
        catch (Exception e){
              System.err.println("Disaster: Could not construct Satella Peer Group");
              System.exit(1);
        }
        
        // Set PeerGroupId
        satellaPeerGroupId = new net.jxta.impl.id.UUID.PeerGroupID (new UUID( 0x4d6172676572696eL, 
                                             0x204272756e6f2030L));
        satellaGroupAdv.setPeerGroupID (satellaPeerGroupId);

        // Starting to define the Peer Group Advertisement field:
        // Set Pid XXX group adv and  peer adv are seperate documents
        //satellaGroupAdv.setPeerID (IDFactory.newPeerID(satellaPeerGroupId));
        
        
        // Set the Name of the Peer Group
        satellaGroupAdv.setName ("Satella");
          
        // Set the Keywords associated with the Peer Group
        satellaGroupAdv.setDescription ("Satella Landsat TM Remote Sensing File Sharing P2P Peer to Peer");
          
        // Set EndPoints.
        satellaGroupAdv.setEndpointAdvertisements(
                     parentPeerGroupAdvertisement.getEndpointAdvertisements());
          
        // Set this peer to be a RendezVous for the Satella Group
        // XXX  this has to be set in the rendedezvous service
	satellaGroupAdv.setIsRendezvous(true);

        // Set GroupApplication
        ServiceAdvertisement  appAdv;
        appAdv = (ServiceAdvertisement) AdvertisementFactory.newAdvertisement(
                                ServiceAdvertisement.getAdvertisementType());

        appAdv.setName("Satella");
        appAdv.setVersion("JXTA1.0");
        appAdv.setParams(new Vector());
        appAdv.setUri("http://www.jaxta.org/download/jxta.jar");
        appAdv.setProvider("some guy");
        appAdv.setSecurity("TBD");
        appAdv.setCode(getClass().getName());
        satellaGroupAdv.setApp(appAdv);

        // SetGroupImplementation
        ServiceAdvertisement  giAdv;
        giAdv = (ServiceAdvertisement) AdvertisementFactory.newAdvertisement(
                                ServiceAdvertisement.getAdvertisementType());

        giAdv.setName("Group");
        giAdv.setVersion("JXTA1.0");
        giAdv.setParams(new Vector());
        giAdv.setUri("http://www.jaxta.org/download/jxta.jar");
        giAdv.setProvider("some guy");
        giAdv.setSecurity("TBD");
        giAdv.setCode(getClass().getName());
        satellaGroupAdv.setApp(giAdv);

        // Set Services. 
        // Important: Satella Group does not inheritate the Membership services 
        // from the Parentgroup (NetPeerGroup) because The Satella group should
        // Enforce some membership authentication.
        //
        // So the following is done:
        // Keep in mind that now we are working on a subset of the
        // Peer Group advertisement that is the Peer Group Service 
        // Advertisement. The Peer Group Service Advertisement is nested within 
        // the Peer Group Advertisement.
        // Each of the Membership services are copied from the parent Peer 
        // Group into Satella Peer Group SERVICE advertisement
        // The membership service is then created from scratch and added to the 
        // Satella Peer Group SERVICE advertisement.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -