Skip to main content

create a new group, new service and use lookupService(..)

5 replies [Last post]
johndickerson
Offline
Joined: 2006-01-20

Has anyone created some code where lookupService(classID) works with a new service in a new peer group ?

I always get ServiceNotFoundException.

The way I am trying to create a service for a new group is by following Brendon Wilson's electronic book,
chapter 10, Peer Group and Service.

My code looks like ( Note code has been skipped out to make it more readable ):

ModuleSpecID moduleSpecID
= moduleImplAdvertisementFromNetPeerGroup.getModuleSpecID();

ModuleImplAdvertisement moduleImplAdvertisement
= ( ModuleImplAdvertisement)
AdvertisementFactory.newAdvertisement(

ModuleImplAdvertisement.getAdvertisementType() );

moduleImplAdvertisement.setModuleSpecID( moduleSpecID );

moduleImplAdvertisement.setCode(
"com.jes.common.p2p.jxta.protocol.service.MyService" );

moduleImplAdvertisement.setCompat(
moduleImplAdvertisementFromNetPeerGroup.getCompat() );

moduleImplAdvertisement.setDescription(
moduleImplAdvertisementDescription );

moduleImplAdvertisement.setProvider(
moduleImplAdvertisemenProvider );

StdPeerGroupParamAdv stdPeerGroupParamAdv
= new StdPeerGroupParamAdv(
moduleImplAdvertisementOfNetPeerGroup.getParam() );

Hashtable servicesHashtable =
stdPeerGroupParamAdv.getServices();

servicesHashtable.put(
moduleClassAdvertisement.getModuleClassID(),
moduleImplAdvertisement );

stdPeerGroupParamAdv.setServices( servicesHashtable );

MimeMediaType mimeMediaType
= new MimeMediaType( "text", "xml" );

StructuredDocument structuredDocument
= ( StructuredDocument)
stdPeerGroupParamAdv.getDocument(
mimeMediaType );

moduleImplAdvertisementOfNetPeerGroup.setParam(
structuredDocument );

PeerGroup peerGroup
= netPeerGroup.newGroup(
peerGroupID,
moduleImplAdvertisementOfNetPeerGroup,
peerGroupName, peerGroupDescription );

// Later on in the code I try and look up the service
// using the same ID I used when I put the moduleImplAdvertisement
// in the servicesHashtable above
ID id = moduleClassAdvertisement.getModuleClassID();

MyService myService
= ( MyService )peerGroup.lookupService( id );

Problem
========

In the code above I put the service in the hashtable as follows:

servicesHashtable.put(
moduleClassAdvertisement.getModuleClassID(),
moduleImplAdvertisement );

but when I try and use the same ID for the lookup I get ServiceNotFoundException.

Does anyone know whether I am doing it in the right way ?

Bernard had a similar problem:

http://www.jxta.org/servlets/ReadMsg?listName=dev&msgNo=11028

Does anyone have any ideas?

My problem with JXTA is that the JXTA books published are several years old.
I am unsure whether my problem is because the code base does not work or because
the particular code in question is not used or tested anymore or the examples are out of date,
or I am plain stupid - very frustrating because JXTA has loads of potential if only I can master the basics.

I think we need more time stamped JXTA examples out there, for else the less able
of us will give up when the brick walls we come up against seem too hard to overcome.

Thanks

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
mehrgan
Offline
Joined: 2008-09-16

hi friend,
I have your problem because I read that online book and I want to create new service like you,
If you know how can create a new service and access to it with lookupService method or any way please help me,
thank u.

karn18
Offline
Joined: 2006-05-05

Hi friend,
I still have a problem like johndickerson.
Could anyone explain me how to solve this problem clearly?

adamman71
Offline
Joined: 2007-01-31

Hi,

An complete example is available at www.practicaljxta.com (see Joe the astrologer and Jill the customer).

Cheers,

J.

golubovic
Offline
Joined: 2006-05-08

hi john,
it took me some time to figure out what is the problem, but if you take a look in GenericPeerGroup source, you will notice following line of code:

if( (null != implAdv.getCode()) && (null != implAdv.getUri()) )

hence, you have to set the uri value in the module implementation advertisement.
hope it helps ...
ag

ae6rt
Offline
Joined: 2005-10-25

You might have a look at

http://www.petrovic.org/blog/?p=7

which does this sort of thing.

Mark