Using Java Remote Method Invocation


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:


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


•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


Sample Code: Server Application



Sample Client Application:



•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



Setting Up Jenkins Using A Git Server Part2

This article will be focusing on setting up multiple users in your test git project so they can access it from different machines. If you have not read part one you can find it here

Note: these instructions are for Linux only i’m afraid

Step 1) You need to create a ssh public key on the machine you wish to connect to the git server. For an overview of how ssh works and setting up ssh on your machine you can find it here. This can be done with the following command:

ssh-keygen -t rsa

It will ask you a series of questions, just press enter for all of them. This would create your public key in your home/.ssh directory.

Step 2) Next we will make a copy of it so it has a more meaningful name (

id_rsa  known_hosts

This should now be the contents of your .ssh folder

Step 3) Now we need to copy our new public key onto the machine which hosts the git server. This can be done via usb, email (as it;s your public key and not private) or using the Linux Cat command

For the linux cat command you will need to know the password of the machine hosting the git server.  More detailed info on using the cat command can be found here

for now copy the public key to the home folder running the git server

Step 4) Now on the git server machine copy the key to the keydir directory of the git server

cp /home/ /home/gitosis-admin/keydir

your keydir directory should now have the original key which you used in part 1 to set up the git server and your new public key

Step 5) Next we need to edit the gitosis-admin.conf file to tell the git server we have added a new key to the keydir directory

gedit /home/gitosis-admin/gitosis.conf

This should be how your current config file should look from part1 of the article:


[group gitosis-admin]
members = james@james-machine
writable = gitosis-admin

[group testGroup]
members = james@james-machine
writable = testproject

next add the text ‘testMachine1’ to the members part of the testGroup section so that your config file now looks like this (do not add the .pub extension of the file)


[group gitosis-admin]
members = james@james-machine
writable = gitosis-admin

[group testGroup]
members = james@james-machine testMachine1
writable = testproject

save and close the file. When you type the following command the git server should have detected the following changes:

git status

# On branch master
# Changes not staged for commit:
#   (use “git add <file>…” to update what will be committed)
#   (use “git checkout — <file>…” to discard changes in working directory)
#    modified:   gitosis.conf

Step 6)Next we need to add testMachine1 key to the git change list so it’s tracked. Navigate to the keydir folder and type

git add .

Next we will commit our changes to the git server

git commit -am “adding new user to test project”

git push gitosis@[ipaddress]:gitosis-admin.git

Counting objects: 5, done.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 360 bytes, done.
Total 3 (delta 1), reused 0 (delta 0)
To gitosis@
b00222d..26f4d4b  master -> master

Setp 7) Now we will test our new git user by making changes to our test project and commiting using the new git user testMachine1.This can be done on the git server machine or the machine which generated your new ssh public key testMachine1

First navigate to test project and make a change to an existing file.

cd /home/testproject

gedit a.txt

git status

# On branch master
# Changes not staged for commit:
#   (use “git add <file>…” to update what will be committed)
#   (use “git checkout — <file>…” to discard changes in working directory)
#    modified:   a.txt

Step 8) Finally commit your changes using the new userrname:

git commit -am “making changes using new username”

1 files changed, 1 insertions(+), 0 deletions(-)

git push testMachine1@[ipaddress of git server]:testproject.git

The next article will be downloading and starting jenkins as a CI environment