activemq-cpp-3.6.0
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 
27 namespace decaf {
28 namespace util {
29 namespace 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() {
71 
73  __FILE__, __LINE__,
74  "Cannot traverse a Synchronous Queue." );
75  }
76 
77  virtual bool hasNext() const {
78  return false;
79  }
80 
81  virtual void remove() {
82 
84  __FILE__, __LINE__,
85  "No Elements to remove from a Synchronous Queue." );
86  }
87  };
88 
89  private:
90 
92  SynchronousQueue& operator= ( const SynchronousQueue& );
93 
94  public:
95 
97 
98  virtual ~SynchronousQueue() {}
99 
110  virtual void put( const E& value ) {
111 
112  //if (o == null) throw new NullPointerException();
113  //if (transferer.transfer(o, false, 0) == null) {
114  // Thread.interrupted();
115  // throw new InterruptedException();
116  //}
117  }
118 
130  virtual bool offer( const E& e, long long timeout, const TimeUnit& unit ) {
131 
132  //if (o == null) throw new NullPointerException();
133  //if (transferer.transfer(o, true, unit.toNanos(timeout)) != null)
134  // return true;
135  //if (!Thread.interrupted())
136  // return false;
137  //throw new InterruptedException();
138 
139  throw false;
140  }
141 
156  virtual bool offer( const E& value ) {
157 
158  //if (e == null) throw new NullPointerException();
159  //return transferer.transfer(e, true, 0) != null;
160 
161  return false;
162  }
163 
171  virtual E take() {
172  //Object e = transferer.transfer(null, false, 0);
173  //if (e != null)
174  // return (E)e;
175  //Thread.interrupted();
176  //throw new InterruptedException();
177 
178  return E();
179  }
180 
195  virtual bool poll( E& result, long long timeout, const TimeUnit& unit ) {
196 
197  //Object e = transferer.transfer(null, true, unit.toNanos(timeout));
198  //if (e != null || !Thread.interrupted())
199  // return (E)e;
200  //throw new InterruptedException();
201 
202  return false;
203  }
204 
215  virtual bool poll( E& result ) {
216  return false; // (E)transferer.transfer(null, true, 0);
217  }
218 
219  virtual bool equals( const Collection<E>& value ) const {
220  if( (void*)&value == this ) {
221  return true;
222  }
223 
224  return false;
225  }
226 
228  return new EmptyIterator();
229  }
230 
232  return new EmptyIterator();
233  }
234 
235  virtual bool isEmpty() const {
236  return true;
237  }
238 
239  virtual int size() const {
240  return 0;
241  }
242 
243  virtual int remainingCapacity() const {
244  return 0;
245  }
246 
247  virtual void clear() {}
248 
249  virtual bool contains( const E& value DECAF_UNUSED ) const {
250  return false;
251  }
252 
253  virtual bool containsAll( const Collection<E>& collection ) const {
254  return collection.isEmpty();
255  }
256 
257  virtual bool remove( const E& value DECAF_UNUSED ) {
258  return false;
259  }
260 
261  virtual bool removeAll( const Collection<E>& collection DECAF_UNUSED ) {
262  return false;
263  }
264 
265  virtual bool retainAll( const Collection<E>& collection DECAF_UNUSED ) {
266  return false;
267  }
268 
269  virtual bool peek( E& result DECAF_UNUSED ) const {
270  return false;
271  }
272 
273  virtual std::vector<E> toArray() const { return std::vector<E>(); }
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  };
314 
315 }}}
316 
317 #endif /* _DECAF_UTIL_CONCURRENT_SYNCHRONOUSQUEUE_H_ */