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 _ACTIVEMQ_CORE_SIMPLEPRIORITYMESSAGEDISPATCHCHANNEL_H_ 00019 #define _ACTIVEMQ_CORE_SIMPLEPRIORITYMESSAGEDISPATCHCHANNEL_H_ 00020 00021 #include <activemq/util/Config.h> 00022 #include <activemq/core/MessageDispatchChannel.h> 00023 00024 #include <decaf/util/LinkedList.h> 00025 #include <decaf/lang/ArrayPointer.h> 00026 #include <decaf/util/concurrent/Mutex.h> 00027 00028 namespace activemq { 00029 namespace core { 00030 00031 using decaf::lang::ArrayPointer; 00032 00033 class AMQCPP_API SimplePriorityMessageDispatchChannel : public MessageDispatchChannel { 00034 private: 00035 00036 static const int MAX_PRIORITIES; 00037 00038 bool closed; 00039 bool running; 00040 00041 mutable decaf::util::concurrent::Mutex mutex; 00042 00043 mutable ArrayPointer< decaf::util::LinkedList< Pointer<MessageDispatch> > > channels; 00044 00045 int enqueued; 00046 00047 private: 00048 00049 SimplePriorityMessageDispatchChannel(const SimplePriorityMessageDispatchChannel&); 00050 SimplePriorityMessageDispatchChannel& operator=(const SimplePriorityMessageDispatchChannel&); 00051 00052 public: 00053 00054 SimplePriorityMessageDispatchChannel(); 00055 virtual ~SimplePriorityMessageDispatchChannel(); 00056 00057 virtual void enqueue(const Pointer<MessageDispatch>& message); 00058 00059 virtual void enqueueFirst(const Pointer<MessageDispatch>& message); 00060 00061 virtual bool isEmpty() const; 00062 00063 virtual bool isClosed() const { 00064 return this->closed; 00065 } 00066 00067 virtual bool isRunning() const { 00068 return this->running; 00069 } 00070 00071 virtual Pointer<MessageDispatch> dequeue(long long timeout); 00072 00073 virtual Pointer<MessageDispatch> dequeueNoWait(); 00074 00075 virtual Pointer<MessageDispatch> peek() const; 00076 00077 virtual void start(); 00078 00079 virtual void stop(); 00080 00081 virtual void close(); 00082 00083 virtual void clear(); 00084 00085 virtual int size() const; 00086 00087 virtual std::vector<Pointer<MessageDispatch> > removeAll(); 00088 00089 public: 00090 00091 virtual void lock() { 00092 mutex.lock(); 00093 } 00094 00095 virtual bool tryLock() { 00096 return mutex.tryLock(); 00097 } 00098 00099 virtual void unlock() { 00100 mutex.unlock(); 00101 } 00102 00103 virtual void wait() { 00104 mutex.wait(); 00105 } 00106 00107 virtual void wait(long long millisecs) { 00108 mutex.wait(millisecs); 00109 } 00110 00111 virtual void wait(long long millisecs, int nanos) { 00112 mutex.wait(millisecs, nanos); 00113 } 00114 00115 virtual void notify() { 00116 mutex.notify(); 00117 } 00118 00119 virtual void notifyAll() { 00120 mutex.notifyAll(); 00121 } 00122 00123 private: 00124 00125 decaf::util::LinkedList<Pointer<MessageDispatch> >& getChannel(const Pointer<MessageDispatch>& dispatch); 00126 00127 Pointer<MessageDispatch> removeFirst(); 00128 00129 Pointer<MessageDispatch> getFirst() const; 00130 00131 }; 00132 00133 }} 00134 00135 #endif /* _ACTIVEMQ_CORE_SIMPLEPRIORITYMESSAGEDISPATCHCHANNEL_H_ */
1.6.1