Key Benefits of Discovery

Before we leave the topic of discovery, let’s see how our example fits with two key benefits of JXTA’s model of service and advertisement discovery.

Performance Improves as the System Ages

The ability to improve performance as the system ages is a fundamental feature of a JXTA network. As a peer discovers new resources, it becomes more capable and efficient. This helps the peer, of course, but it benefits other peers on the network as well.

The first time a peer attempts to discover another peer, it will take some time. The second time it will take less time, because the peer has cached the discoveries it has previously made. That helps the peer.

Remember, though, that advertisements get cached on all intermediary peers that they pass through. Therefore, advertisements in a JXTA network tend to move towards the end user’s peer; a peer does not always have to go back to a central location or to the publisher of the advertisement to obtain an advertisement. So the first HungryPeer to run on a local network may take some time to discover the RestoNet peergroup, particularly if the only RestoPeer on the network was just started many network hops away. The second HungryPeer will find the RestoNet more quickly: it has to find only the first HungryPeer or the RestoPeer, one of which is bound to be closer than the other. As the peergroup becomes more popular, the probability that a nearby peer has already discovered the peergroup increases, making the discovery process faster for new peers.

The JXTA network also provides a new kind of fault-tolerant environment that allows information to be replicated as it is used. An advertisement may be cached locally, it may be known by a nearby peer or by a rendezvous peer, or a remote peer may have it. There is no unique path to obtain an advertisement. As advertisements are propagated and cached within the network, JXTA adapts to retrieve the advertisement from the most efficient location. In many cases, this location is the closest to the peer.

As a final example, consider what happens when you stop the RestoPeer and restart the HungryPeer. You get the same output we’re used to seeing:

Attempting to discover the RestoNet Peergroup
Found the RestoNet PeerGroup Advertisement
The HungryPeer joined the restoNet PeerGroup

The HungryPeer finds the RestoNet advertisement in its cache and joins the RestoNet peergroup. JXTA removed the need for a centralized infrastructure to support the RestoNet peergroup. Any peer (RestoPeer or HungryPeer) that previously joined the RestoNet group has enough information to join the group again. In our case, we just have a hungry peer in the peergroup and no food to feed him! This is okay: when a RestoPeer joins the peergroup, it may try to look for our hungry peer.

Reliability from an Unreliable and Unpredictable Network

Programming in a P2P network such as JXTA is a little more involved than in a traditional, reliable network with a higher guarantee of predictability. However, by assuming unreliability in a network from the beginning, JXTA allows us to build more reliable applications in the long run. Many traditional network programming models provide the illusion of reliability by trying to mask network errors. In many situations, this leads to unpredictable and intractable behaviors when an application is deployed in a real-world network. The programming model of JXTA, while giving the appearance of more complexity, may lead to more robust and predictable network applications.

This is a fundamental programming shift that JXTA introduces. We strongly believe that the JXTA programming model will lead to more robust distributed applications by forcing applications to leverage all of their surrounding environments and dynamically bind themselves to interchangeable network resources. Network failures are treated not as special cases, but as normal operations. Network resources should be interchangeable, and peer location should be irrelevant.

Consider the scenario of a man driving at night, searching for a restaurant. The man may decide to search until his stomach tells him, “Enough is enough. Give me some food!” So instead of continuing to search for a restaurant, the man may stop at a grocery store he is just passing by, even though a restaurant on the next block happens to be open. If the man had continued driving one more block, he would have discovered the restaurant.

This is exactly what happens in real life. Different resources are available, new resources may be just around the corner or just about to open, and we make decisions based on our knowledge available at the time.

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.