Using Java Remote Method Invocation

Overview

This arctile is a slightly off topic from the normal themes but worth writing about as it’s a tricky subject. The content below is from some slides i produced:

Agenda

•Introduction
•Why Use RMI
•Overview Of RMI
•Sample App
•Gotchas
•More reading

Introduction

•Remote Method Invocation allows method calls to be made from one Java Virtual Machine (JVM) to another JVM
•Operates A Client/Server Model where The Server ‘registers’ classes it wishes to be available for clients to access

Why Use RMI

•Removes the complexity of using Sockets to communicate
•Allows a level of control over which objects you can access
•Makes it easier to simulate real life client/server scenarios
•Lends itself well to TDD

Overview Of RMI

•RMI Registry – holds a list of stub references which have be registered by server application
•Server application – defines interfaces and concrete implementations to be registered on RMI Registry
•Client application – connects to the RMI registry in order to make use of servers classes

Overview Of RMI

overview

Sample Code: Server Application

sampleServer

 

Sample Client Application:

sampleClient

Gothcas:

•How do you make the compile classes available without copying them – use a webserver and have the client code download the classes dynamically
•Connection refused when running clientApp: Check serverApp is running first
•Class not found in client project: make sure you have copied the latest copy of your serverAppImpl.class to the client project
•Class not found exception when running client: ensure on the server application you have imported all of the classes your serverApp requires
More Reading

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s