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

📄 studentdemonull.java

📁 Java p2p程序设计2002年版
💻 JAVA
字号:
package com.sams.jxta.groups.student;

import net.jxta.discovery.DiscoveryEvent;
import net.jxta.discovery.DiscoveryListener;
import net.jxta.discovery.DiscoveryService;
import net.jxta.document.Advertisement;
import net.jxta.document.AdvertisementFactory;
import net.jxta.document.MimeMediaType;
import net.jxta.document.StructuredDocument;
import net.jxta.document.TextElement;
import net.jxta.exception.PeerGroupException;
import net.jxta.exception.ProtocolNotSupportedException;
import net.jxta.id.ID;
import net.jxta.id.IDFactory;
import net.jxta.impl.document.PlainTextDocument;
import net.jxta.impl.peergroup.StdPeerGroup;
import net.jxta.peergroup.PeerGroup;
import net.jxta.peergroup.PeerGroupFactory;
import net.jxta.platform.Module;
import net.jxta.platform.ModuleClassID;
import net.jxta.platform.ModuleSpecID;
import net.jxta.protocol.DiscoveryResponseMsg;
import net.jxta.protocol.ModuleImplAdvertisement;
import net.jxta.protocol.PeerGroupAdvertisement;
import net.jxta.protocol.PeerAdvertisement;
import net.jxta.impl.peergroup.Platform;
import net.jxta.impl.peergroup.GenericPeerGroup;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.util.Enumeration;
import java.net.*;
import java.io.IOException;
import com.sams.jxta.groups.*;

/**
 * This class demonstrates how to use the Group Manager.
 *
 */

public class StudentDemoNull implements Module{
    
    private static final org.apache.log4j.Category LOG = org.apache.log4j.Category.getInstance(StudentDemo.class.getName());
    
    protected static PeerGroup netPeerGroup = null;
    
    /*
     * The main method which serves as the entry point
     */
    
    public static void main(String args[]){
        
        StudentDemoNull sample = new StudentDemoNull();
        sample.runJXTA();
    }
    
    /*
     * This method starts the JXTA platform.
     *
     */
    
    private void runJXTA(){
        
        
        // Get an instance of the net peer group
        try {
            
            netPeerGroup = PeerGroupFactory.newNetPeerGroup();
        } catch (PeerGroupException peerGroupException) {
            //could not instanciate the group, print the stack and exit
            LOG.error("Group Creation Failure !",peerGroupException);
            System.exit(1);
        }
        // Create a module impl advertisement by using the factory.
        // Set the appropriate fields.
        ModuleClassID mID = IDFactory.newModuleClassID();
        ModuleSpecID moduleSpecID = PeerGroup.refMembershipSpecID;
        ModuleImplAdvertisement adv = (ModuleImplAdvertisement)
        AdvertisementFactory.newAdvertisement(ModuleImplAdvertisement.getAdvertisementType());
        adv.setModuleSpecID(moduleSpecID);
        adv.setCompat(StdPeerGroup.stdCompatStatement);
        adv.setCode("com.sams.jxta.groups.student.StudentDemoNull");
        adv.setUri("http://www.jxta.org/download/jxta.jar");
        // This module is loaded by the net peer group.
        try{
            netPeerGroup.loadModule(mID,adv);
        } catch (ProtocolNotSupportedException protocolException) {
            LOG.error("Could not load Module !",protocolException);
            System.exit(1);
        } catch (PeerGroupException peerGroupException) {
            LOG.error("Could not load Module !",peerGroupException);
            System.exit(1);
        }
    }
    
    /*
     * This method is called when the module is initialized.
     * This is when we use the Group Manager.
     */
    public void init(PeerGroup parentGroup,ID assignedID,Advertisement implAdv)
    throws PeerGroupException{
        
        GroupManager manager = new GroupManager(netPeerGroup, parentGroup);
        // This is to create a new University Admissions group
        // to deal with the admissions of a particular university
        PeerGroup p =manager.addGroup("StudentGroup",
        "net.jxta.impl.membership.NullMembershipService",
        "To test the Null Membership Service",null,false);
        try{
            
            manager.joinGroup(p,null,"NullAuthentication");
            
        } catch(GroupManagerAuthenticationException authenticationException) {
            
            LOG.debug("Exception :Expected behavior. University has no admissions for this dpt");
            LOG.debug("Message is : "+authenticationException.getMessage());
            
        } catch(ProtocolNotSupportedException protocolException) {
            
            LOG.error("Error in join !",protocolException);
        }
    }
    
    
    /*
     * Methods to be implemented by virtue of being a module.
     * Not used in this example
     */
    public int startApp(String[] args){return 0;}
    public void stopApp(){};
    
}

⌨️ 快捷键说明

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