RMI – implementation of the library book

As from previous post, the Borrowable interface, for the RMI (Remote Method Invocation), this is the part of the Book class, this is what is called from the Library as such to see if a book has been taken out or not.

import java.util.*;
import java.rmi.*;
import java.rmi.server.*;
 
// UnicaseRemoteObject = remote object classes need to implement the related
// remote interface
public class Book extends UnicastRemoteObject implements Borrowable {
	private Date borrowDate;
	private Date returnDate;
	private String borrowerID;
	private String title;
	private boolean checkedOut = false;
 
	// create book.
	public Book (String bookName) throws RemoteException
	{
		title = bookName;
	}
 
	// is the book already checked out ?
	public boolean isCheckedOut() throws RemoteException
	{
		return checkedOut;
	}
 
	// if the book is checked out, return the library card number + date it was taken out on
	public String checkedOutCardNumber() throws RemoteException
	{
		String returnID = null;
		if (isCheckedOut())
		{
			returnID = borrowerID + " Date taken out on "+ borrowDate.toString();
		}
		return returnID;
	}
 
	public boolean checkOut(String cardNumber, Date d ) throws RemoteException
	{
		// do not check out the book if already checked out!
		if (isCheckedOut())
			return false;
		borrowerID = cardNumber;
		borrowDate = d;
		checkedOut = true;
		return true;
	}
 
	public boolean checkIn(String cardNumber, Date d) throws RemoteException
	{
		// if it is checked out, check the book in.
		if (isCheckedOut())
		{
			borrowerID = cardNumber;
			returnDate = d;
			checkedOut = false;
			return true;
		}
		return false;
	}
}

if you save that as Book.java, next comes the fun part the actual Library server as such.

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.

Acid Rip

I have just been using AcidRip to convert DVD’s into AVI files so that I can I copies of family movies in a more compressed format.. it will either use a DVD disk or a DVD image on a harddrive to convert to the required format that you want.

It uses mencoder which is part of the mplayer suit of applications, mplayer is also a very nice movie player too, which I use mainly from the command line, but there is also a GUI for it.

mplayer -fs <filename>

would play a video in full screen (-fs) and since I do have a console window open most of the time then it is sometimes just easier to use the console to play a video.