[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

RMI Stub question...

Posted on 2004-08-05
10
Medium Priority
?
424 Views
Last Modified: 2006-11-17
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
Comment
Question by:maxol
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +2
10 Comments
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 11727803
it seems somewhere you are wrong
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 11727813
can u post some code snippet so that experts understand

Best Regards
Sudhakar Chavali
0
 

Author Comment

by:maxol
ID: 11728030
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:wolfc
ID: 11728150
Which version JDK?
0
 

Author Comment

by:maxol
ID: 11728226
jdk1.4.2_01
0
 
LVL 35

Expert Comment

by:girionis
ID: 11728441
Can you make sure it is serializable and the data you want to transfer can also be serialized?
0
 
LVL 7

Expert Comment

by:bvanderveen
ID: 11729186
You need to make  sure the remote interface the stub is implementing is also on the other machine's classpath.
0
 
LVL 1

Accepted Solution

by:
wolfc earned 1500 total points
ID: 11734279
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
 

Author Comment

by:maxol
ID: 11734317
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
 
LVL 1

Expert Comment

by:wolfc
ID: 11734596
You're welcome. :-)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question