RMI – interface

Sometimes you will want to call a remote server e.g. like in a library, and see if a book has been taken out or not. Well in Java you can use something that is called a Remote Method Invocation ( it is very similar to web services ) this allows for a server to respond to clients without sending any more data across than what is required.

In this part of the tutorial I am building up the interface which the Client can use because the server will be implementing the functions below, but the Client only needs to know what functions have been implemented.

import java.rmi.*;
import java.util.*;
// this is used by the RMIClient.java to communicate with the remote server
// the Book.java uses this to implement a Book
// a remote interface java.rmi.Remote 
public interface Borrowable extends Remote {
	// all interface functions must throw RemoteException
	// is the booked checked out
	public boolean isCheckedOut() throws RemoteException;
	// return the library card number
	public String checkedOutCardNumber() throws RemoteException;
	// check out the book
	public boolean checkOut(String cardNumber, Date d) throws RemoteException;
	// check back in the book
	public boolean checkIn(String cardNumber, Date d) throws RemoteException;

so if you save that as the Borrowable.java file.

Next I am going to do the Book.java file, which is what the server will use as the library book as such.

Leave a Reply

Your email address will not be published. Required fields are marked *