FileDocCategorySizeDatePackage
HelloWorld.javaAPI DocExample3681Thu Jan 03 20:44:02 GMT 2002None

HelloWorld

public class HelloWorld extends Object

(Omit source code)

Fields Summary
static net.jxta.peergroup.PeerGroup
group
net.jxta.discovery.DiscoveryService
disco
net.jxta.resolver.ResolverService
resolv
net.jxta.pipe.PipeService
pipe
net.jxta.membership.MembershipService
member
net.jxta.protocol.PeerGroupAdvertisement
pgadv
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)


         
        HelloWorld myapp = new HelloWorld();
        myapp.startJxta();
        System.exit(0);
    
private voidstartJxta()


        try {
            // create and start the default jxta NetPeerGroup
            group = PeerGroupFactory.newNetPeerGroup();
        } catch (PeerGroupException e) {
            // could not instantiate the group; print the stack and exit
            System.out.println("Fatal error : creating the net PeerGroup");
            System.exit(1);
        }

        System.out.println("Started Hello World");

        // get the PeerGroup Advertisement                 
        pgadv = group.getPeerGroupAdvertisement();
        
        try {
            // Print out the PeerGroup Advertisement Document
            // To do so, we must convert it to a text document with
            // whatever MIME type we want. First, we'll print it as
            // a plain text document.
            StructuredTextDocument doc = (StructuredTextDocument)
                       pgadv.getDocument(new MimeMediaType("text/plain"));
            
            // Now that we have a plain text document
            // we can print the document via the StructuredTextDocument
            // senddtoWriter method
            StringWriter out = new StringWriter();
            doc.sendToWriter(out);
            System.out.println(out.toString());
            out.close();

            // For comparison, now we'll do the same thing but print it
            // out as an XML document.
            StructuredTextDocument adoc = (StructuredTextDocument)
                      pgadv.getDocument(new MimeMediaType("text/xml"));
            StringWriter aout = new StringWriter();
            adoc.sendToWriter(aout);
            System.out.println(aout.toString());
            aout.close();        
            
            // Now we'll access the PeerGroup service
            // and get various information from it
            PeerGroupID pgid = group.getPeerGroupID();
            System.out.println ("pgid= " + pgid);
            
            PeerID pid = group.getPeerID();
            System.out.println("pid= " + pid);
            
            String name = group.getPeerName();
            System.out.println("peer name=" + name);

            // Get the core services. We don't use the core services
            // in this example, but this is how you retrieve them if
            // you need them.
            disco = group.getDiscoveryService();
            pipe = group.getPipeService();
            member = group.getMembershipService();
            resolv = group.getResolverService();
            
            System.out.println("All done");

        } catch (Exception ex) {
             ex.printStackTrace();
        }