|
activemq-cpp-3.3.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 #ifndef _ACTIVEMQ_CORE_ACTIVEMQPRODUCER_H_ 00018 #define _ACTIVEMQ_CORE_ACTIVEMQPRODUCER_H_ 00019 00020 #include <cms/MessageProducer.h> 00021 #include <cms/Message.h> 00022 #include <cms/Destination.h> 00023 #include <cms/DeliveryMode.h> 00024 00025 #include <activemq/util/Config.h> 00026 #include <activemq/util/MemoryUsage.h> 00027 #include <activemq/commands/ProducerInfo.h> 00028 #include <activemq/commands/ProducerAck.h> 00029 #include <activemq/exceptions/ActiveMQException.h> 00030 00031 #include <memory> 00032 00033 namespace activemq{ 00034 namespace core{ 00035 00036 using decaf::lang::Pointer; 00037 00038 class ActiveMQSession; 00039 00040 class AMQCPP_API ActiveMQProducer : public cms::MessageProducer { 00041 private: 00042 00043 // Disable sending timestamps 00044 bool disableTimestamps; 00045 00046 // Disable adding a Message Id 00047 bool disableMessageId; 00048 00049 // The default delivery Mode of this Producer 00050 int defaultDeliveryMode; 00051 00052 // The default priority Level to send at 00053 int defaultPriority; 00054 00055 // The default time to live value for messages in milliseconds 00056 long long defaultTimeToLive; 00057 00058 // The default Send Timeout for this Producer. 00059 long long sendTimeout; 00060 00061 // Session that this producer sends to. 00062 ActiveMQSession* session; 00063 00064 // This Producers protocol specific info object 00065 Pointer<commands::ProducerInfo> producerInfo; 00066 00067 // Boolean that indicates if the consumer has been closed 00068 bool closed; 00069 00070 // Memory Usage Class, created only if the Producer is tracking its usage. 00071 std::auto_ptr<util::MemoryUsage> memoryUsage; 00072 00073 // The Destination assigned at creation, NULL if not assigned. 00074 Pointer<cms::Destination> destination; 00075 00076 private: 00077 00078 ActiveMQProducer( const ActiveMQProducer& ); 00079 ActiveMQProducer& operator= ( const ActiveMQProducer& ); 00080 00081 public: 00082 00096 ActiveMQProducer( ActiveMQSession* session, 00097 const Pointer<commands::ProducerId>& producerId, 00098 const Pointer<commands::ActiveMQDestination>& destination, 00099 long long sendTimeout ); 00100 00101 virtual ~ActiveMQProducer() throw(); 00102 00103 public: // cms::MessageProducer methods. 00104 00105 virtual void close(); 00106 00107 virtual void send( cms::Message* message ); 00108 00109 virtual void send( cms::Message* message, int deliveryMode, int priority, long long timeToLive ); 00110 00111 virtual void send( const cms::Destination* destination, cms::Message* message ); 00112 00113 virtual void send( const cms::Destination* destination, cms::Message* message, 00114 int deliveryMode, int priority, long long timeToLive ); 00115 00120 virtual void setDeliveryMode( int mode ) { 00121 this->defaultDeliveryMode = mode; 00122 } 00123 00128 virtual int getDeliveryMode() const { 00129 return this->defaultDeliveryMode; 00130 } 00131 00136 virtual void setDisableMessageID( bool value ) { 00137 this->disableMessageId = value; 00138 } 00139 00144 virtual bool getDisableMessageID() const { 00145 return this->disableMessageId; 00146 } 00147 00152 virtual void setDisableMessageTimeStamp( bool value ) { 00153 this->disableTimestamps = value; 00154 } 00155 00160 virtual bool getDisableMessageTimeStamp() const { 00161 return this->disableTimestamps; 00162 } 00163 00168 virtual void setPriority( int priority ) { 00169 this->defaultPriority = priority; 00170 } 00171 00176 virtual int getPriority() const { 00177 return this->defaultPriority; 00178 } 00179 00184 virtual void setTimeToLive( long long time ) { 00185 this->defaultTimeToLive = time; 00186 } 00187 00192 virtual long long getTimeToLive() const { 00193 return this->defaultTimeToLive; 00194 } 00195 00200 virtual void setSendTimeout( long long time ) { 00201 this->sendTimeout = time; 00202 } 00203 00208 virtual long long getSendTimeout() const { 00209 return this->sendTimeout; 00210 } 00211 00212 public: 00213 00217 bool isClosed() const { 00218 return this->closed; 00219 } 00220 00225 const Pointer<commands::ProducerInfo>& getProducerInfo() const { 00226 this->checkClosed(); 00227 return this->producerInfo; 00228 } 00229 00234 const Pointer<commands::ProducerId>& getProducerId() const { 00235 this->checkClosed(); 00236 return this->producerInfo->getProducerId(); 00237 } 00238 00243 virtual void onProducerAck( const commands::ProducerAck& ack ); 00244 00251 void dispose(); 00252 00253 private: 00254 00255 // Checks for the closed state and throws if so. 00256 void checkClosed() const; 00257 00258 }; 00259 00260 }} 00261 00262 #endif /*_ACTIVEMQ_CORE_ACTIVEMQPRODUCER_H_*/