|
activemq-cpp-3.4.0
|
00001 /* 00002 * Licensed to the Apache Software Foundation (ASF) under one or more 00003 * contributor license agreements. See the NOTICE file distributed with 00004 * this work for additional information regarding copyright ownership. 00005 * The ASF licenses this file to You under the Apache License, Version 2.0 00006 * (the "License"); you may not use this file except in compliance with 00007 * the License. You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 00018 #ifndef _DECAF_UTIL_CONCURRENT_SYNCHRONOUSQUEUE_H_ 00019 #define _DECAF_UTIL_CONCURRENT_SYNCHRONOUSQUEUE_H_ 00020 00021 #include <decaf/util/Config.h> 00022 00023 #include <decaf/util/concurrent/BlockingQueue.h> 00024 00025 #include <vector> 00026 00027 namespace decaf { 00028 namespace util { 00029 namespace concurrent { 00030 00063 template< typename E > 00064 class SynchronousQueue : public BlockingQueue<E> { 00065 private: 00066 00067 class EmptyIterator : public Iterator<E> { 00068 public: 00069 00070 virtual E next() { 00071 00072 throw NoSuchElementException( 00073 __FILE__, __LINE__, 00074 "Cannot traverse a Synchronous Queue." ); 00075 } 00076 00077 virtual bool hasNext() const { 00078 return false; 00079 } 00080 00081 virtual void remove() { 00082 00083 throw lang::exceptions::IllegalStateException( 00084 __FILE__, __LINE__, 00085 "No Elements to remove from a Synchronous Queue." ); 00086 } 00087 }; 00088 00089 private: 00090 00091 SynchronousQueue( const SynchronousQueue& ); 00092 SynchronousQueue& operator= ( const SynchronousQueue& ); 00093 00094 public: 00095 00096 SynchronousQueue() {} 00097 00098 virtual ~SynchronousQueue() {} 00099 00110 virtual void put( const E& value ) { 00111 00112 //if (o == null) throw new NullPointerException(); 00113 //if (transferer.transfer(o, false, 0) == null) { 00114 // Thread.interrupted(); 00115 // throw new InterruptedException(); 00116 //} 00117 } 00118 00130 virtual bool offer( const E& e, long long timeout, const TimeUnit& unit ) { 00131 00132 //if (o == null) throw new NullPointerException(); 00133 //if (transferer.transfer(o, true, unit.toNanos(timeout)) != null) 00134 // return true; 00135 //if (!Thread.interrupted()) 00136 // return false; 00137 //throw new InterruptedException(); 00138 00139 throw false; 00140 } 00141 00156 virtual bool offer( const E& value ) { 00157 00158 //if (e == null) throw new NullPointerException(); 00159 //return transferer.transfer(e, true, 0) != null; 00160 00161 return false; 00162 } 00163 00171 virtual E take() { 00172 //Object e = transferer.transfer(null, false, 0); 00173 //if (e != null) 00174 // return (E)e; 00175 //Thread.interrupted(); 00176 //throw new InterruptedException(); 00177 00178 return E(); 00179 } 00180 00195 virtual bool poll( E& result, long long timeout, const TimeUnit& unit ) { 00196 00197 //Object e = transferer.transfer(null, true, unit.toNanos(timeout)); 00198 //if (e != null || !Thread.interrupted()) 00199 // return (E)e; 00200 //throw new InterruptedException(); 00201 00202 return false; 00203 } 00204 00215 virtual bool poll( E& result ) { 00216 return false; // (E)transferer.transfer(null, true, 0); 00217 } 00218 00219 virtual bool equals( const Collection<E>& value ) const { 00220 if( (void*)&value == this ) { 00221 return true; 00222 } 00223 00224 return false; 00225 } 00226 00227 virtual decaf::util::Iterator<E>* iterator() { 00228 return new EmptyIterator(); 00229 } 00230 00231 virtual decaf::util::Iterator<E>* iterator() const { 00232 return new EmptyIterator(); 00233 } 00234 00235 virtual bool isEmpty() const { 00236 return true; 00237 } 00238 00239 virtual int size() const { 00240 return 0; 00241 } 00242 00243 virtual int remainingCapacity() const { 00244 return 0; 00245 } 00246 00247 virtual void clear() {} 00248 00249 virtual bool contains( const E& value DECAF_UNUSED ) const { 00250 return false; 00251 } 00252 00253 virtual bool containsAll( const Collection<E>& collection ) const { 00254 return collection.isEmpty(); 00255 } 00256 00257 virtual bool remove( const E& value DECAF_UNUSED ) { 00258 return false; 00259 } 00260 00261 virtual bool removeAll( const Collection<E>& collection DECAF_UNUSED ) { 00262 return false; 00263 } 00264 00265 virtual bool retainAll( const Collection<E>& collection DECAF_UNUSED ) { 00266 return false; 00267 } 00268 00269 virtual bool peek( E& result DECAF_UNUSED ) const { 00270 return false; 00271 } 00272 00273 virtual std::vector<E> toArray() const { return std::vector<E>(); } 00274 00275 virtual int drainTo( Collection<E>& c ) { 00276 00277 if( (void*)&c == this ) { 00278 throw decaf::lang::exceptions::IllegalArgumentException( 00279 __FILE__, __LINE__, 00280 "Cannot drain a Collection to Itself." ); 00281 } 00282 00283 int count = 0; 00284 E element; 00285 00286 while( ( poll( element ) ) != false ) { 00287 c.add( element ); 00288 ++count; 00289 } 00290 00291 return count; 00292 } 00293 00294 virtual int drainTo( Collection<E>& c, int maxElements ) { 00295 00296 if( (void*)&c == this ) { 00297 throw decaf::lang::exceptions::IllegalArgumentException( 00298 __FILE__, __LINE__, 00299 "Cannot drain a Collection to Itself." ); 00300 } 00301 00302 int count = 0; 00303 E element; 00304 00305 while( count < maxElements && ( poll( element ) != false ) ) { 00306 c.add( element ); 00307 ++count; 00308 } 00309 00310 return count; 00311 } 00312 00313 }; 00314 00315 }}} 00316 00317 #endif /* _DECAF_UTIL_CONCURRENT_SYNCHRONOUSQUEUE_H_ */