Peergroup Services

All peergroup objects carry certain information: the name of the peergroup, its unique universal identifier (UUID), and so on. In addition, peergroups provide certain core JXTA services, as we mentioned in Chapter 2. In particular, peergroups can provide a discovery service that can be used to discover other JXTA peers and services, a pipe service that can be used to create input and output pipes, and a membership service that can be used to join the peergroup. All of this information can be retrieved from the peergroup object:

private void startJxta( ) { 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"); // 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. DiscoveryService disco = group.getDiscoveryService( ); PipeService pipe = group.getPipeService( ); MembershipService member = group.getMembershipService( ); ResolverService ...

Get JXTA in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.