Solved

RMI Stub question...

Posted on 2004-08-05
10
386 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
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…
This video teaches viewers about errors in exception handling.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

867 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

22 Experts available now in Live!

Get 1:1 Help Now