Re: Peer-Discovery in own Group
Yun Ding <[email protected]>
| Newsgroups | gmane.comp.java.jxta.user |
|---|---|
| Message-ID | <[email protected]> |
Hi Mohamed,
thank you for your suggestion. Now I can improve my code :-).
Thank you!
Yun
> I also suggest you use the rendezvous event notification callbacks and
> wait rather than sleep, as it provides for a cleaner application
> interaction. Here's what I mean ;
>
> private String rendezvousLock = "Rendezvous Lock";
>
> ..
> ..
>
> rendezvous.addListener(this);
>
> if ( !rendezvous.isRendezVous() &&
> !rendezvous.isConnectedToRendezVous()) {
> System.out.println("Waiting for Rendezvous Connection");
> try {
> synchronized(rendezvousLock) {
> rendezvousLock.wait(autoRendezvousTimeout);
> }
> } catch (InterruptedException e) {
> }
> }
> ....
> ....
>
> public void rendezvousEvent(RendezvousEvent event) {
> if (event.getType() == event.RDVCONNECT ||
> event.getType() == event.RDVRECONNECT) {
> synchronized(rendezvousLock) {
> rendezvousLock.notify();
> }
> }
> }
>
>
>
> Yun Ding wrote:
>
>> Hi,
>>
>>> thank you very much for that explanation. Now I tried this:
>>>
>>> dhtPeerGoup.getRendezVousService().setAutoStart(true);
>>> rdv = dhtPeerGoup.getRendezVousService();
>>>
>>> while (!rdv.isConnectedToRendezVous()) {
>>> try {
>>> Thread.sleep(2000);
>>> } catch (InterruptedException e1) {
>>> }
>>>
>>> But I never get out of the loop. When there is just one instance of
>>> my Application. So there ist just one member in this group - me. So
>>> I should become rendezvous-peer of this group, don't I?
>>>
>>>
>> yes, you are right. Your peer will become the rendezvous peer, and
>> it is not
>> connected to itself (sounds strange). You should use the following
>> code.
>> Your peer will get out of the loop, since it itself becomes a
>> rendezvous peer.
>>
>> while (( ! rdv.isConnectedToRendezVous () ) &&
>> ( ! rdv.isRendezVous () ) ) {
>> try {
>> Thread.sleep ( 2000 );
>> }
>> catch ( Exception e ) {}
>> }
>>
>> Best wishes,
>>
>> Yun
>>
>>
>
>
--
Dr. Yun Ding
European Media Laboratory GmbH
Schloss-Wolfsbrunnenweg 33
D-69118 Heidelberg
Tel.: (+49) 6221 533 240
Fax.: (+49) 6221 533 298