rmiregistry woes

Discussion in 'Java' started by jonck, Jan 21, 2005.

  1. jonck

    jonck Guest

    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
    jonck, Jan 21, 2005
    #1
    1. Advertising

  2. jonck

    Esmond Pitt Guest

    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.
    Esmond Pitt, Jan 21, 2005
    #2
    1. Advertising

  3. jonck

    jonck Guest

    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
    jonck, Jan 21, 2005
    #3
  4. jonck

    jonck Guest

    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
    jonck, Jan 21, 2005
    #4
  5. jonck

    Esmond Pitt Guest

    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.
    Esmond Pitt, Jan 22, 2005
    #5
  6. jonck

    jonck Guest

    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
    jonck, Jan 22, 2005
    #6
  7. jonck

    Esmond Pitt Guest

    My guess is that you are *binding* null, there is really no other way
    you can get a null from Registry.lookup.
    Esmond Pitt, Jan 24, 2005
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rob Dempster

    RMI with rmiregistry on remote host

    Rob Dempster, Oct 8, 2003, in forum: Java
    Replies:
    1
    Views:
    2,694
    Marek Lange
    Oct 8, 2003
  2. Arun Goel
    Replies:
    0
    Views:
    941
    Arun Goel
    Nov 12, 2003
  3. JP Martin

    RMI without the rmiregistry

    JP Martin, Oct 5, 2004, in forum: Java
    Replies:
    1
    Views:
    3,077
    Esmond Pitt
    Oct 6, 2004
  4. silarri

    Monitoring the rmiregistry

    silarri, Jan 3, 2005, in forum: Java
    Replies:
    3
    Views:
    1,534
    silarri
    Jan 4, 2005
  5. David Kensche

    Help! with RMIRegistry

    David Kensche, Mar 11, 2005, in forum: Java
    Replies:
    0
    Views:
    704
    David Kensche
    Mar 11, 2005
Loading...

Share This Page