Is it possible to register non-Java objects with the RMI Registry?

M

mshetty

Hi,

I have read that RMI Registry is a name server wherein Java Objects can
be registered.

I have a query.. Is it possible to register non-Java objects with the
RMI Registry?

Non-Java as-in say CORBA Objects developed using C++.

Thanks and Regards,
M Shetty
 
T

Thomas Fritsch

I have read that RMI Registry is a name server wherein Java Objects can
be registered.

I have a query.. Is it possible to register non-Java objects with the
RMI Registry?

Non-Java as-in say CORBA Objects developed using C++.

The RMI registry can register Java objects only (or to be more exact:
implementations of java.rmi.Remote).
However, you can create simple Java wrapper objects for carrying any
native data, like in the following *incomplete* example:

public class WrapperObject implements Remote {
private int pData;
WrapperObject(....) { init(); }
private native void init();
private native void free();
protected void finalize() { free(); }
}

The pData variable can contain a C/C++ pointer. The native methods,
which you can implement in C/C++ via JNI, do the real stuff.
The init() method allocates the C/C++ object and stores the pointer in
pData. The free() method is called when the Java object is
garbage-collected and frees the C/C++ object.
(BTW: Java itself uses sort of this technique in many places, for
example in class java.awt.Font)

Complications will arise because RMI objects are usually intended to be
transported through the net. Hence you'll have to implement the
semantics of the Serializable interface somehow. How much effort this
will be, depends on what kind of non-Java objects you have.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top