FileDocCategorySizeDatePackage
RestoPeerService.javaAPI DocExample12907Sun Jan 06 12:29:50 GMT 2002None

RestoPeerService

public class RestoPeerService extends Object implements net.jxta.service.Service

Fields Summary
public static String
Module_Spec_ID
private String
brand
private String
specials
private net.jxta.peergroup.PeerGroup
restoNet
private net.jxta.pipe.PipeService
pipes
private net.jxta.protocol.ModuleImplAdvertisement
srvImpl
private net.jxta.protocol.PipeAdvertisement
myAdv
private net.jxta.pipe.InputPipe
pipeIn
private int
rtimeout
Constructors Summary
Methods Summary
private booleancreateRestoPipe()

        try {
            // Create my input pipe to listen for hungry peers
            // requests
            pipeIn = pipes.createInputPipe(myAdv);
        } catch (Exception e) {
            System.out.println(
                "Could not initialize the Restaurant pipe" + e.getMessage());
            return false;
        }
        return true;
    
private java.lang.StringfriesPrice(java.lang.String size)

        if (size.equals("small"))
              return "$1.50";
        if (size.equals("medium"))
              return "2.50";
        if (size.equals("large"))
              return "3.00";
        return "error";
    
public net.jxta.document.AdvertisementgetImplAdvertisement()

        return srvImpl;
    
public net.jxta.service.ServicegetInterface()

             // Resolver pipe timeout

    // Service objects are not manipulated directly to protect usage
    //of the service. A Service interface is returned to access the service
       
        return this;
    
public voidinit(net.jxta.peergroup.PeerGroup group, net.jxta.id.ID assignedID, net.jxta.document.Advertisement impl)

        // Save the RestoNet pointer, the pipe and the RestoPeer Service
        restoNet = group;
        srvImpl = (ModuleImplAdvertisement) impl;
        System.out.println("Initialization RestoPeer Special Service: " +
                           srvImpl.getModuleSpecID());

        // Extract the service pipe advertisement from the service
        // module impl Advertisement. The client MUST use the same pipe
        // advertisement to talk to the service. When the client
        // discovers the peergroup advertisement, it will extract the
        // pipe advertisement to create the connecting pipe by getting
        // the module impl advertisement associated with the RestoPeer
        // service.
        System.out.println("Extract the pipe advertisement from the Service");
        PipeAdvertisement pipeadv = null;

        try {
            // Extract the pipe adv from the Module impl param section
            myAdv = (PipeAdvertisement)
                AdvertisementFactory.newAdvertisement((TextElement)
                      srvImpl.getParam().getChildren().nextElement());
        } catch (Exception e) {
            System.out.println("failed to read/parse pipe advertisement");
            e.printStackTrace();
            System.exit(-1);
        }

        // Start the RestoPeer service loop thread to respond to Hungry peers
        // fries requests. Start a new thread for processing all the
        // requests
        HandleFriesRequest peerRequest = new HandleFriesRequest();
        peerRequest.start();
    
public intstartApp(java.lang.String[] args)

        // nothing to do here
        return 0;
    
public voidstopApp()