I am reading some RMI document and all the books say that we need to create Stub for the client in order to communicate with the server. However, I have tried to not create stub and things worked like a charm. I have put the client program on one machine and the server on another, things worked perfectly. So, what is actually the purpose of creating Stub and do we really need to create one? Thanks.
RMI uses a standard mechanism (employed in RPC systems) for communicating with remote objects: stubs and skeletons. A stub for a remote object acts as a client's local representative or proxy for the remote object.
Stub − A stub is a representation (proxy) of the remote object at client. It resides in the client system; it acts as a gateway for the client program. Skeleton − This is the object which resides on the server side. stub communicates with this skeleton to pass request to the remote object.
The stub and skeleton classes are responsible for dispatching and processing RMI requests. Developers should not write these classes, however. Once a service implementation exists, the rmic tool, which ships with the JDK, should be used to create them.
A stub may simulate the behavior of existing code (such as a procedure on a remote machine; such methods are often called mocks) or be a temporary substitute for yet-to-be-developed code. Stubs are therefore most useful in porting, distributed computing as well as general software development and testing.
Since Java 1.5 you don't have to:
This release adds support for the dynamic generation of stub classes at runtime, obviating the need to use [...] stub compiler, rmic, to pregenerate stub classes for remote objects. Note that rmic must still be used to pregenerate stub classes for remote objects that need to support clients running on earlier versions.
From http://download.oracle.com/javase/1.5.0/docs/guide/rmi/relnotes.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With