O'Reilly logo

Java RMI by William Grosso

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The Basic Objects

It’s often useful to start the process of designing a distributed application by pretending it is a single-machine application. Doing this allows architects to focus on finding the domain objects first.[17] Once the domain objects have been discovered, and their roles have been defined, the distributed infrastructure can be built around them.

In this case, we’ll start with a very simple interface for our abstract notion of Printer:

public interface Printer extends PrinterConstants {
	public boolean printerAvailable(  );
	public boolean printDocument(DocumentDescription document) throws
         PrinterException;
}

Our goal is to take a concrete implementation of the Printer interface[18] and make it available over the network.

This definition of Printer relies on two additional classes: DocumentDescription and PrinterException. These are both fairly simple classes, designed more to encapsulate related pieces of information than to implement complex behavior. The definition of DocumentDescription begins with five state variables that encapsulate the print request:

public class DocumentDescription {
	public static final int FAST_PRINTING = 0;
	public static final int HIGH_QUALITY_PRINTING = 1;

	public static final int POSTSCRIPT = 0;
	public static final int PDF = 1;

	private DataInputStream _actualDocument;
	private int _documentType;
	private boolean _printTwoSided;
	private int _printQuality;
	private int _length;

The only interesting aspect of this is the decision to use ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required