Any peer can create a peergroup. The shell creates a peergroup with these commands:
JXTA>mygroupadv = mkadv -g mygroup JXTA>mkpgrp -d mygroupadv
The first of these commands creates an advertisement (
mygroupadv) of a new group with a symbolic name of
mygroup (advertisements are discussed in more detail later in this chapter). The
mkpgrp command actually creates the group.
When you create a group in this manner, information about the group is broadcast to other peers using a discovery protocol that we discuss in the next section. In general, a peer can find a peergroup in two ways:
1. When a new group is created, an announcement of that group is broadcast, and peers who are listening will discover the new group.
2. A peer can initiate discovery to find groups. In the shell, this is accomplished with the
groups -r command:
JXTA>groups -r group discovery message sent
You can see which groups the shell knows about by using the
JXTA>groups group0: mygroup group1: anothergroup
In this last example, we know about
mygroup because that's the group that we created; we know about
anothergroup because another peer on the network created that group and we discovered it. Note that the NetPeerGroup does not show up in this list, even though it is also a peergroup.
Each peergroup is uniquely identified by a unique peergroup ID. The peergroup ID is guaranteed to be unique within the entire JXTA network.
Once a peer has discovered or created a group, it must join the group. This entails sending an application (with any necessary credentials) to the group and awaiting a response. The membership service of the group will vote on the new application and send back either an acceptance or a rejection.
A shell joins a particular group by using the
JXTA>join -d group0 Enter the identity you want to use when joining this peergroup (nobody) 1Identity: jra
After executing this command, the shell is a member of the group
mygroup. A quick note about syntax here:
group0 comes from the list of groups we obtained with the
groups command. You can use the symbolic group name (e.g.,
mygroup) to join a group only if that shell created the group. To join a group that the shell discovered (such as
anothergroup), however, you must use the
group# that the shell has assigned. Because the shell caches information about groups, it might have created the group, exited, and restarted. In that case, you must also use the
group# that the shell has assigned.
A peer can join multiple groups by executing another
join command; the
join command can also be used to determine which groups the peer has joined:
JXTA>join -d group1 Enter the identity you want to use when joining this peergroup (nobody) 1Identity: sdo JXTA> join Joined group : mygroup Joined group : anothergroup (current)
Commands that the shell executes will be associated with the current group (
anothergroup); the current group can be changed with the
n this command, you always use the symbolic group name rather than the
group# name. The current group is used to find any service that the shell needs; it is also the group printed by the
Membership in any group created by the shell is automatic, so these examples work well when dealing with groups created by two different shells. A shell might also discover a different group, however: one that has membership criteria and requires the shell to present some special credentials. Membership in such groups requires that you know how to fill out a credential request, which is group-specific; we'll look at how this works in Chapter 7.
Canceling Group Membership
A peer can cancel its membership in a group. The shell cancels its membership in a group with the
This command cancels membership in the current group. You cannot leave the NetPeerGroup.