Skip to main content

Customs advertisement

8 replies [Last post]
leodali
Offline
Joined: 2006-08-11
Points: 0

Hi, i'm new using Jxta technology and actually i'm working on a project given by my university, where i have to create a Jxta service, implemented by a peer group, that provide some actions for peers. I found problems creating an advertisement personalized with some informations inside: is it possible to do this? Is available a class that permit this creation?
Thanks anyway for your help.

Leonardo

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
jlaffitte
Offline
Joined: 2006-08-09
Points: 0

Hi, i'm having a very weird error, at least for me:

Well, i'm developping a file sharing application with Jxta.
For every file found in the specified folder i make an advertisement which is published locally.
I'm using two peers for trying,the first that connects, is set as rendezvous:

...
for (int i = 0;i if (files[i].isFile()){
fileAdv= new FileAdv();
fileAdv.setFileName(files[i].getName());
fileAdv.setFileSize(getTamFic(pathCarpeta,files[i].getName()));
fileAdv.setPeerID(peerID);
fileAdv.setPeerName(grupoFs.getPeerName());
grupoFs.getDiscoveryService().publish(fileAdv, oneDay, oneDay);
}

}
...
where fileAdv is the advertisement class, where i specify the indexfields,and i register it
...
AdvertisementFactory.registerAdvertisementInstance(FileAdv .getAdvertisementType(),new FileAdv .Instantiator());
...
Thus, i publish locally every file i share.

When one peer search a file sends a discover request:

...
myQueryID = discoFile.getRemoteAdvertisements(null,DiscoveryService.ADV
,fileAdv.nameKey,nameFile,1,FileListener);
...

Then, my discovery event receive only the advertisement of the last file
published, althougth i have specified a correct attribute and value in
getRemoteAdvertisement.
It becomes very weird because it receives even 4 discoveries responses,
when i specified only 1:
discoFile.getRemoteAdvertisements(null,DiscoveryService.ADV
,fileAdv.nameKey,nameFile,1,FileListener);

Finally, and getting me completely lost the results don't change if i try to discover the advertisement as
myQueryID =
discoFichero.getRemoteAdvertisements(null,DiscoveryService.ADV,null,null,1
,oyenteFichero);

I don't know what's happening.If someone has any idea it would be great!
Thanks

Jose

Message was edited by: jlaffitte

jlaffitte
Offline
Joined: 2006-08-09
Points: 0

Well, Looking for a solution i've realised that my peer in unabled even to
discover locally his advertisements created(it discovers only the last adv
created):with the next code i create the advs for every file.

for (int i = 0;i if (files[i].isFile()){
advFile= (AdvFile)
AdvertisementFactory.newAdvertisement(AdvFile.getAdvertisementType());
advFile.setFileName(files[i].getName());

advFile.setTamañoFichero(getFileSize(pathCarpeta,ficheros[i].getName()));
advFile.setPeerID(peerID);
advFile.setPeerName(grupoFs.getPeerName());
ds.publish(advFile, oneDay, oneDay);
}

}
Enumeration enumer4 = ds.getLocalAdvertisements(ds.ADV,
AdvFile.FileNameKey, null);
while(enumer4.hasMoreElements()){
System.out.println("file:"+enumer4.nextElement());
}

It's very weird because the only element of the enumeration is that adv of the
last file!!!
I need help!!!!

Jose

jlaffitte
Offline
Joined: 2006-08-09
Points: 0

I fell into a stupid error: I set the Adv Id as the Peer Id.Thus i had only 1 advertisement, althoght i publish several!Finally, i changed in the FileAdv:

public ID getID() {
try {
return (CodatID) IDFactory.newCodatID(fsId,(new CheckSum().getCodeFromString(nameFile).getBytes()));
} catch(Exception e) {
return null;
}
}

and that runs correctly.

Thanks to all of you that gave me a hand!

tra
Offline
Joined: 2003-06-16
Points: 0

> Hi, i'm new using Jxta technology and actually i'm
> working on a project given by my university, where i
> have to create a Jxta service, implemented by a peer
> group, that provide some actions for peers. I found
> problems creating an advertisement personalized with
> some informations inside: is it possible to do this?
Yes, check the advertisement factory class to see
how to register a new advertisement type.

B.

> Is available a class that permit this creation?
> Thanks anyway for your help.
>
> Leonardo

leodali
Offline
Joined: 2006-08-11
Points: 0

ok tra, now i have created an instantiator for my advertisements...a customs advertisement, to be found, what does it need inside? because i'm trying to publish and discover it via the .remotePublish(......) and .getRemoteAdvertisement(......) methods, but i'm not able to find the adv in the Jxta network. Maybe i ignore some crucial informations about customs advertisement...what do you think about? Thanks.

tra
Offline
Joined: 2003-06-16
Points: 0

> ok tra, now i have created an instantiator for my
> advertisements...a customs advertisement, to be
> found, what does it need inside? because i'm trying
> to publish and discover it via the
> .remotePublish(......) and
> .getRemoteAdvertisement(......) methods, but i'm not
> able to find the adv in the Jxta network. Maybe i
> ignore some crucial informations about customs
> advertisement...what do you think about?

Did you define the indexable tags for your new
advertisement type. These are the tags you should
be using when discovering advertisements.

Hth,

B.

leodali
Offline
Joined: 2006-08-11
Points: 0

indexable tags? you mean the fields inside my adv i use to write down informations? i already defined them...i'm sure i'm forgetting something else, this is my first custom advertisement i'm trying to publish and it's quite simple to wrong. What do you think if i show you the code of my adv?
Thanks for your help.

Leonardo

tra
Offline
Joined: 2003-06-16
Points: 0

> indexable tags? you mean the fields inside my adv i
> use to write down informations? i already defined
> them...i'm sure i'm forgetting something else, this
> is my first custom advertisement i'm trying to
> publish and it's quite simple to wrong. What do you
> think if i show you the code of my adv?
> Thanks for your help.
Whne you define the new advertisement type, you also
define which of the tags will be indexed. You can
only discover advertisements by querying on the
indexed tags.

Hth,

B.

>
> Leonardo