Information Technology Reference
In-Depth Information
public class BoundedBufferV1 {
private Book array[];
private int takePtr = 0, putPtr = 0;
protected int usedSlots = 0, size;
BoundedBufferV1(int capacity) throws IllegalArgumentException {
if (capacity <= 0) throw new IllegalArgumentException();
array = new Object[capacity];
size = capacity ;
}
public int count() { return usedSlots; }
public int capacity() { return size; }
public void put(Book x) throws Full {
if (usedSlots == array.length) throw new Full();
array[putPtr] = x;
putPtr = (putPtr + 1) % size;
usedSlots++;
System.out.println( "BB got book:" );
b.print();
}
public Book take() throws Empty {
if (usedSlots == 0) throw new Empty();
Book old = array[takePtr];
takePtr = (takePtr + 1) % size;
usedSlots −− ;
return old;
}
}
public class Book {
private int isbn = 0;
private String title = null;
private Postscript ps;
Book(int n, String t) {isbn = n; title = t;}
public void print() {
System.out.println ( "Book: " + isbn + title);
}
}
Figure 3.7.
BoundedBuffer example (reproduced from Lopes
[65]).
methods of the class that can be invoked remotely, and the parameters and return
values of those methods. For each parameter and return value the programmer
may optionally define the mode that describes how the data transfers are to be
made, copy-by-value or copy-by-reference.
Search WWH ::




Custom Search