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

And So It Begins!

So i finally decided to create a blog on software testing, agile practices I’ve used and continuous integration. The aim of this site is out put my experiences that I’ve learned into one place for others benefit from. My only disclaimer is that i don’t have all the answers and i can only go on what I’ve learnt so watch this space!