O'Reilly logo

JXTA in a Nutshell by Li Gong, Bernard Traversat, Scott Oaks

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

A Peer Service Example

Let’s use our RestoNet example to illustrate how the RestoPeer can publish itself as a service and how the HungryPeer can discover and use that service.

The RestoPeer as a Peer Service

First, we’ll modify the RestoPeer class to publish a service advertisement rather than a pipe advertisement. To do so, we’ll use the createRestoPeerService( ) method of the RestoPeer class:

// This routine creates a module specification advertisement to be
// associated with a RestoPeer
private void createRestoPeerService(  ) {
    try {
        // First, create the module class advertisement associated with the
        // service. The module class advertisement advertises the existence
        // of the service. To access the service, a peer will have to
        // discover the associated module specification advertisement.
        ModuleClassAdvertisement mcadv = (ModuleClassAdvertisement)
                              AdvertisementFactory.newAdvertisement(
                              ModuleClassAdvertisement.getAdvertisementType(  ));

                          mcadv.setName("JXTAMOD:RestoNet:Service:" + brand);
                          mcadv.setDescription("RestoPeer service");

                          ModuleClassID mcID = IDFactory.newModuleClassID(  ); mcadv.setModuleClassID(mcID); // Publish the module class advertisement in my local cache and to // peergroup disco.publish(mcadv, DiscoveryService.ADV); disco.remotePublish(mcadv, DiscoveryService.ADV); // Create the module specification advertisement associated // with the service. The module specification advertisement will // contain all the information necessary for a client to contact the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required