Solved

RMI Stub question...

Posted on 2004-08-05
10
382 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
  • 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
 
LVL 1

Expert Comment

by:wolfc
ID: 11728150
Which version JDK?
0
 

Author Comment

by:maxol
ID: 11728226
jdk1.4.2_01
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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 500 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

759 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now