01: /**
02:  * This program implements the bounded buffer using message passing.
03:  * Note that this solutions is NOT thread-safe. A thread safe solution
04:  * can be developed using Java synchronization which is discussed in Chapter 7.
05:  *
06:  * Figure 4.14
07:  *
08:  * @author Gagne, Galvin, Silberschatz
09:  * Operating System Concepts with Java - Sixth Edition
10:  * Copyright John Wiley & Sons - 2003.
11:  */
12: 
13: import java.util.Vector;
14:  
15: public class MessageQueue implements Channel
16: {
17: private Vector queue;
18: 
19:    public MessageQueue() {
20:       queue = new Vector();
21:    }
22:    
23:    /*
24:     * This implements a non-blocking send
25:     */
26:    public void send(Object item) {
27:       queue.addElement(item);
28:    }
29:    
30:    /*
31:     * This implements a non-blocking receive
32:     */
33:     
34:    public Object receive() {
35:       if (queue.size() == 0)
36:          return null;
37:       else 
38:          return queue.remove(0);
39:     }
40: }