|
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 _ACTIVEMQ_STATE_CONNECTIONSTATE_H_ 00019 #define _ACTIVEMQ_STATE_CONNECTIONSTATE_H_ 00020 00021 #include <activemq/util/Config.h> 00022 #include <activemq/commands/ConnectionInfo.h> 00023 #include <activemq/commands/DestinationInfo.h> 00024 #include <activemq/commands/SessionInfo.h> 00025 #include <activemq/commands/ConsumerId.h> 00026 #include <activemq/commands/ProducerId.h> 00027 #include <activemq/commands/TransactionId.h> 00028 #include <activemq/commands/LocalTransactionId.h> 00029 #include <activemq/state/ConsumerState.h> 00030 #include <activemq/state/ProducerState.h> 00031 #include <activemq/state/SessionState.h> 00032 #include <activemq/state/TransactionState.h> 00033 00034 #include <decaf/util/StlMap.h> 00035 #include <decaf/util/concurrent/atomic/AtomicBoolean.h> 00036 #include <decaf/util/concurrent/ConcurrentStlMap.h> 00037 #include <decaf/util/LinkedList.h> 00038 #include <decaf/lang/Pointer.h> 00039 00040 #include <string> 00041 #include <memory> 00042 00043 namespace activemq { 00044 namespace state { 00045 00046 using decaf::lang::Pointer; 00047 using namespace decaf::util; 00048 using namespace activemq::commands; 00049 00050 class AMQCPP_API ConnectionState { 00051 private: 00052 00053 Pointer< ConnectionInfo > info; 00054 ConcurrentStlMap< Pointer<LocalTransactionId>, 00055 Pointer<TransactionState>, 00056 LocalTransactionId::COMPARATOR > transactions; 00057 ConcurrentStlMap< Pointer<SessionId>, 00058 Pointer<SessionState>, 00059 SessionId::COMPARATOR > sessions; 00060 LinkedList< Pointer<DestinationInfo> > tempDestinations; 00061 decaf::util::concurrent::atomic::AtomicBoolean disposed; 00062 00063 bool connectionInterruptProcessingComplete; 00064 StlMap< Pointer<ConsumerId>, 00065 Pointer<ConsumerInfo>, 00066 ConsumerId::COMPARATOR > recoveringPullConsumers; 00067 00068 public: 00069 00070 ConnectionState( const Pointer<ConnectionInfo>& info ); 00071 00072 virtual ~ConnectionState(); 00073 00074 std::string toString() const; 00075 00076 const Pointer<commands::ConnectionInfo>& getInfo() const { 00077 return this->info; 00078 } 00079 00080 void checkShutdown() const; 00081 00082 void shutdown(); 00083 00084 void reset( const Pointer<ConnectionInfo>& info ); 00085 00086 void addTempDestination( const Pointer<DestinationInfo>& info ) { 00087 checkShutdown(); 00088 tempDestinations.add( info ); 00089 } 00090 00091 void removeTempDestination( const Pointer<ActiveMQDestination>& destination ) { 00092 00093 std::auto_ptr< decaf::util::Iterator< Pointer<DestinationInfo> > > iter( 00094 tempDestinations.iterator() ); 00095 00096 while( iter->hasNext() ) { 00097 Pointer<DestinationInfo> di = iter->next(); 00098 if( di->getDestination()->equals( destination.get() ) ) { 00099 iter->remove(); 00100 } 00101 } 00102 } 00103 00104 void addTransactionState( const Pointer<TransactionId>& id ) { 00105 checkShutdown(); 00106 transactions.put( id.dynamicCast<LocalTransactionId>(), 00107 Pointer<TransactionState>( new TransactionState( id ) ) ); 00108 } 00109 00110 const Pointer<TransactionState>& getTransactionState( const Pointer<TransactionId>& id ) const { 00111 return transactions.get( id.dynamicCast<LocalTransactionId>() ); 00112 } 00113 00114 std::vector< Pointer<TransactionState> > getTransactionStates() const { 00115 return transactions.values(); 00116 } 00117 00118 Pointer<TransactionState> removeTransactionState( const Pointer<TransactionId>& id ) { 00119 return transactions.remove( id.dynamicCast<LocalTransactionId>() ); 00120 } 00121 00122 void addSession( const Pointer<SessionInfo>& info ) { 00123 checkShutdown(); 00124 sessions.put( 00125 info->getSessionId(), Pointer<SessionState>( new SessionState( info ) ) ); 00126 } 00127 00128 Pointer<SessionState> removeSession( const Pointer<SessionId>& id ) { 00129 return sessions.remove( id ); 00130 } 00131 00132 const Pointer<SessionState>& getSessionState( const Pointer<SessionId>& id ) const { 00133 return sessions.get( id ); 00134 } 00135 00136 const LinkedList< Pointer<DestinationInfo> >& getTempDesinations() const { 00137 return tempDestinations; 00138 } 00139 00140 std::vector< Pointer<SessionState> > getSessionStates() const { 00141 return sessions.values(); 00142 } 00143 00144 StlMap< Pointer<ConsumerId>, Pointer<ConsumerInfo>, ConsumerId::COMPARATOR >& getRecoveringPullConsumers() { 00145 return recoveringPullConsumers; 00146 } 00147 00148 void setConnectionInterruptProcessingComplete( bool connectionInterruptProcessingComplete ) { 00149 this->connectionInterruptProcessingComplete = connectionInterruptProcessingComplete; 00150 } 00151 00152 bool isConnectionInterruptProcessingComplete() { 00153 return this->connectionInterruptProcessingComplete; 00154 } 00155 00156 }; 00157 00158 }} 00159 00160 #endif /*_ACTIVEMQ_STATE_CONNECTIONSTATE_H_*/