I'm really new to Java RMI, and I don't quite understand what it actually does. When a remote method is called, is the method executed on the server, or the client? In other words does RMI utilize the servers resources or is it simply used for access to remote classes and methods which will run client side?
Java RMI (Remote Method Invocation) uses client side "stubs" to connect to server side implementation and the real work is done on the Server side.
Related
I am following the Java RMI tutorial from here to build an example compute engine where the clients can submit tasks to a known server, and which the server will perform the task and return the result.
Having compiled and created new tasks sucessfully I want to learn further by reversing the logic, i.e. the server sends the task to the clients.
How would I conceptually do this? If I have understood correctly, the RMI server exposes the executeTask() method, which a client calls upon connecting to the server. I am toiling with turning each client into a 'server', each running an RMI registry and another application will connect to each of the rmi registries and call the executeTask method, and thus download the class.
Is there an obvious apporach in the logic I am missing? Having multiple RMI registries seem's incorrect.
What I want to end up with is a server with exposed RMI registry. All clients connect to server, server calls executeTask() method on each client to process the task on the clients. Ofcourse the task class needs to be located at the server and downloaded dynamically to the clients (currently the task is located at the client and sent to the server).
Have the server expose a fetchNextTask() method, and have the clients call it when they're ready to perform another task.
Java RMI stand-alone applications
Is it possible to create a Server – Client Java application using RMI that can run just by running the server and the client (with servers IP), without any change on any environment variable, or installation of any other program?
As far as I know, to make an RMI compo (Server – Client) to work, you need:
server application
client application
protocol file(s) (implementations) common for both
but the location of the server must be accessible by the client. Is there a way that java can make it accessible without any help?
Is it possible to create a Server – Client Java application using RMI that can run just by running the server and the client (with servers IP), without any change on any environment variable, or installation of any other program?
RMI doesn't have environment variables or separate programs.
As far as I know, to make an RMI compo (Server – Client) to work, you need: server application client application protocol file(s) (implementations) common for both
No you don't. There is no such thing. You just need the relevant .class files in each place. I can't imagine where you are getting this misinformation from.
but the location of the server must be accessible by the client. Is there a way that java can make it accessible without any help?
No. Accessibility is a property of firewalls. If you could change that from the client there wouldn't be any point in having them in the first place.
We have working on simple definitions and concepts of Distributed Systems in computer networks which are
Replications and Transparency.
so I need to implement RMI client that connects to RMI proxy,then the proxy redirects the client connection to one of n-servers and choose to connect to one of these server based on some value between proxy and server.
so here we have n-servers replications and the client apply the transparency concepts that the client cannot connects directly to servers and from client perspective he can see only one server(proxy server).
Here is simple diagram for what i want to design using RMI only in java...
So, as i have some experience in RMI i implement client and server using RMI
but here Does i need to implement the Proxy server as server to serve the client and as client for the n-servers or what .....????
how to put the first step in implementing proxy using RMI....
Use RMI/IIOP with a load-balancing ORB.
I have implemented a RMI solution, where my client program can get a datasource object from a DB pool in a Server program . Both run on local host (I am still a newbiew ;) )
But then I was looking at one of the posts in SO and it mentioned about wrapping a socket first and then use the RMI to access the remote access object.
Java RMI not closing socket after lease expiration
I also read that RMI also uses Sockets internally.
My question is if I have to create a wrapper on the Socket instance and then use RMI, should I create Sockets (server and client sockets) by myself and then use RMI....if yes...then how to do it? I have learnt to create sockets and RMI but not use them together.
Unless you plan to write and control the protocol for communication between client and server, stick to using an RMI client to interrogate a server and use the RMI server to respond.
Also, a DataSource instance is not something you should serialise and distribute to clients. Typically I would expect that when the client makes requests for data, that the server would use the data source to access data on behalf of the client, then marshall the results and send them back to the client.
Trying to get an understanding on how the RMI is working (I have a simple application that uses RMI and seems to work just fine).
My question is : What happens when an rmi call is made? What happens on the way from an rmi client to an rmi server?
after the lookup described above, the objects used as parameters in a rmi call are serialized (Marshalling) that means a byte by byte representation of the objects non transient data will be send over the network connection. On server-side the serialized data will be unmarshalled and the objects will be instantiated. After that the server-side method is invoked, return values will be returned in a similar way as parameters have been previously send. It is similar to writing an object into a file.
http://java.sun.com/j2se/1.4.2/docs/guide/rmi/faq.html
RMI is the object oriented approach for RPC.
There is a Stub in client side and a Skeleton in server side. Client and Server does not directly communicate but they communicate over Stub and Skeleton which are generated automatically..
As you might guess there must be some objects both Server and Client have to use. These objects are defined in Server side and hold in RMI Registry. Both server and client can call RMI registry and it works as a memory somehow (It is not a Memory this is an example just to be clear). Server binds an object to registry and client invokes methods on it.