activemq-cpp-3.4.0

src/main/activemq/core/ActiveMQQueueBrowser.h

Go to the documentation of this file.
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_ACTIVEMQQUEUEBROWSER_H_
00019 #define _ACTIVEMQ_CORE_ACTIVEMQQUEUEBROWSER_H_
00020 
00021 #include <activemq/util/Config.h>
00022 
00023 #include <cms/Queue.h>
00024 #include <cms/QueueBrowser.h>
00025 #include <cms/MessageEnumeration.h>
00026 #include <activemq/commands/ConsumerId.h>
00027 #include <activemq/commands/ActiveMQDestination.h>
00028 #include <decaf/lang/Pointer.h>
00029 #include <decaf/util/concurrent/Mutex.h>
00030 #include <decaf/util/concurrent/atomic/AtomicBoolean.h>
00031 
00032 #include <string>
00033 
00034 namespace activemq {
00035 namespace core {
00036 
00037     class ActiveMQConsumer;
00038     class ActiveMQSession;
00039     class Browser;
00040 
00041     using decaf::lang::Pointer;
00042 
00043     class AMQCPP_API ActiveMQQueueBrowser : public cms::QueueBrowser,
00044                                             public cms::MessageEnumeration {
00045     private:
00046 
00047         friend class Browser;
00048 
00049         ActiveMQSession* session;
00050         Pointer<commands::ConsumerId> consumerId;
00051         Pointer<commands::ActiveMQDestination> destination;
00052         std::string selector;
00053         bool dispatchAsync;
00054         cms::Queue* queue;
00055         volatile bool closed;
00056 
00057         mutable decaf::util::concurrent::Mutex mutex;
00058         mutable decaf::util::concurrent::Mutex wait;
00059         decaf::util::concurrent::atomic::AtomicBoolean browseDone;
00060 
00061         mutable ActiveMQConsumer* browser;
00062 
00063     private:
00064 
00065         ActiveMQQueueBrowser( const ActiveMQQueueBrowser& );
00066         ActiveMQQueueBrowser& operator= ( const ActiveMQQueueBrowser& );
00067 
00068     public:
00069 
00070         ActiveMQQueueBrowser( ActiveMQSession* session,
00071                               const Pointer<commands::ConsumerId>& consumerId,
00072                               const Pointer<commands::ActiveMQDestination>& destination,
00073                               const std::string& selector,
00074                               bool dispatchAsync );
00075 
00076         virtual ~ActiveMQQueueBrowser() throw();
00077 
00078     public:
00079 
00080         virtual const cms::Queue* getQueue() const;
00081 
00082         virtual std::string getMessageSelector() const;
00083 
00084         virtual cms::MessageEnumeration* getEnumeration();
00085 
00086         virtual void close();
00087 
00088         virtual bool hasMoreMessages();
00089 
00090         virtual cms::Message* nextMessage();
00091 
00092     private:
00093 
00094         void checkClosed();
00095         void notifyMessageAvailable();
00096         void waitForMessageAvailable();
00097 
00098         ActiveMQConsumer* createConsumer();
00099         void destroyConsumer();
00100 
00101     };
00102 
00103 }}
00104 
00105 #endif /* _ACTIVEMQ_CORE_ACTIVEMQQUEUEBROWSER_H_ */