Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > rmiregistry woes

Reply
Thread Tools

rmiregistry woes

 
 
jonck
Guest
Posts: n/a
 
      01-21-2005
Hi all,
I was fiddling around with RMI, got it working, and then all of a
sudden things stopped working. My main class is as follows (it's an
example from a book):

import java.io.Serializable;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;

public class RatingServer extends UnicastRemoteObject implements
RatingServerInterface, Serializable {
public RatingServer() throws RemoteException {
super();
System.out.println("Entering 0-argument constructor");
}

public int serverRating(MovieInterface m) throws RemoteException {
System.out.println("RatingServer asked for a rating");
int s = m.getScript();
int a = m.getActing();
int d = m.getDirection();
return 3 * Math.max(Math.max(s, a), d);
}

public static void main(String args[]) {
try {
Naming.rebind("//localhost/ratingService", new
RatingServer());
System.out.println("Rating server connected to server");
} catch (RemoteException e) {
System.out.println("Ratingserver exception: " + e);
} catch (MalformedURLException e) {
System.out.println("Ratingserver exception: " + e);
}
}
}

I tried reverting back to the state where things still worked (returned
to the exact code as it is mentioned in my book, this code worked
earlier on), but now all of a sudden whenever I tried running my class,
I got the following exception:

Ratingserver exception: java.rmi.ServerException: RemoteException
occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments;
nested exception is:
java.lang.ClassNotFoundException: RatingServer_Stub

Now I know that this would indicate that RatingServer_Stub cannot be
found, but it's on my classpath (same directory! And this exact setup
worked a few minutes back.

What I think caused all my problems was that during a certain launch,
the 0-argument constructor kept getting called, over and over again. In
fact, it did not stop untill I rebooted my computer. After the reboot
things stopped working.

So my guess is that somehow rmiregistry got screwed up. Could someone
tell me how I could go about re-installing it? I'm on OS X 10.3.7.
Thanks very much for any help, Jonck

 
Reply With Quote
 
 
 
 
Esmond Pitt
Guest
Posts: n/a
 
      01-21-2005
jonck wrote:

> Ratingserver exception: java.rmi.ServerException: RemoteException
> occurred in server thread; nested exception is:
> java.rmi.UnmarshalException: error unmarshalling arguments;
> nested exception is:
> java.lang.ClassNotFoundException: RatingServer_Stub
>
> Now I know that this would indicate that RatingServer_Stub cannot be
> found, but it's on my classpath (same directory! And this exact setup
> worked a few minutes back.


It's on *your* classpath but it's not on your *registry*'s classpath.
The error is coming from the registry during Naming.rebind(). You must
have restarted the registry under different conditions. Nothing wrong
with your code.

 
Reply With Quote
 
 
 
 
jonck
Guest
Posts: n/a
 
      01-21-2005
You are correct, thank you! Wish all problems were solved so simply, I
navigated to the directory where the code is located and started
rmiregistry, and voila, after running my class it works again
Thanks again, Jonck

 
Reply With Quote
 
jonck
Guest
Posts: n/a
 
      01-21-2005
Perhaps you know the answer to this one as well? If I were to change
the above posted class into this:

public class RatingServer extends UnicastRemoteObject implements
RatingServerInterface, Serializable {
private Object test;

public RatingServer(Object test) throws RemoteException,
MalformedURLException {

Naming.rebind("//localhost/ratingService", new RatingServer());
System.out.println("Rating server connected to server");

setTest(test);
}

public RatingServer() throws RemoteException {
super();
}

public int serverRating(MovieInterface m) throws RemoteException {
System.out.println("RatingServer asked for a rating");
System.out.println(getTest());
int s = m.getScript();
int a = m.getActing();
int d = m.getDirection();
return 3 * Math.max(Math.max(s, a), d);
}

public static void main(String args[]) {
try {
RatingServer ratingServer = new RatingServer(new Object());
} catch (RemoteException e) {
System.out.println("Ratingserver exception: " + e);
} catch (MalformedURLException e) {
System.out.println("Ratingserver exception: " + e);
}
}

public Object getTest() {
return test;
}

public void setTest(Object test) {
this.test = test;
}
}

(so added a 1-argument constructor, which I call in the main method,
and added a field Object test and its getter and setter)

If I now call the serverRating method over RMI the line
"System.out.println(getTest());" produces "null", while obviously test
is not null. I've noticed that it is possible to call primitives like
int or boolean, but any call to a field that extends Object returns
null.

Is this a bug or is this supposed to happen?

Any tips on how to bypass this, I'd like to be able to access
non-primitive fields in the remotely called method.
Thanks very much, Jonck

 
Reply With Quote
 
Esmond Pitt
Guest
Posts: n/a
 
      01-22-2005
Anything passed or returned by a Remote method needs to be either Remote
or Serializable, and ditto anything reachable via non-transient attributes.

new Object() is neither.

 
Reply With Quote
 
jonck
Guest
Posts: n/a
 
      01-22-2005
I figured that Serializable had something to do with it, so I created
another object that was serializable and tried it, same outcome, the
returned value was null. After that I also implemented the Remote
interface, same thing, returned value was null.

So I'm at a loss here. It doesn't really matter, cause I've solved what
I wanted to do with a simple socket connection, but I'm interested in
how I would get this to work nonetheless.
Thanks for any feedback, Jonck

 
Reply With Quote
 
Esmond Pitt
Guest
Posts: n/a
 
      01-24-2005

My guess is that you are *binding* null, there is really no other way
you can get a null from Registry.lookup.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help! with RMIRegistry David Kensche Java 0 03-11-2005 10:20 AM
Monitoring the rmiregistry silarri Java 3 01-04-2005 12:51 PM
RMI without the rmiregistry JP Martin Java 1 10-06-2004 07:33 AM
Running Rmiregistry as service, problem on logofff. Arun Goel Java 0 11-12-2003 06:41 PM
RMI with rmiregistry on remote host Rob Dempster Java 1 10-08-2003 04:18 PM



Advertisments