• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 426
  • Last Modified:

RMI Stub question...

i'm trying to transfer a stub object to allow it to be invoked on a different machine.

when i do so, the stub object no longer contains a remoteRef? it is now null?

i.e. before the transfer it returns remote ref IP = xxx.xxx.xxx.xxx + port
      after transfer remote ref = null?

any help....
0
maxol
Asked:
maxol
  • 3
  • 3
  • 2
  • +2
1 Solution
 
sudhakar_koundinyaCommented:
it seems somewhere you are wrong
0
 
sudhakar_koundinyaCommented:
can u post some code snippet so that experts understand

Best Regards
Sudhakar Chavali
0
 
maxolAuthor Commented:
RMI object exported is called 'myServer'

RemoteStub rs = RemoteObject.toStub(myServer);

System.out.println(rs.toString())    gives "RemoteStub [ref: 111.111.111.111 ObjID:0] ... okay

after i send it over an ObjectOutputStream and recast it as a stub the

System.out.println(rs.toString())    gives "RemoteStub [ref: null] ... bad, no reference now

??
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
wolfcCommented:
Which version JDK?
0
 
maxolAuthor Commented:
jdk1.4.2_01
0
 
girionisCommented:
Can you make sure it is serializable and the data you want to transfer can also be serialized?
0
 
bvanderveenCommented:
You need to make  sure the remote interface the stub is implementing is also on the other machine's classpath.
0
 
wolfcCommented:
Using http://java.sun.com/j2se/1.4.2/docs/guide/rmi/getstart.doc.html as a base.

Added the following to HelloImpl:
      RemoteStub rs = (RemoteStub) RemoteObject.toStub(obj);
      
      System.out.println("rs = " + rs);
      
      ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("hello.ref"));
      out.writeObject(rs);
      out.flush();
      out.close();
                  
Created:
package examples.hello;

import java.io.FileInputStream;
import java.io.ObjectInputStream;

public class HelloFile{
    public static void main(String args[]) {
        try {
              ObjectInputStream in = new ObjectInputStream(new FileInputStream("hello.ref"));
              Object rs = in.readObject();
              in.close();
              
              System.out.println("rs = " + rs);
              Hello obj = (Hello) rs;
              System.out.println(obj.sayHello());
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("HelloFile exception: " + e.getMessage());
        }
    }
}

Got the following on Windows XP using JDK 1.4.2_03:
rs = examples.hello.HelloImpl_Stub[RemoteStub [ref: [endpoint:[192.168.1.7:1441](local),objID:[0]]]]
HelloServer bound in registry
Saying hello to 192.168.1.1

With on Debian Woody Linux 2.4.18 using JRE 1.4.1_05:
carlo@ogre:~/tmp/TestRMI$ java -cp . examples.hello.HelloFile
rs = examples.hello.HelloImpl_Stub[RemoteStub [ref: [endpoint:[192.168.1.7:1441](remote),objID:[1bab50a:fe33b6565b:-8000, 0]]]]
Hello World!

And the same running HelloFile on Windows.

What am I doing right? :-)
0
 
maxolAuthor Commented:
you beauty!

i was casting it as a stub when it should have been a remote object on the client side!

i thank you!
0
 
wolfcCommented:
You're welcome. :-)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 3
  • 3
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now