Skip to main content

Different way create group

3 replies [Last post]
Joined: 2008-01-08

Hi, I need your opinion about this.
I have read jxta programmers guide for create group , and here is the piace of code

// create and publish a new peer group
private void createGroup() {
PeerGroupAdvertisement adv;
System.out.println("Creating a new group advertisement");
try {
// create a new all purpose peergroup.
ModuleImplAdvertisement implAdv =
PeerGroup pg = myGroup.newGroup(null, // Assign new group ID
implAdv, // The implem. adv
"PubTest",// The name
"testing group adv"); // descr.
// print the name of the group and the peer group ID
adv = pg.getPeerGroupAdvertisement();
PeerGroupID GID = adv.getPeerGroupID();
System.out.println(" Group = " +adv.getName() +
"\n Group ID = " + GID.toString());
} catch (Exception eee) {
System.out.println("Group creation failed with " +
try {
// publish this advertisement
//(send out to other peers and rendezvous peer)
System.out.println("Group published successfully.");
} catch (Exception e) {
System.out.println("Error publishing group advertisement");

Beside that, i have download the example from petrovic blog and found he create group similiarly but not same. because he use modulespecID, and define himself the groupID,specID. like this :

private void createPeerGroup() throws Exception, PeerGroupException {

// The new-application subgroup parameters.
String name = "My App Group";
String desc = "My App Group Description";
String gid = "urn:jxta:uuid-79B6A084D3264DF8B641867D926C48D902";
String specID = "urn:jxta:uuid-309B33F10EDF48738183E3777A7C3DE9C5BFE5794E974DD99AC7D409F5686F3306";

StringBuilder sb = new StringBuilder("=Creating group: ");
sb.append(name).append(", ");
sb.append(desc).append(", ");
sb.append(gid).append(", ");

ModuleImplAdvertisement implAdv = netPeerGroup.getAllPurposePeerGroupImplAdvertisement();
ModuleSpecID modSpecID = (ModuleSpecID )IDFactory.fromURI(new URI(specID));

// Publish the Peer Group implementation advertisement.
discovery.remotePublish(null, implAdv);

// Create the new group using the group ID, advertisement, name, and description
PeerGroupID groupID = (PeerGroupID )IDFactory.fromURI(new URI(gid));
PeerGroup newGroup = netPeerGroup.newGroup(groupID,implAdv,name,desc);

// Start the rendezvous for our applcation subgroup.
apppgRendezvous = newGroup.getRendezVousService();

// Publish the group remotely. newGroup() handles the local publishing.
PeerGroupAdvertisement groupAdv = newGroup.getPeerGroupAdvertisement();
discovery.remotePublish(null, groupAdv);

My Question are :

1. What is the best from both of them?
2. Why he use modulespecID and define itself not using generated by JXTA??
3. The last , in petrovic code he publish the peer group implementation advertisement after that he also create the group from it using newGroup() and retrieve the GroupADV from that group and publish it. Could someone explain to me what is the difference between both of them?? Why he do not just publish the GroupADV only??


Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2007-01-31


1) I think the best way to create a new group is to retrieve the net peer group when calling NetworkManager.startNetwork(...). Then call one of the new group method from this object.

2) No idea, I don't see the purpose of doing that when there is an easier way...

3) I don't think it is really useful, unless petrovic also has implemented minimal peers in his network and that these minimal peers need to find a location where they can 'load' the code for the default implementation of JXTA in Java.

Hope this helps,


Joined: 2008-05-17

I hava a question:
In Lan,A NetPeerGroup create lots of custom peergroups ,but when I use the NetPeerGroup's DiscoveryService to find all of custom peergroups.I find only NetPeerGroup .Why?

Joined: 2007-01-31

It could be because the advertisement corresponding to these peer groups have not been published remotely and locally.