Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What exactly is the point of the codebase in Java RMI?

Tags:

java

rmi

codebase

Im currently learning about RMI.

I dont really understand the concept of the codebase. Every paper i read suggests, that the client, which calls the Remote object can load the Method definitions from the codebase. The Problem is now: Dont I need the descriptions/interfaces in my classpath anyway? How can i call methods on the remote object, if i only know them during Runtime? This Wouldnt even compile.

Am i completely missing the point here? What exactly is the point of the codebase then? It seems like a lot of extra work and requirements to provide a codebase

thanks

like image 215
Simiil Avatar asked May 05 '12 19:05

Simiil


People also ask

What is Codebase in Java?

A codebase (sometimes spelled as two words, code base) is the complete body of source code for a given software program or application. Source code is the version of a program that a programmer writes and saves as a file.

What is the purpose of RMI registry?

The RMI registry is a simple server-side name server that allows remote clients to get a reference to a remote object. It typically is used to locate only the first remote object an RMI client needs to talk to. Then, that first object in turn, provides application-specific support getting references for other objects.

How does RMI work in Java?

RMI passes objects by their actual classes, so the behavior of the objects is not changed when they are sent to another Java virtual machine. This capability enables new types and behaviors to be introduced into a remote Java virtual machine, thus dynamically extending the behavior of an application.

What are the main features of RMI?

The RMI (Remote Method Invocation) is an API that provides a mechanism to create distributed application in java. The RMI allows an object to invoke methods on an object running in another JVM. The RMI provides remote communication between the applications using two objects stub and skeleton.


1 Answers

Well, let's say you provide to your client only interfaces, and the implementations will be located in a given code base. Then the client requests the server to send a given object, the client expects to receive an object that implements a given interface, but the actual implementation is unknown to the client, when it deserializes the sent object is when it has to go to the code base and download the corresponding implementing class for the actual object being passed.

This will make the client very thin, and you will very easily update your classes in the code base without having to resort to updating every single client.

EDIT

Let's say you have a RMI server with the following interface

public interface MiddleEarth {
     public List<Creature> getAllCreatures();
}

The client will only have the interfaces for MiddleEarth and Creature, but none of the implementations in the class path.

Where the implementations of Creature are serializable objects of type Elf, Man, Dwarf and Hobbit. And these implementations are located in your code base, but not in your client's class path.

When you ask your RMI server to send you the list of all creatures in Middle Earth, it will send objects that implement Creature, that is, any of the classes listed above.

When the client receives the serialized objects it has to look for the class files in order to deserialized them, but these are not located in the local class path. Every object in this stream comes tagged with the given code base that can be used to look for missing classes. Therefore, the client resort to the code base to look for these classes. There it will find the actual creature classes being used.

The code base works in both directions, so it means that if you send your server a Creature (i.e. an Ent) it will look for it in the code base as well.

This means that when both, client and server need to publish new types of creatures all they have to do is to update the creaturesImpl.jar in the code base, and nothing in the server or client applications themselves.

like image 199
Edwin Dalorzo Avatar answered Oct 12 '22 22:10

Edwin Dalorzo