September 2002
Intermediate to advanced
416 pages
14h 46m
English
That completes our look at
the RestoPeer implementation; we now have a service that can discover
(and create, if necessary) the RestoNet peergroup. Now
we’ll turn our attention to the
HungryPeer class.
The HungryPeer class represents an individual that
is looking to eat at a restaurant. The implementation in this chapter
illustrates how a peer can search for and join a peergroup: the
HungryPeer class discovers and joins the RestoNet
peergroup created by the previous RestoPeer class:
import java.io.*; import java.util.Enumeration; import java.util.Vector; import net.jxta.peergroup.PeerGroup; import net.jxta.peergroup.PeerGroupFactory; import net.jxta.exception.PeerGroupException; import net.jxta.document.Advertisement; import net.jxta.discovery.DiscoveryService; import net.jxta.pipe.PipeService; import net.jxta.protocol.PeerGroupAdvertisement; // HungryPeer tries to find a restaurant to get a good meal. It finds all // RestoPeers in the RestoNet peergroup and (in later examples) requests // bids from them. public class HungryPeer { private PeerGroup netpg = null; // NetPeerGroup private PeerGroup restoNet = null; // Resto peergroup private int timeout = 3000; // Time-out; can be adjusted // Services within the RestoNet peergroup private DiscoveryService disco; // Discovery service private PipeService pipes; // Pipe service // Vector of discovered RestoPeers private Vector restaurantAdvs = new Vector( ); public static void main(String args[]) { ...Read now
Unlock full access