Skip to main content

Group creation and rendesvous

2 replies [Last post]
rille
Offline
Joined: 2004-11-14
Points: 0

Hi, I'm trying to create a basic service but I'm having issues when it comes to grouping it into a group.

I'm aiming for the following tree:

<br />
NetPeerGroup<br />
|<br />
|-MyServices<br />
    |-subgroup-service1<br />
    |-subgroup-service2<br />
    ...<br />
    |-subgroup-serviceN<br />

Group creation seems to go well and I can find it in netPeerGroup using discovery service.

The details
-------------------------------------------------------------
This is how I init jxta (edited)

<br />
public void startNet() {     //startJxta</p>
<p>        PeerGroupAdvertisement adv = null;</p>
<p>        try {<br />
            netPeerGroup = PeerGroupFactory.newNetPeerGroup();<br />
            //waitOnRendevou();<br />
            System.out.println("JXTA started");<br />
            disco = netPeerGroup.getDiscoveryService();</p>
<p>            adv = defaultGroupExist("BombermanNet");</p>
<p>            // Se om vi kan hitta gruppen sedan tidigare<br />
            if (adv != null) {<br />
                netBomberManGroup = netPeerGroup.newGroup(adv);<br />
            } else {<br />
                netBomberManGroup = createBomberGroup();<br />
            }</p>
<p>            joinGroup(netBomberManGroup);</p>
<p>            disco = netBomberManGroup.getDiscoveryService();</p>
<p>            gameNetPipeAdvertisementFinder = new GamePipeAdvertisementFinder(netBomberManGroup);<br />
            gameNetPipeAdvertisementFinder.start();</p>
<p>            incoming.addEvent(new NetEvent(CONNECTED_TO_NET, null));</p>
<p>        } catch (PeerGroupException e) {<br />
            LOG.error("Error: Peer group exception, couldn't join new net peer group");<br />
        }<br />
    }<br />

netBomberManGroup is my main group.
Making a small multiplayer game with JXTA.

Using this code:
(pretty much the same as the examples)
Generating a new ID with hashing so I always get the same groupID.

<br />
private PeerGroup createBomberGroup() {<br />
        PeerGroupAdvertisement adv      = null;<br />
        PeerGroup pg                    = null;<br />
        ModuleImplAdvertisement implAdv = null;</p>
<p>        try {<br />
            // create a new all purpose peergroup.<br />
            implAdv = netPeerGroup.getAllPurposePeerGroupImplAdvertisement();</p>
<p>            pg = netPeerGroup.newGroup(newIDFactory.createPeerGroupID(netPeerGroup.getPeerGroupID(),<br />
                                       "BomberManNet", "BomberMan"),<br />
                                       implAdv,<br />
                                       "BombermanNet",<br />
                                       "Game Group");</p>
<p>            adv = pg.getPeerGroupAdvertisement();<br />
            // don't know about this but I leave if off<br />
            // pg.getRendezVousService().setAutoStart(true);<br />
            netPeerGroup.init(pg, pg.getPeerGroupID(), implAdv);</p>
<p>        } catch (Exception e) {<br />
            LOG.error("Error: Peer group creation failed");<br />
        }</p>
<p>        try {<br />
            disco.remotePublish(adv);<br />
            disco.publish(adv);<br />
        } catch (Exception e) {<br />
            LOG.error("Error: Publishing group advertisement");<br />
        }</p>
<p>        return pg;<br />
    }<br />

And then I join the peergroup:

<br />
private void joinGroup(PeerGroup grp) {<br />
        StructuredDocument creds = null;</p>
<p>        try {<br />
            // Generate the credentials for the Peer Group<br />
            AuthenticationCredential authCred = new AuthenticationCredential(grp, null, creds);</p>
<p>            // Get the MembershipService from the peer group<br />
            MembershipService membership = grp.getMembershipService();</p>
<p>            // Get the Authenticator from the Authentication creds<br />
            Authenticator auth = membership.apply(authCred);</p>
<p>            // Check if everything is okay to join the group<br />
            if (auth.isReadyForJoin()) {<br />
                membership.join(auth);</p>
<p>            } else<br />
                LOG.error("Failure: unable to join group");<br />
        } catch (Exception e) {<br />
            LOG.error("Failure in authentication.");<br />
            e.printStackTrace();<br />
        }<br />
    }<br />

Now I got the PeerGroups:
netPeerGroup (the default one)
myServicePeerGroup (my new group)

I got a thread that looks for advertises: (looks like this)
AdvertisementFinder(PeerGroup peerGroup)

It works with the netPeerGroup but not with my own group that I just created.

I have this piece of test code for checking i I get any contact at all and it works for the default netPeerGroup (of ourse) but not for my group. So I need to get rendevous somehow.

<br />
private void waitOnRendevous() {<br />
        while (!rvs.isConnectedToRendezVous() || rvs.isRendezVous()) {<br />
            try {<br />
                Thread.sleep(200);<br />
            } catch (InterruptedException ex) {}<br />
        }<br />
    }<br />

I have tried to get the RendesVousService from the group and set it to:
peerGroup.getRendezVousService().setAutoStart(true, t)
and I have tested peerGroup.getRendezVousService().startRendezVous()

But I still don't get any rendesvous for the current app connected or for other instances (new peers) that tries to discover new services.

-------------------------------------------------------------

I obviously need to get my group manager to work unless I want to put everything in the default netPeerGroup.
Could someone give me a hand/suggestion on what I'm doing wrong?

like,
Do I need to implement the rendevous by myself?
Are there any obvious errors in my group creation/join code etc.

Message was edited by: rille

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
turbogeek
Offline
Joined: 2003-06-10
Points: 0

I am not sure if you have an error. Try setting the LOG to warn and see if there is anything from creating the group.

Autostart should work and because you are even able to call it means that you have partially gotten the RDV code for your sub group.

Check your code against the wiki and see if there is something different

http://wiki.java.net/bin/view/Jxta/CreatingASubPeerGroup

rille
Offline
Joined: 2004-11-14
Points: 0

Thanks for the suggestion. ;)

I'm gonna try using the LightWeightPeerGroup and implement something like the SimpleRdvPeerGroup. Though I don't really see why that should be needed. :/

I found the Wiki some time ago and I find it to be more rewarding than those small examples.