Friday, February 16, 2007

How To: Implement RMI from scratch

The java.lang.reflect.Proxy class will let you provide an arbitrary implementation for an interface.

So, start with that on the client. Figure out how to produce a factory for interface objects. Understand how the proxy invocation works.

Then, create a socket connection to the server. Wrap it with an ObjectInputStream/ObjectOutputStream.

Now you need to define a protocol between client and server. For example, let's say that the client sends an integer object ID, followed by a method name, followed by an array of parameters. The server needs to find the object, and invoke the appropriate method. Then it needs to send the result back to the client.

Then you can get into distributed GC ...

source: java dev forums

2 comments:

  1. Hello Mickail:

    Just I am thinking in the classes that I need for implementing RMI without making use of Java RMI. I mean to implement from zero and to use Java...

    1. What classes are required?
    2. What tools do I need for developing?
    3. Do you have some source code?

    I want implement the following:

    1. Interface Definition Language (IDL).
    2. IDL Compiler.
    3. Parameter Passing.
    4. Binding. (Do not using Naming.lookup(), Naming.bind())
    5. Marshalling and Unmarshalling.
    6. Execution Semantics : at-least-once, and at-most-once.
    7. Concurrent operations.

    Thanks you.

    Angel.

    ReplyDelete
  2. yikes, those are some nice requirements.

    I dont have much in terms of code, since i ended up not doing this, heh.

    I would say you can get by with 1) using java.lang.reflect.* for creating proxies (i have some code for this, will post tonight)
    sockets+threading for binding
    2) i know that java 1.5 has new classes for managing thread pools, which might be goo for resource manangement
    3) serialization for marshalling. i have an old post that shows you how to implement serialization for streams which might be helpful, filed under RMI.
    4) thread synchronization for concurrent stuff. you will need to have a multithreaded server listening.
    5) i have no idea what IDL is =)

    if you need to get in touch with me my AIM SN is ArcaneAche maybe i can help you. Good luck.

    ReplyDelete