ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.


AddThis Social Bookmark Button

Getting Started with JXTA, Part 1
Pages: 1, 2

JXTA Peers

We'll start our examination of JXTA's key concepts with the notion of a peer. As defined in the JXTA specification, a peer is a device that implements one or more JXTA protocols. The key idea is that something implements the protocols. Don't get too hung up on the notion of a device--a device is not necessarily a machine. A single machine can host multiple JXTA programs, each of which is really a peer. The program is really a virtual device.

Of course, peers normally communicate with each other over a network, so a JXTA community typically has many different machines within it. However, some of these machines could be running multiple JXTA peers. A single JXTA peer could be a distributed application running across multiple machines. And if you're following the example in this chapter at home on your own single computer, you'll end up running many peers on your local system.

To start our first peer, we'll execute the JXTA Shell. On Microsoft Windows systems, you can do this by selecting Programs -> Jxta -> JXTA Shell from the start menu. On other platforms, you can do this by executing these commands:

piccolo% cd /files/JXTA_Demo/Shell
piccolo% sh shell.sh

When you first start the shell, you'll see the window displayed in Figure 2-1. This allows you to configure the shell for the network on which it will run. We explain the configurator in detail later in this chapter. For now, we'll just step through the two required elements that you must configure.[1]

Figure 2-1

The JXTA configurator tool

First, fill in the peer name with a string of your choice (we chose "Test Shell 1") and press the OK button. On the next screen, fill in the username you'd like to use and a password for that username. In Figure 2-2, we've specified myusername and entered a password.

Figure 2-2

Entering a username into the configurator

The next window that comes up is the JXTA Shell itself. This is the first JXTA peer that we've created. The shell is interactive; its command prompt is JXTA>, and it accepts more than 40 commands. For now, we'll just look at the commands that illustrate the basic JXTA concepts.

One of these commands is the peers command; it displays a list of all the peers that the shell knows about. If you execute that command now, you'll see the following:

peer0: name = Test Shell 1
peer1: name = JXTA.ORG 237
peer2: name = JXTA.ORG 235

More information can be printed this way:

JXTA>peers -l
peer0: ID = uuid-
59616261646162614A78746159325933A69CA85997D6433D82BDA4A4D0953AC603 name 
= Test Shell 1 addr = tcp://
peer1: ID = uuid-59616261646162614A787461593259336ACC981CFAF047CFA name = 
JXTA.ORG 237 addr = tcp://
peer2: ID = uuid-59616261646162614A7874FAEDBB84753E1E16503C14495AE name = 
JXTA.ORG 235 addr = tcp://

All peers have names (in the case of our peer, "Test Shell 1"). In addition, peers carry other important pieces of information: the peergroup to which they belong (which we'll explain later in this chapter), a unique peer ID, and information about what network addresses can be used to contact the peer. You can see this information in the shell with the whoami command:

<Peer>Test Shell 1</Peer>

The peer ID is unique across all JXTA peers. The transport addresses contain the information about how the peer may be contacted.

You can discover a peer explicitly using its peer ID like this:

JXTA> peers -p jxta://59616261646162614A78746150325033D13E08EF

This technique is easier to imagine programatically, where you wouldn't have to type in the entire string. You can, for example, save a peer ID and use it in later sessions as the default peer to provide a service (assuming that the program can handle the fact that the default peer may no longer be available); in fact, peer IDs are often saved by the JXTA platform itself when it performs caching.

Peers keep configuration information within their current directory. If you want to start a second instance of the shell on the same machine, you cannot do so from the same directory. Instead, you must follow the instructions on advanced configuration that we give later in this chapter.

In the next installment, learn about peergroups.

1. This default configuration assumes that your computer is directly connected to the Internet. If you are not connected to the Internet directly or connect to the Internet through a proxy, then you must take additional steps as outlined in the detailed section on the configurator tool later in this chapter.

Scott Oaks is a Java Technologist at Sun Microsystems, where he has worked since 1987. While at Sun, he has specialized in many disparate technologies, from the SunOS kernel to network programming and RPCs.

Bernard Traversat is a well-known developer in the Java Community and an active member of the Project JXTA. Bernard is the Engineering Manager for the JXTA CORE.

Li Gong is a well-known developer in the Java Community and an active member of the Project JXTA. Li is the JXTA Engineering Director for the JXTA CORE.

Return to ONJava.com.