KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jgroups > util > SizeBoundedQueue


1 package org.jgroups.util;
2
3
4 import java.util.Map JavaDoc;
5 import java.util.Collection JavaDoc;
6 import java.util.Iterator JavaDoc;
7 import java.util.concurrent.ConcurrentHashMap JavaDoc;
8 import java.util.concurrent.BlockingQueue JavaDoc;
9 import java.util.concurrent.TimeUnit JavaDoc;
10
11 /**
12  * Queue as described in http://jira.jboss.com/jira/browse/JGRP-376. However, this queue only works with
13  * {@link org.jgroups.protocols.TP.IncomingPacket} elements.
14  * The queue maintains a max number of bytes and a total of all of the messages in the internal queues. Whenever a
15  * message is added, we increment the total by the length of the message. When a message is removed, we decrement the
16  * total. Removal blocks until a message is available, addition blocks if the max size has been exceeded, until there
17  * is enough space to add another message.
18  * Note that the max size should always be greater than the size of the largest message to be received, otherwise an
19  * additon would always fail because msg.length > max size !<br/>
20  * Access patterns: this instance is always accessed by the thread pool only ! Concurrent take() or poll() methods,
21  * but only a single thread at a time calls put() !
22  * @author Bela Ban
23  * @version $Id: SizeBoundedQueue.java,v 1.3 2006/12/31 14:29:52 belaban Exp $
24  */

25 public class SizeBoundedQueue implements BlockingQueue JavaDoc {
26     int max_size=1000 * 1000;
27     int capacity=0;
28     /** Map<Address, List<IncomingMessage>>. Maintains a list of unicast messages per sender */
29     final Map JavaDoc ucast_msgs=new ConcurrentHashMap JavaDoc(10);
30     /** Map<Address, List<IncomingMessage>>. Maintains a list of multicast messages per sender */
31     final Map JavaDoc mcast_msgs=new ConcurrentHashMap JavaDoc(10);
32
33
34     public boolean add(Object JavaDoc o) {
35         return false;
36     }
37
38     public int drainTo(Collection JavaDoc c) {
39         return 0;
40     }
41
42     public int drainTo(Collection JavaDoc c, int maxElements) {
43         return 0;
44     }
45
46     public boolean offer(Object JavaDoc o) {
47         return false;
48     }
49
50     public boolean offer(Object JavaDoc o, long timeout, TimeUnit JavaDoc unit) throws InterruptedException JavaDoc {
51         return false;
52     }
53
54     public Object JavaDoc poll(long timeout, TimeUnit JavaDoc unit) throws InterruptedException JavaDoc {
55         return null;
56     }
57
58     public void put(Object JavaDoc o) throws InterruptedException JavaDoc {
59     }
60
61     public int remainingCapacity() {
62         return 0;
63     }
64
65     public Object JavaDoc take() throws InterruptedException JavaDoc {
66         return null;
67     }
68
69
70     public Object JavaDoc element() {
71         return null;
72     }
73
74     public Object JavaDoc peek() {
75         return null;
76     }
77
78     public Object JavaDoc poll() {
79         return null;
80     }
81
82     public Object JavaDoc remove() {
83         return null;
84     }
85
86     public boolean addAll(Collection JavaDoc c) {
87         return false;
88     }
89
90     public void clear() {
91     }
92
93     public boolean contains(Object JavaDoc o) {
94         return false;
95     }
96
97     public boolean containsAll(Collection JavaDoc c) {
98         return false;
99     }
100
101     public boolean isEmpty() {
102         return false;
103     }
104
105     public Iterator JavaDoc iterator() {
106         return null;
107     }
108
109     public boolean remove(Object JavaDoc o) {
110         return false;
111     }
112
113     public boolean removeAll(Collection JavaDoc c) {
114         return false;
115     }
116
117     public boolean retainAll(Collection JavaDoc c) {
118         return false;
119     }
120
121     public int size() {
122         return 0;
123     }
124
125     public Object JavaDoc[] toArray() {
126         return new Object JavaDoc[0];
127     }
128
129     public Object JavaDoc[] toArray(Object JavaDoc[] a) {
130         return new Object JavaDoc[0];
131     }
132 }
133
Popular Tags