FileDocCategorySizeDatePackage
SynchronizedPrinter.javaAPI DocExample1900Thu Nov 08 00:23:34 GMT 2001com.ora.rmibook.chapter21.printer.printers

SynchronizedPrinter

public class SynchronizedPrinter extends Object implements Printer

Fields Summary
private PrintWriter
_log
Constructors Summary
public SynchronizedPrinter(OutputStream log)

        _log = new PrintWriter(log);
    
Methods Summary
public synchronized booleanprintDocument(DocumentDescription documentDescription)

        if (null == _log) {
            throw new NoLogException();
        }
        if (null == documentDescription) {
            throw new NoDocumentException();
        }
        _log.println("Printed file");
        _log.flush();
        if (_log.checkError()) {
            throw new CantWriteToLogException();
        }
        sleepForRandomAmountOfTime();
        return true;
    
public synchronized booleanprinterAvailable()

        return true;
    
private voidsleepForRandomAmountOfTime()

        int time = 1000 + (int) (Math.random() * 100000);

        try {
            Thread.sleep(time);
        } catch (Exception ignored) {
        }