Integration with Other Network Services

As we said at the start of this chapter, JXTA does not require that network services use pipes or other JXTA facilities in order to be invoked; you can create network services that advertise themselves to JXTA peergroups but are invoked via another technique. We’ll conclude this chapter with a brief discussion of how this can be accomplished.

We’ll center our discussion around an RMI-based network service. The specific details in our discussion will apply to RMI-based services only, but the general technique will be applicable to other types of network services.

The general technique is this: the service must publish a standard module service advertisement within a JXTA peergroup. The service advertisement must contain information so that JXTA peers can contact it; this information is stored in the param tag of the service advertisement. JXTA peers that discover the advertisement extract the special information from the param tag and contact the service using that information.

RMI clients contact RMI servers via a specialized class known as a stub. An RMI service that wants to advertise itself in a JXTA peergroup must encode its stub into the service advertisement. Here’s how a service can achieve this:

import java.rmi.*; import java.rmi.server.*; import java.io.*; import net.jxta.peergroup.PeerGroup; import net.jxta.peergroup.PeerGroupFactory; import net.jxta.exception.PeerGroupException; import net.jxta.document.Advertisement; import ...

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.