Re: Using lookupService()

"Mike [bondolo] Duigou" <[email protected]> Tue, 19 Dec 2006 10:22:53 -0800
Newsgroups gmane.comp.java.jxta.user
Organization Project JXTA, http://www.jxta.org
Message-ID <[email protected]>
Daniel Evers wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Hello!
> 
> I'm trying to find a service that I advertised on another peer, using
> PeerGroup.lookupService(). Since that doesn't work, I have some questions:

PeerGroup.lookupService() is designed to return a reference to a local 
instance of a running service. It's not capable of finding service 
instances running on other peers.

There is no built-in API for finding service instances running on other 
peers. Commonly a pipe is used for service instance location. All 
instances of the service will listen on a well-known pipe and peers can 
locate instances by opening an output pipe and sending a contact 
request. One or more instances of the service should respond to the 
client and the client will then establish a connection to one of the 
instances.

> 1. I like to publish the advertisements inside a new group. All examples
> I found (mostly in the book by Brendon J. Wilson) use the net peer
> group's discovery service to publish the advertisements, not the group
> they create. Shouldn't they/I use newgroup.getDiscoveryService()?

Depends on what the advertisements are for. If you are adding your 
service to the peer group implementation then you need to publish the 
service module implementation, peer group module implementation 
advertisement (and the class and spec advs) into the peer group in which 
you will be instantiating your peer group.

Publishing of other resource advertisement into the parent peergroup 
(and/or net peer group) should only be used for locating the application 
peer groups and in some specialized cases for locating services. (The 
Rendezvous service does this).

> 2. I can't find the service implementation. I create the class adv, spec
> adv and impl adv for the service and according to the examples I've
> seen, only the class and spec advs are published. The implementation adv
> is added to the group's parameters (using StdPeerGroupParamAdv etc.).
> Since I cannot find this advertisement, shouldn't it be published along
> with the others?

If you are publishing the impl advertisements into your peer group then 
peers which want to instantiate your peer group can't access them. It's 
a chicken and egg problem. They need the advertisement to instantiate 
the peergroup but can't get it because the peergroup is not instantiated.


> 3. Something strange: I have 2 example services doing nothing, just
> printing log statements on startApp(), init() and so on. I create and
> treat both the same, but one service is always started (without using
> it), i.e. I get log messages from init() and startApp(), but the other
> one isn't. When are init() and startApp() called?

I'm not sure I follow. Are these two services part of the same peer 
group? Or the same service running on two different peers? You should 
also make sure you are running with Log4J INFO level in order to better 
see what's happing

> 4. [Maybe related to 3.] Do I have to call newgroup.startApp() after
> creating a new group to start the services? And must/should I join this
> group, or am I joining it automatically?

Yes, your application needs to call newgroup.startApp(). What do you 
mean by "join" in this case. Do you mean MembershipService.join() or 
something else?

> Sorry to bother with so many questions, but I'm "punishing" google for
> quite a while now and can't find answers. Also most examples use JXTA
> 2.0 or 2.1, and it seems there were changes since then.

No worries. :-)

Mike