The Artima Developer Community
Sponsored Link

Jini Forum
Need help writting a new Jini attribute! Please!!!

6 replies on 1 page. Most recent reply: Jan 28, 2004 4:36 AM by Dan Creswell

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 6 replies on 1 page
Erika Ruiz

Posts: 4
Nickname: erika
Registered: Dec, 2003

Need help writting a new Jini attribute! Please!!! Posted: Dec 3, 2003 6:10 PM
Reply to this message Reply
Advertisement
Hello! I want to write a new Jini attribute, I have followed all the instructions in the Core Jini book, I have compiled the code from the book , I even have a Bean for my new attribute, but when I want my client to search based on this new attribute, it doesn't work!!! I would really appreciate if someone would help me. My attribute is called Photo, and it is supposed to give the client information about an image:

Photo(String city, String format, String color, String size, String dimensions)

The service browser that comes with Jini shows my new attribute, but it does now show it's parameters (they appear all "null") it just shows the standard ones like "Name" and "Location". It looks like this on the attribute window of the Jini browser:

Name [net.jini.lookup.entry.Name(name=Photo archive of mexican colonial cities)]
Photo [Photo(city=null,format=null,color=null,size=null,dimensions=null)]
Comment [net.jini.lookup.entry.Comment(comment=Gif/jpeg images of Mexico City and Guanajuato)]
Location [net.jini.lookup.entry.Location(floor=2,room=20,building=Public Library, Mexico D.F.)]

Does anybody know why this is happening? And why my client doesn't do the searching based on the attribute?

I have this on the client code:

public void discovered(DiscoveryEvent evt) {

ServiceRegistrar[] registrars = evt.getRegistrars();
Class [] classes = new Class[] {Images.class};

Entry[] attr = new Entry[1];
attr[0] = new Photo("Mexico DF", "jpeg", "color", "11886 bytes", "180 x 200 pixels");


ServiceTemplate template = new ServiceTemplate(null, classes, attr);

for (int n = 0; n < registrars.length; n++) {
System.out.println("\nService Found...");
ServiceRegistrar registrar = registrars[n];
ServiceMatches matches;
try {
matches = registrar.lookup(template, 10);
} catch(java.rmi.RemoteException e) {
e.printStackTrace();
continue;
}
for (int m = 0; m < matches.items.length; m++)

...

The service code looks like this:

public void discovered(DiscoveryEvent evt) {

ServiceRegistrar[] registrars = evt.getRegistrars();

Location ltn = new Location("2", "20", "Public Library, Mexico D.F.");
Comment comment = new Comment("Gif/jpeg images of Mexico City and Guanajuato");
Name name = new Name("Photo archive of mexican colonial cities");

Photo photo1 = new Photo("Mexico DF", "jpeg", "color", "11886 bytes", "180 x 200 pixeles");
Photo photo2 = new Photo("Mexico DF", "jpeg", "color", "12717 bytes", "180 x 203 pixeles");
Photo photo3 = new Photo("Mexico DF", "jpeg", "color", "14518 bytes", "444 x 292 pixeles");
Photo photo4 = new Photo("Mexico DF", "jpeg", "color", "37993 bytes", "480 x 360 pixeles");
Photo photo5 = new Photo("Mexico DF", "jpeg", "color", "19013 bytes", "267 x 400 pixeles");

Entry[] entries = new Entry[] {name, photo1, photo2, photo3, photo4, photo5, comment, ltn};


for (int n = 0; n < registrars.length; n++) {
ServiceRegistrar registrar = registrars[n];

ServiceItem item = new ServiceItem(serviceID,
new ImageUrl2(),
entries);
ServiceRegistration reg = null;
try {
reg = registrar.register(item, Lease.FOREVER);
} catch(java.rmi.RemoteException e) {
System.err.println("Registry exception: " + e.toString());
continue;

}


...

Is it possible to have multiple attributes of the same type? I would like the browser to show the five images above.

I really need help!!! :(

Thank you very much !!!!

Erika :)


Dan Creswell

Posts: 49
Nickname: dancres
Registered: Apr, 2003

Re: Need help writting a new Jini attribute! Please!!! Posted: Jan 15, 2004 7:40 AM
Reply to this message Reply
Can you post the code for Photo itself?

Are the attributes public or private?

They should be public - if they're not, they won't be serialized and transferred. To be a valid field in the Entry implementation, the attribute field must be public.

Erika Ruiz

Posts: 4
Nickname: erika
Registered: Dec, 2003

Re: Need help writting a new Jini attribute! Please!!! Posted: Jan 25, 2004 9:41 AM
Reply to this message Reply
> Can you post the code for Photo itself?
>
> Are the attributes public or private?
>
> They should be public - if they're not, they won't be
> serialized and transferred. To be a valid field in the
> Entry implementation, the attribute field must be public.

Hello Dan, thank you very much for your reply, I had already started to give up on the problem, I hadn't logged in for a while. Here is the code for Photo, all the attributes are public:

import net.jini.entry.AbstractEntry;

public class Photo extends AbstractEntry {

public String city;
public String format;
public String color;
public String size;
public String dimensions;

public Photo() {
city = new String();
format = new String();
color = new String();
size = new String();
dimensions = new String();

}

public Photo(String city, String format, String color, String size, String dimensions) {
city = new String();
format = new String();
color = new String();
size = new String();
dimensions = new String();
}

}


Thank you very much Dan :)

Greetings,
Erika.

Steven E. Newton

Posts: 137
Nickname: cm
Registered: Apr, 2003

Re: Need help writting a new Jini attribute! Please!!! Posted: Jan 25, 2004 1:18 PM
Reply to this message Reply
Well I don't know much about Jini, but I do know Java, and it looks to me like this in the constructor code is wrong:

    public Photo(String city, String format, String color,
                 String size, String dimensions) {
 	city = new String();
 	format = new String();
 	color = new String();
 	size = new String();
 	dimensions = new String();
    }

I think what it should do is set the instance variables to the values passed in, not to new String(). Unless Jini is supposed to be doing something tricky with the values and the public instance variables after the constructor is called, then I would expected them all to be the null String, as returned by your test.

Erika Ruiz

Posts: 4
Nickname: erika
Registered: Dec, 2003

Re: Need help writting a new Jini attribute! Please!!! Posted: Jan 25, 2004 3:34 PM
Reply to this message Reply
> Well I don't know much about Jini, but I do know Java, and
> it looks to me like this in the constructor code is
> wrong:
>
>
> public Photo(String city, String format, String
> ring color,
>                  String size, String dimensions) {
>  	city = new String();
>  	format = new String();
>  	color = new String();
>  	size = new String();
>  	dimensions = new String();
>     }
> 

> I think what it should do is set the instance variables to
> the values passed in, not to new String(). Unless Jini is
> supposed to be doing something tricky with the values and
> the public instance variables after the constructor is
> called, then I would expected them all to be the null
> String, as returned by your test.

Hello Steve, thank you very much for your reply, I was wondering how the constructor would actually look like, 'cause I've been trying to fix it but it's still working the same.

My best regards,
Erika.

Erika Ruiz

Posts: 4
Nickname: erika
Registered: Dec, 2003

Re: Need help writting a new Jini attribute! Please!!! Posted: Jan 25, 2004 3:37 PM
Reply to this message Reply
Hello Steve, thank you very much for your reply, I was wondering how the constructor would actually look like, 'cause I've been trying to fix it but it's still working the same.

My best regards,
Erika.

Dan Creswell

Posts: 49
Nickname: dancres
Registered: Apr, 2003

Re: Need help writting a new Jini attribute! Please!!! Posted: Jan 28, 2004 4:36 AM
Reply to this message Reply
Okay, well the constructor is certainly not right but that doesn't explain why the ServiceBrowser shows nulls for each field. Even with the faulty constructor we should be seeing empty strings not nulls, I think.

As a test, rather than extend AbstractEntry, implement net.jini.core.entry.Entry and add a toString method like:

<pre>
public String toString() {
return city + format + color + size + dimensions;
}

And let's see what you get in the browser then.....

Flat View: This topic has 6 replies on 1 page
Topic: jini help Previous Topic   Next Topic Topic: Clustered JavaSpaces

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use