activemq-cpp-3.9.5
SynchronousQueue.h
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef _DECAF_UTIL_CONCURRENT_SYNCHRONOUSQUEUE_H_
19#define _DECAF_UTIL_CONCURRENT_SYNCHRONOUSQUEUE_H_
20
21#include <decaf/util/Config.h>
22
24
25#include <vector>
26
27namespace decaf {
28namespace util {
29namespace concurrent {
30
63 template< typename E >
64 class SynchronousQueue : public BlockingQueue<E> {
65 private:
66
67 class EmptyIterator : public Iterator<E> {
68 public:
69
70 virtual E next() {
72 __FILE__, __LINE__,
73 "Cannot traverse a Synchronous Queue.");
74 }
75
76 virtual bool hasNext() const {
77 return false;
78 }
79
80 virtual void remove() {
82 __FILE__, __LINE__,
83 "No Elements to remove from a Synchronous Queue.");
84 }
85 };
86
87 private:
88
89 SynchronousQueue(const SynchronousQueue&);
90 SynchronousQueue& operator=(const SynchronousQueue&);
91
92 public:
93
95
96 virtual ~SynchronousQueue() {}
97
108 virtual void put(const E& value DECAF_UNUSED) {
109
110 //if (o == null) throw new NullPointerException();
111 //if (transferer.transfer(o, false, 0) == null) {
112 // Thread.interrupted();
113 // throw new InterruptedException();
114 //}
115 }
116
128 virtual bool offer(const E& e DECAF_UNUSED, long long timeout DECAF_UNUSED, const TimeUnit& unit DECAF_UNUSED) {
129
130 //if (o == null) throw new NullPointerException();
131 //if (transferer.transfer(o, true, unit.toNanos(timeout)) != null)
132 // return true;
133 //if (!Thread.interrupted())
134 // return false;
135 //throw new InterruptedException();
136
137 throw false;
138 }
139
154 virtual bool offer(const E& value DECAF_UNUSED) {
155
156 //if (e == null) throw new NullPointerException();
157 //return transferer.transfer(e, true, 0) != null;
158
159 return false;
160 }
161
169 virtual E take() {
170 //Object e = transferer.transfer(null, false, 0);
171 //if (e != null)
172 // return (E)e;
173 //Thread.interrupted();
174 //throw new InterruptedException();
175
176 return E();
177 }
178
193 virtual bool poll(E& result DECAF_UNUSED, long long timeout DECAF_UNUSED, const TimeUnit& unit DECAF_UNUSED) {
194
195 //Object e = transferer.transfer(null, true, unit.toNanos(timeout));
196 //if (e != null || !Thread.interrupted())
197 // return (E)e;
198 //throw new InterruptedException();
199
200 return false;
201 }
202
213 virtual bool poll(E& result DECAF_UNUSED) {
214 return false; // (E)transferer.transfer(null, true, 0);
215 }
216
217 virtual bool equals(const Collection<E>& value) const {
218 if ((void*) &value == this) {
219 return true;
220 }
221
222 return false;
223 }
224
226 return new EmptyIterator();
227 }
228
230 return new EmptyIterator();
231 }
232
233 virtual bool isEmpty() const {
234 return true;
235 }
236
237 virtual int size() const {
238 return 0;
239 }
240
241 virtual int remainingCapacity() const {
242 return 0;
243 }
244
245 virtual void clear() {}
246
247 virtual bool contains(const E& value DECAF_UNUSED) const {
248 return false;
249 }
250
251 virtual bool containsAll(const Collection<E>& collection) const {
252 return collection.isEmpty();
253 }
254
255 virtual bool remove(const E& value DECAF_UNUSED) {
256 return false;
257 }
258
259 virtual bool removeAll(const Collection<E>& collection DECAF_UNUSED) {
260 return false;
261 }
262
263 virtual bool retainAll(const Collection<E>& collection DECAF_UNUSED) {
264 return false;
265 }
266
267 virtual bool peek(E& result DECAF_UNUSED) const {
268 return false;
269 }
270
271 virtual std::vector<E> toArray() const {
272 return std::vector<E>();
273 }
274
275 virtual int drainTo(Collection<E>& c) {
276
277 if ((void*) &c == this) {
279 __FILE__, __LINE__,
280 "Cannot drain a Collection to Itself.");
281 }
282
283 int count = 0;
284 E element;
285
286 while ((poll(element)) != false) {
287 c.add(element);
288 ++count;
289 }
290
291 return count;
292 }
293
294 virtual int drainTo(Collection<E>& c, int maxElements) {
295
296 if ((void*) &c == this) {
298 __FILE__, __LINE__,
299 "Cannot drain a Collection to Itself.");
300 }
301
302 int count = 0;
303 E element;
304
305 while (count < maxElements && (poll(element) != false)) {
306 c.add(element);
307 ++count;
308 }
309
310 return count;
311 }
312
313 public:
314
315 using AbstractQueue<E>::remove;
316
317 };
318
319}}}
320
321#endif /* _DECAF_UTIL_CONCURRENT_SYNCHRONOUSQUEUE_H_ */
Definition IllegalArgumentException.h:31
Definition IllegalStateException.h:32
This class provides skeletal implementations of some Queue operations.
Definition AbstractQueue.h:48
virtual E element() const
Gets but not removes the element in the head of the queue.Throws a NoSuchElementException if there is...
Definition AbstractQueue.h:112
virtual E remove()
Gets and removes the element in the head of the queue.Throws a NoSuchElementException if there is no ...
Definition AbstractQueue.h:95
The root interface in the collection hierarchy.
Definition Collection.h:69
virtual bool add(const E &value)=0
Returns true if this collection changed as a result of the call.
virtual bool isEmpty() const =0
Defines an object that can be used to iterate over the elements of a collection.
Definition Iterator.h:34
Definition NoSuchElementException.h:31
A decaf::util::Queue that additionally supports operations that wait for the queue to become non-empt...
Definition BlockingQueue.h:164
virtual bool equals(const Collection< E > &value) const
Compares the passed collection to this one, if they contain the same elements, i.e.
Definition SynchronousQueue.h:217
virtual void clear()
Removes all of the elements from this collection (optional operation).This collection will be empty a...
Definition SynchronousQueue.h:245
virtual bool poll(E &result DECAF_UNUSED, long long timeout DECAF_UNUSED, const TimeUnit &unit DECAF_UNUSED)
Retrieves and removes the head of this queue, waiting if necessary up to the specified wait time,...
Definition SynchronousQueue.h:193
virtual int drainTo(Collection< E > &c, int maxElements)
Removes at most the given number of available elements from this queue and adds them to the given col...
Definition SynchronousQueue.h:294
virtual ~SynchronousQueue()
Definition SynchronousQueue.h:96
virtual void put(const E &value DECAF_UNUSED)
Adds the specified element to this queue, waiting if necessary for another thread to receive it.
Definition SynchronousQueue.h:108
virtual bool poll(E &result DECAF_UNUSED)
Retrieves and removes the head of this queue, if another thread is currently making an element availa...
Definition SynchronousQueue.h:213
virtual bool remove(const E &value DECAF_UNUSED)
Definition SynchronousQueue.h:255
virtual bool removeAll(const Collection< E > &collection DECAF_UNUSED)
Definition SynchronousQueue.h:259
virtual decaf::util::Iterator< E > * iterator() const
Definition SynchronousQueue.h:229
virtual int size() const
Returns the number of elements in this collection.
Definition SynchronousQueue.h:237
virtual bool retainAll(const Collection< E > &collection DECAF_UNUSED)
Definition SynchronousQueue.h:263
virtual int drainTo(Collection< E > &c)
Removes all available elements from this queue and adds them to the given collection.
Definition SynchronousQueue.h:275
virtual std::vector< E > toArray() const
Returns an array containing all of the elements in this collection.
Definition SynchronousQueue.h:271
virtual bool containsAll(const Collection< E > &collection) const
Returns true if this collection contains all of the elements in the specified collection.
Definition SynchronousQueue.h:251
virtual bool offer(const E &value DECAF_UNUSED)
Inserts the specified element into this queue, if another thread is waiting to receive it.
Definition SynchronousQueue.h:154
virtual bool isEmpty() const
Definition SynchronousQueue.h:233
virtual bool contains(const E &value DECAF_UNUSED) const
Definition SynchronousQueue.h:247
virtual bool offer(const E &e DECAF_UNUSED, long long timeout DECAF_UNUSED, const TimeUnit &unit DECAF_UNUSED)
Inserts the specified element into this queue, waiting if necessary up to the specified wait time for...
Definition SynchronousQueue.h:128
SynchronousQueue()
Definition SynchronousQueue.h:94
virtual int remainingCapacity() const
Returns the number of additional elements that this queue can ideally (in the absence of memory or re...
Definition SynchronousQueue.h:241
virtual decaf::util::Iterator< E > * iterator()
Definition SynchronousQueue.h:225
virtual bool peek(E &result DECAF_UNUSED) const
Definition SynchronousQueue.h:267
virtual E take()
Retrieves and removes the head of this queue, waiting if necessary for another thread to insert it.
Definition SynchronousQueue.h:169
A TimeUnit represents time durations at a given unit of granularity and provides utility methods to c...
Definition TimeUnit.h:62
Definition AbstractExecutorService.h:28
Definition AbstractCollection.h:33
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
Definition AprPool.h:25