RE: IDFactory.newPeerGroupID Exception
Eugenio Flores <[email protected]> Fri, 17 Feb 2006 18:14:07 -0600 (CST)
| Newsgroups | gmane.comp.java.jxta.user |
|---|---|
| Message-ID | <[email protected]> |
Paul:
After quite a bit of time searching to find a solution to my problem, finally I found it.
The problem is that publishing the group advertisement in local cache is not enough in order to instantiate that group, it is also required, at least, is my conclusion, to publish the ModuleImplAdvertisement used when the group is created.
I saw an example I found in the book Mastering JXTA (example 3 chapter 12, page 187). When I tried to run it, it didnÂt work, It threw the same exception that I saw in my program. After checking out the advertisement file located in the jxta-NetGroup folder (advertisements.tbl) I realized that the group advertisement was in there, but the ModuleImplAdvertisement was not. So I published locally that advertisement:
myGroupImpl = netPeerGroup.getAllPurposePeerGroupImplAdvertisement();
myDiscoveryService.publish(myGroupImpl);
Afterward the group instantiation worked.
The example code that I'm talking about is available at http://www.wiley.com//legacy/compbooks/gradecki/jxta/, I'm also attaching it as text file with the lines I added.
I hope this could be helpful to new users like me.
Greetings
Eugenio Flores Centeno
"Poole, Paul P1" <[email protected]> escribió:
Eugenio,
The 2 code attachments didn't make it to me (they are being stripped off somewhere en route). However, the advertisement made it and I reviewed it. If the advertisement "socket.adv" is the advertisement you are trying to instantiate, then that is your problem. That advertisement is a PipeAdvertisement, and you need a PeerGroupAdvertisement when creating a group. Also, you should define a propagate pipe in your PipeAdvertisement for use with a peer group, otherwise you will only have one-to-one communication with your peers.
I think that the maillist on jxta.org does not store attachments, but allows them to go through to subscribers. I think they are likely being stripped off by the mail servers here at Lochkeed (security/virus precautions). You can try renaming the extension to adv (since the advertisement made it through) and sending them again. You might just send them directly to me instead of the entire newsgroup.
HTH,
Paul
---------------------------------
From: Eugenio Flores [mailto:[email protected]]
Sent: Thursday, February 16, 2006 7:05 PM
To: [email protected]
Subject: RE: [JXTA user] IDFactory.newPeerGroupID Exception
Paul, here I'm attching both codes and a socket advertisement that I intend to use.
Thanks.
"Poole, Paul P1" <[email protected]> escribió:
Eugenio,
I am sorry... I am out of ideas with what I have to work with. I think I would need to see both apps and run them to see exactly what is going on.
If you can get both apps posted in a way that I can get them, I would be happy to look at them.
-Paul
---------------------------------
From: Eugenio Flores [mailto:[email protected]]
Sent: Thursday, February 16, 2006 4:14 PM
To: [email protected]
Subject: RE: [JXTA user] IDFactory.newPeerGroupID Exception
Are you making sure that the PeerGroupAdvertisement is not null before calling netPeerGroup.newGroup(advPG)?
I'm completely suere that advPG is not null because I debug my application with Eclipse and I see the value of the advPG variable (I see the xml).
Are you obtaining the DiscoveryService from netPeerGroup?
Yes. Like this:
private transient PeerGroup netPeerGroup = null;
private DiscoveryService discovery;
try {
netPeerGroup = PeerGroupFactory.newNetPeerGroup();
}
catch(PeerGroupException e){
// could not instantiate the group, print the stack and exit
System.out.println("fatal error : group creation failure");
e.printStackTrace();
System.exit(1);
}
discovery = netPeerGroup.getDiscoveryService();
Are you getting more than one result back from getLocalAdvertisements()?
No, becuase I' running just one group in the subnet. I just get the PGAdvertisement that I'm looking for.
Make sure the group you are trying to instantiate is the one you want.
I'm completely sure.
Thanks again.
"Poole, Paul P1" <[email protected]>! escribió:
It would seem that your attachment was stripped...
I don't really see any errors in your code...
Some thoughts...
Are you making sure that the PeerGroupAdvertisement is not null before calling netPeerGroup.newGroup(advPG)?
Are you obtaining the DiscoveryService from netPeerGroup?
Are you getting more than one result back from getLocalAdvertisements()? You might want to filter you! r results for the specific group you are looking for. Make sure the group you are trying to instantiate is the one you want.
-Paul
---------------------------------
From: Eugenio Flores [mailto:[email protected]]
Sent: Thursday, February 16, 2006 3:35 PM
To: [email protected]
Subject: RE: [JXTA user] IDFactory.newPeerGroupID Exception
Pool, I'm very thankful for your help.
I understood what you and Cedric said about publishing the ! group before using the newGroup(PeerGroupID gid) method, that's why ! a look for the peer group advertisement, but the search is a remote one, not a local one, because the first application is running in a diferent computer than the second one (in my tests I use one computer but different folders for each application).
I use this line to look up for groups advertisements:
discovery.getRemoteAdvertisements( null,discovery.GROUP,null,null,5);
And it is inside a while loop that ends until a group advertisement is localted in local cache. The function that searchs for groups advertisement is as follow:
PeerGroupAdvertisement advPG = null; //this a global variable
private int groupsInLoca! lCache() {
System.out.println("--- local cache (Peer Groups)&n! bsp; ---");
int c! ounter = 0;
try {
Enumeration en = discovery.getLocalAdvertisements(discovery.GROUP, null, null);
if (en != null) {
while (en.hasMoreElements()) {
counter = counter + 1;
advPG = (PeerGroupAdvertisement) en.nextElement();
System.out.println( advPG.getName() + ", group ID = " + advPG.getID() + " module ID " + advPG.getModuleSpecID());
}
}
} catch (Exception e) {}
System.out.println("--- end local cache ---");
return counter;
}
And the while loop is this:
int respuesta;
while (this.groupsInLocalCache() < 1){
respuesta = discovery.getRemoteAdvertisements( null,discovery.GROUP,null,null,5);
System.out.println("Respuesta = " + respuesta);
}
The global variable advPG contains the PGAdvertisement that is found locally and I use it to instatiate the group like this:
private PeerGroup pg = null;
pg = netPeerGroup.newGroup(advPG);
The last line is the one where I get the exception I was telling you about.
I'm also attaching the second application code. The one that I'm explaining here.
Thanks again.
"Poole, Paul P1" <[email protected]>! ; escribió:
Eugenio,
In my post, I stated that you need to make sure your PeerGroupAdvertisement has been published before you can use the newGroup(PeerGroupID gid) method. This is the same thing (I believe that Cedric said as well). If you are using the DiscoveryService to retrieve published advertisements, you can safely use the newGroup(PeerGroupID) method OR the newGroup(Advertisement) method. Either one should work.&! nbsp; However, if you are using a well-known ID or a file to retr! ieve the ID and creating the group with that, then you must create an advertisement (using a ModuleImplAdvertisement) and publish it before you can use the newGroup(PeerGroupID) method.
"What I did in the second application is to find the group advertisement, once it finds it I use the function newGroup(Advertisement pgAdv) but it does not work because I get an exception telling me that I need the ModuleImplAdvertisment, and it is what jxta documentation says. But I don't know how to obtain the MIA."
This doesn't make sense to me. I don't know why you would receive this message. I use the DiscoveryService to retrieve an enumeration of loc! al advertisements and use that advertisement (only PeerGroupAdvertisements of course) to create the group without any problem. The only thing that comes to mind... what PeerGroup are you using to instantiate the new PeerGroup? Use the same PeerGroup to instantiate the new one that you used in the search.
If this doesn't help, please post all applicable code such as the s! earch code and the group creation. Perhaps if I see it, I can make better sense of your problem.
!
Good luck,
Paul
---------------------------------
From: Eugenio Flores [mailto:[email protected]]
Sent: Thursday, February 16, 200! 6 1:50 PM
To: [email protected]
Subject: RE: [JXTA user] IDFactory.newPeerGroupID Exception
Hello, I've trying all your suggestion but I think I don't understand the group creation logic.
I have two applications, the first one creates the group the first time it runs, thus creates a groups once. The other application that will be running in other computer is the o! ne that wants to join the group. I'm using the join function that comes in the guide, this function receives a group object as p! arameter (
private void joinGroup(PeerGroup grp)).
That is why I want to instantiate in the second application the group created in the first one.
What I did in the second application is to find the group advertisement, once it finds it I use the function newGroup(Advertisement pgAdv) but it does not work because I get an exception telling me that I need the ModuleImplAdvertisment, and it is what jxta documentation says. But I don't know how to obtain the MIA.
Cedric said this:
Create PGAdvertisement (and save PGID for later)
publish locally
next session
recreatePGID
omit PGAdvertisement creation
create PG from PGID (using locally available PGAdvertisement)
With the group search I find the group advertisement, instead of creating a PGAdvertisement because as I said, I want to instantiate the group created in the first application. And Poole suggested to use another newGroup funct! ion! ! instead of newGroup(PeerGroupID gid) that is why I'm using newGroup(Advertisement pgAdv)
So, any suggestion? Am I over the correct track?
Thanks a lot.
"Poole, Paul P1" <[email protected]> escribió: Cedric,
With the other 2 newGroup() methods, you don't actually have to publish the PeerGroupAdvertisement first. In fact, much to my chagrin, those two methods publish an advertisement by default and use a default expiration and lifetime (see my thread with the subject "Advertisements"). I do not believe that newGroup(PeerGroupID) publishes the advertisement for you, thus it needs to be published. However, I don't know if it needs to be published first (before calling newGroup()) or if you can publish it afterwards.
I think that the information in my last email was correct and may address a future problem. I rescinded it only because I realized afterwards that it didn't address the question asked.
Disclaimer: Since I am not a jxta "expert" it is certainly poss! ible that this information is wrong. However, i believe it to be true.
Paul
---------------------------------
From: Cedric Hyppolite [mailto:[email protected]]
Sent: Monday, February 13, 2006 1:28 PM
To: [email protected]
Cc: Cedric Hyppolite
Subject: Re: [JXTA user] IDFactory.newPeerGroupID Exception
Actually I think that the peer group advertisement must be published before the newGroup method is called.
A bit more like:
!
Create PGAdvertisement (and save PGID for later)
publish locally
next session
recreatePGID
omit PGAdvertisement creation
create PG from PGID (using locally available PGAdvertisement)
Please tell me if I understood incorrectly.
Cedric
Le 13 févr. 06 à 19:22, Poole, Paul P1 a écrit :
According to the javadoc, this method (newGroup(PeerGroupID gid) should be used when a group has already been published and discovered. The fact that the group isn't published could be what is causing your problem. I looked at the implementation for this method and unlike the other two newGroup() methods, this one does NOT publish your PeerGroupAdvertisement.
I would recommend you use one of the other two newGroup() methods to instantiate your PeerGroup.
Alternatively, you can try keeping the code you have, but publishing your PeerGroupAdvertisement before joining the group.
pg = netPeerGroup.newGroup(PID);
<insert publish call here>
this.joinGroup(pg);
This might work as well... not sure.
HTH
Paul
---------------------------------
From: Eugenio Flores [mailto:[email protected]]
Sent: Monday, February ! 13, 2006 12:58 PM
To: [email protected]
Subject: [JXTA user] IDFactory.newPeerGroupID Exception
Hello, I'm trying to instantiate a group based in its ID.
To do ! ! this, I create a group in an a! plication and print its ID, then, in another application, where I want to instantiate the group that I created, I do the following:
private PeerGroupID PID = null;
private PeerGroup pg = null;
netPeerGroup = PeerGroupFactory.newNetPeerGroup();
PID = IDFactory.newPeerGroupID("urn:jxta:uuid-95BDAD67763B4951B9D2DDD00441FCF002");
pg = netPeerGroup.newGroup(PID);
this.joinGroup(pg);
But the newPeerID(PeerGroupID groupID)!
Creates a new PeerID instance.
throws this execption:
failed : java.util.NoSuchElementException: key 'urn:jxta:uuid-95BDAD67763B4951B9D2DDD00441FCF002' not registered.
Where do I have to registir the ID in order to use this function, or does any one know! a better way to do this?
---------------------------------
Do You Yahoo!? La mejor conexión a Internet y 2GB extra a tu correo por $100 al mes. http://net.yahoo.com.mx
---------------------------------
Do You Yahoo!? La mejor conexión a Internet y 2GB extra a tu correo por $100 al mes. http://net.yahoo.com.mx
---------------------------------
Do You Yahoo!? La mejor conexión a Internet y 2GB extra a tu correo por $100 al mes. http://net.yahoo.com.mx
---------------------------------
Do You Yahoo!? La mejor conexión a Internet y 2GB extra a tu correo por $100 al mes. http://net.yahoo.com.mx
---------------------------------
Do You Yahoo!? La mejor conexión a Internet y 2GB extra a tu correo por $100 al mes. http://net.yahoo.com.mx
---------------------------------
Do You Yahoo!? La mejor conexión a Internet y 2GB extra a tu correo por $100 al mes. http://net.yahoo.com.mx
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
creator.txt
(text/plain, 5.8 KB)
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.net.*;
import java.util.Enumeration;
import net.jxta.peergroup.*;
import net.jxta.exception.*;
import net.jxta.id.IDFactory;
import net.jxta.protocol.*;
import net.jxta.discovery.*;
import net.jxta.document.*;
import net.jxta.credential.*;
import net.jxta.membership.*;
public class creator extends JFrame {
private static PeerGroup netPeerGroup = null,
wileyHowGroup = null,
discoveredWileyHowGroup = null;
private static PeerGroupID wileyHowGroupID;
private DiscoveryService myDiscoveryService = null;
private JTextArea displayArea;
private final static MimeMediaType XMLMIMETYPE = new MimeMediaType("text/xml");
public static void main(String args[]) {
creator myapp = new creator();
myapp.addWindowListener (
new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
}
);
myapp.run();
}
public creator() {
super("Creator");
Container c = getContentPane();
displayArea = new JTextArea();
c.add (new JScrollPane(displayArea), BorderLayout.CENTER);
setSize(300,150);
show();
launchJXTA();
getServices();
wileyHowGroupID = createPeerGroupID("jxta:uuid-DCEF4386EAED4908BE25CE5019EA02");
wileyHowGroup = createPeerGroup(wileyHowGroupID, "wileyHowGroup", "Experimentation Group");
joinGroup(wileyHowGroup);
//findAdvertisement("Name", "wileyHowGroup");
}
public void run() {
}
private void launchJXTA() {
displayArea.append("Launching Peer into JXTA Network...\n");
try {
netPeerGroup = PeerGroupFactory.newNetPeerGroup();
} catch (PeerGroupException e) {
System.out.println("Unable to create PeerGroup - Failure");
e.printStackTrace();
System.exit(1);
}
}
private void getServices() {
displayArea.append("Obtaining Discovery Service....\n");
myDiscoveryService = netPeerGroup.getDiscoveryService();
}
PeerGroupID createPeerGroupID(String myStringID) {
PeerGroupID tempPeerGroupID = null;
try {
tempPeerGroupID = (PeerGroupID) IDFactory.fromURL(new URL("urn", "", myStringID));
} catch (Exception e) {
e.printStackTrace();
System.exit(-1);
}
displayArea.append("Valid PeerGroupID has been created from StringID\n");
return tempPeerGroupID;
}
//---------------------------------Create Group-----------------------------------------------
PeerGroup createPeerGroup(PeerGroupID myPeerGroupID, String myPeerGroupName, String myPeerGroupDescription) {
PeerGroupAdvertisement wileyHowGroupAdvertisement;
PeerGroup tempPeerGroup = null;
ModuleImplAdvertisement myGroupImpl = null;
try {
myGroupImpl = netPeerGroup.getAllPurposePeerGroupImplAdvertisement();
myDiscoveryService.publish(myGroupImpl);
StructuredTextDocument doc = (StructuredTextDocument)myGroupImpl.getDocument(XMLMIMETYPE );
doc.sendToStream(System.out);
System.out.println("------------------------------------------------------------------------------------------------");
} catch (Exception e) {
e.printStackTrace();
System.exit(-1);
}
wileyHowGroupAdvertisement = (PeerGroupAdvertisement) AdvertisementFactory.newAdvertisement(PeerGroupAdvertisement.getAdvertisementType());
wileyHowGroupAdvertisement.setPeerGroupID(myPeerGroupID);
wileyHowGroupAdvertisement.setModuleSpecID(myGroupImpl.getModuleSpecID());
wileyHowGroupAdvertisement.setName(myPeerGroupName);
wileyHowGroupAdvertisement.setDescription(myPeerGroupDescription);
StructuredTextDocument doc1 = (StructuredTextDocument)wileyHowGroupAdvertisement.getDocument(XMLMIMETYPE );
try{
doc1.sendToStream(System.out);
}
catch(Exception e){
e.printStackTrace();
}
displayArea.append("New Peer Group Advertisement has been created\n");
try {
//myDiscoveryService.publish(wileyHowGroupAdvertisement, myDiscoveryService.GROUP, PeerGroup.DEFAULT_LIFETIME, PeerGroup.DEFAULT_EXPIRATION);
myDiscoveryService.publish(wileyHowGroupAdvertisement);
//myDiscoveryService.remotePublish(wileyHowGroupAdvertisement, myDiscoveryService.GROUP, PeerGroup.DEFAULT_EXPIRATION);
//myDiscoveryService.remotePublish(wileyHowGroupAdvertisement);
} catch (Exception e) {
e.printStackTrace();
System.exit(-1);
}
displayArea.append("New Peer Group Advertisement has been published\n");
try {
tempPeerGroup = netPeerGroup.newGroup(wileyHowGroupAdvertisement);
} catch (Exception e) {
e.printStackTrace();
System.exit(-1);
}
displayArea.append("New Peer Group has been created\n");
return tempPeerGroup;
}
void joinGroup(PeerGroup myLocalGroup) {
StructuredDocument myCredentials = null;
try {
AuthenticationCredential myAuthenticationCredential = new AuthenticationCredential(myLocalGroup, null, myCredentials);
MembershipService myMembershipService = myLocalGroup.getMembershipService();
net.jxta.membership.Authenticator myAuthenticator = myMembershipService.apply(myAuthenticationCredential);
if (!myAuthenticator.isReadyForJoin()) {
displayArea.append("Authenticator is not complete\n");
return;
}
myMembershipService.join(myAuthenticator);
displayArea.append("Group has been joined\n");
} catch (Exception e) {
displayArea.append("Authentication failed - group not joined\n");
e.printStackTrace();
System.exit(-1);
}
}
}