|
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 00018 #ifndef _ACTIVEMQ_CORE_ACTIVEMQCONNECTION_H_ 00019 #define _ACTIVEMQ_CORE_ACTIVEMQCONNECTION_H_ 00020 00021 #include <cms/Connection.h> 00022 #include <activemq/util/Config.h> 00023 #include <activemq/core/ActiveMQConnectionMetaData.h> 00024 #include <activemq/core/Dispatcher.h> 00025 #include <activemq/commands/ActiveMQTempDestination.h> 00026 #include <activemq/commands/ConnectionInfo.h> 00027 #include <activemq/commands/ConsumerInfo.h> 00028 #include <activemq/commands/SessionId.h> 00029 #include <activemq/exceptions/ActiveMQException.h> 00030 #include <activemq/transport/Transport.h> 00031 #include <activemq/transport/TransportListener.h> 00032 #include <activemq/threads/Scheduler.h> 00033 #include <decaf/util/Properties.h> 00034 #include <decaf/util/concurrent/atomic/AtomicBoolean.h> 00035 #include <decaf/util/concurrent/CopyOnWriteArrayList.h> 00036 #include <decaf/lang/exceptions/UnsupportedOperationException.h> 00037 #include <decaf/lang/exceptions/NullPointerException.h> 00038 #include <decaf/lang/exceptions/IllegalStateException.h> 00039 00040 #include <string> 00041 #include <memory> 00042 00043 namespace activemq{ 00044 namespace core{ 00045 00046 using decaf::lang::Pointer; 00047 using decaf::util::concurrent::atomic::AtomicBoolean; 00048 00049 class ActiveMQSession; 00050 class ActiveMQProducer; 00051 class ConnectionConfig; 00052 class PrefetchPolicy; 00053 class RedeliveryPolicy; 00054 00061 class AMQCPP_API ActiveMQConnection : public virtual cms::Connection, 00062 public transport::TransportListener { 00063 private: 00064 00065 ConnectionConfig* config; 00066 00070 std::auto_ptr<cms::ConnectionMetaData> connectionMetaData; 00071 00075 AtomicBoolean started; 00076 00081 AtomicBoolean closed; 00082 00087 AtomicBoolean closing; 00088 00092 AtomicBoolean transportFailed; 00093 00094 private: 00095 00096 ActiveMQConnection( const ActiveMQConnection& ); 00097 ActiveMQConnection& operator= ( const ActiveMQConnection& ); 00098 00099 public: 00100 00109 ActiveMQConnection( const Pointer<transport::Transport>& transport, 00110 const Pointer<decaf::util::Properties>& properties ); 00111 00112 virtual ~ActiveMQConnection() throw(); 00113 00122 virtual void addSession( ActiveMQSession* session ); 00123 00132 virtual void removeSession( ActiveMQSession* session ); 00133 00142 virtual void addProducer( ActiveMQProducer* producer ); 00143 00149 virtual void removeProducer( const Pointer<commands::ProducerId>& producerId ); 00150 00157 virtual void addDispatcher( const Pointer<commands::ConsumerId>& consumer, Dispatcher* dispatcher ); 00158 00164 virtual void removeDispatcher( const Pointer<commands::ConsumerId>& consumer ); 00165 00176 virtual void sendPullRequest( const commands::ConsumerInfo* consumer, long long timeout ); 00177 00182 bool isClosed() const { 00183 return this->closed.get(); 00184 } 00185 00190 bool isStarted() const { 00191 return this->started.get(); 00192 } 00193 00198 bool isTransportFailed() const { 00199 return this->transportFailed.get(); 00200 } 00201 00220 virtual void destroyDestination( const commands::ActiveMQDestination* destination ); 00221 00240 virtual void destroyDestination( const cms::Destination* destination ); 00241 00242 public: // Connection Interface Methods 00243 00247 virtual const cms::ConnectionMetaData* getMetaData() const { 00248 return connectionMetaData.get(); 00249 } 00250 00254 virtual cms::Session* createSession(); 00255 00259 virtual std::string getClientID() const; 00260 00264 virtual void setClientID( const std::string& clientID ); 00265 00269 virtual cms::Session* createSession( cms::Session::AcknowledgeMode ackMode ); 00270 00274 virtual void close(); 00275 00279 virtual void start(); 00280 00284 virtual void stop(); 00285 00289 virtual cms::ExceptionListener* getExceptionListener() const; 00290 00294 virtual void setExceptionListener( cms::ExceptionListener* listener ); 00295 00296 public: // Configuration Options 00297 00302 void setUsername( const std::string& username ); 00303 00309 const std::string& getUsername() const; 00310 00315 void setPassword( const std::string& password ); 00316 00322 const std::string& getPassword() const; 00323 00328 void setDefaultClientId( const std::string& clientId ); 00329 00335 void setBrokerURL( const std::string& brokerURL ); 00336 00342 const std::string& getBrokerURL() const; 00343 00352 void setPrefetchPolicy( PrefetchPolicy* policy ); 00353 00359 PrefetchPolicy* getPrefetchPolicy() const; 00360 00369 void setRedeliveryPolicy( RedeliveryPolicy* policy ); 00370 00376 RedeliveryPolicy* getRedeliveryPolicy() const; 00377 00381 bool isDispatchAsync() const; 00382 00391 void setDispatchAsync( bool value ); 00392 00398 bool isAlwaysSyncSend() const; 00399 00405 void setAlwaysSyncSend( bool value ); 00406 00411 bool isUseAsyncSend() const; 00412 00417 void setUseAsyncSend( bool value ); 00418 00423 bool isUseCompression() const; 00424 00431 void setUseCompression( bool value ); 00432 00442 void setCompressionLevel( int value ); 00443 00449 int getCompressionLevel() const; 00450 00455 unsigned int getSendTimeout() const; 00456 00462 void setSendTimeout( unsigned int timeout ); 00463 00468 unsigned int getCloseTimeout() const; 00469 00474 void setCloseTimeout( unsigned int timeout ); 00475 00483 unsigned int getProducerWindowSize() const; 00484 00491 void setProducerWindowSize( unsigned int windowSize ); 00492 00497 bool isMessagePrioritySupported() const; 00498 00506 void setMessagePrioritySupported( bool value ); 00507 00512 long long getNextTempDestinationId(); 00513 00518 long long getNextLocalTransactionId(); 00519 00520 public: // TransportListener 00521 00533 void addTransportListener( transport::TransportListener* transportListener ); 00534 00543 void removeTransportListener( transport::TransportListener* transportListener ); 00544 00550 virtual void onCommand( const Pointer<commands::Command>& command ); 00551 00556 virtual void onException( const decaf::lang::Exception& ex ); 00557 00561 virtual void transportInterrupted(); 00562 00566 virtual void transportResumed(); 00567 00568 public: 00569 00576 const commands::ConnectionInfo& getConnectionInfo() const; 00577 00584 const commands::ConnectionId& getConnectionId() const; 00585 00591 transport::Transport& getTransport() const; 00592 00598 Pointer<threads::Scheduler> getScheduler() const; 00599 00606 std::string getResourceManagerId() const; 00607 00612 void cleanup(); 00613 00624 void oneway( Pointer<commands::Command> command ); 00625 00640 Pointer<commands::Response> syncRequest( Pointer<commands::Command> command, unsigned int timeout = 0 ); 00641 00646 virtual void fire( const exceptions::ActiveMQException& ex ); 00647 00652 void setTransportInterruptionProcessingComplete(); 00653 00659 decaf::lang::Exception* getFirstFailureError() const; 00660 00667 void onAsyncException( const decaf::lang::Exception& ex ); 00668 00674 void checkClosed() const; 00675 00681 void checkClosedOrFailed() const; 00682 00686 void ensureConnectionInfoSent(); 00687 00688 protected: 00689 00693 virtual Pointer<commands::SessionId> getNextSessionId(); 00694 00695 // Sends a oneway disconnect message to the broker. 00696 void disconnect( long long lastDeliveredSequenceId ); 00697 00698 // Waits for all Consumers to handle the Transport Interrupted event. 00699 void waitForTransportInterruptionProcessingToComplete(); 00700 00701 // Marks processing complete for a single caller when interruption processing completes. 00702 void signalInterruptionProcessingComplete(); 00703 00704 // Allow subclasses to access the original Properties object for this connection. 00705 const decaf::util::Properties& getProperties() const; 00706 00707 }; 00708 00709 }} 00710 00711 #endif /*_ACTIVEMQ_CORE_ACTIVEMQCONNECTION_H_*/