|
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_CONNECTIONSTATETRACKER_H_ 00019 #define _ACTIVEMQ_STATE_CONNECTIONSTATETRACKER_H_ 00020 00021 #include <activemq/util/Config.h> 00022 #include <activemq/commands/ConnectionId.h> 00023 #include <activemq/exceptions/ActiveMQException.h> 00024 #include <activemq/state/CommandVisitorAdapter.h> 00025 #include <activemq/state/ConnectionState.h> 00026 #include <activemq/state/ConsumerState.h> 00027 #include <activemq/state/ProducerState.h> 00028 #include <activemq/state/SessionState.h> 00029 #include <activemq/state/TransactionState.h> 00030 #include <activemq/state/Tracked.h> 00031 #include <activemq/transport/Transport.h> 00032 00033 #include <decaf/util/concurrent/ConcurrentStlMap.h> 00034 #include <decaf/lang/Pointer.h> 00035 00036 namespace activemq { 00037 namespace state { 00038 00039 class RemoveTransactionAction; 00040 using decaf::lang::Pointer; 00041 using decaf::util::concurrent::ConcurrentStlMap; 00042 00043 class AMQCPP_API ConnectionStateTracker : public CommandVisitorAdapter { 00044 private: 00045 00047 const Pointer<Tracked> TRACKED_RESPONSE_MARKER; 00048 00050 ConcurrentStlMap< Pointer<ConnectionId>, Pointer<ConnectionState>, 00051 ConnectionId::COMPARATOR > connectionStates; 00052 00053 // TODO - The Map doesn't have a way to automatically remove the eldest Entry 00054 // Either we need to implement something similar to LinkedHashMap or find 00055 // some other way of tracking the eldest entry into the map and removing it 00056 // if the cache size is exceeded. 00057 ConcurrentStlMap< Pointer<MessageId>, Pointer<Message>, 00058 MessageId::COMPARATOR > messageCache; 00059 00060 bool trackTransactions; 00061 bool restoreSessions; 00062 bool restoreConsumers; 00063 bool restoreProducers; 00064 bool restoreTransaction; 00065 bool trackMessages; 00066 bool trackTransactionProducers; 00067 int maxCacheSize; 00068 int currentCacheSize; 00069 00070 friend class RemoveTransactionAction; 00071 00072 public: 00073 00074 ConnectionStateTracker(); 00075 00076 virtual ~ConnectionStateTracker(); 00077 00078 Pointer<Tracked> track( const Pointer<Command>& command ); 00079 00080 void trackBack( const Pointer<Command>& command ); 00081 00082 void restore( const Pointer<transport::Transport>& transport ); 00083 00084 void connectionInterruptProcessingComplete( 00085 transport::Transport* transport, const Pointer<ConnectionId>& connectionId ); 00086 00087 void transportInterrupted(); 00088 00089 virtual Pointer<Command> processDestinationInfo( DestinationInfo* info ); 00090 00091 virtual Pointer<Command> processRemoveDestination( DestinationInfo* info ); 00092 00093 virtual Pointer<Command> processProducerInfo( ProducerInfo* info ); 00094 00095 virtual Pointer<Command> processRemoveProducer( ProducerId* id ); 00096 00097 virtual Pointer<Command> processConsumerInfo( ConsumerInfo* info ); 00098 00099 virtual Pointer<Command> processRemoveConsumer( ConsumerId* id ); 00100 00101 virtual Pointer<Command> processSessionInfo( SessionInfo* info ); 00102 00103 virtual Pointer<Command> processRemoveSession( SessionId* id ); 00104 00105 virtual Pointer<Command> processConnectionInfo( ConnectionInfo* info ); 00106 00107 virtual Pointer<Command> processRemoveConnection( ConnectionId* id ); 00108 00109 virtual Pointer<Command> processMessage( Message* message ); 00110 00111 virtual Pointer<Command> processMessageAck( MessageAck* ack ); 00112 00113 virtual Pointer<Command> processBeginTransaction( TransactionInfo* info ); 00114 00115 virtual Pointer<Command> processPrepareTransaction( TransactionInfo* info ); 00116 00117 virtual Pointer<Command> processCommitTransactionOnePhase( TransactionInfo* info ); 00118 00119 virtual Pointer<Command> processCommitTransactionTwoPhase( TransactionInfo* info ); 00120 00121 virtual Pointer<Command> processRollbackTransaction( TransactionInfo* info ); 00122 00123 virtual Pointer<Command> processEndTransaction( TransactionInfo* info ); 00124 00125 bool isRestoreConsumers() const { 00126 return this->restoreConsumers; 00127 } 00128 00129 void setRestoreConsumers( bool restoreConsumers ) { 00130 this->restoreConsumers = restoreConsumers; 00131 } 00132 00133 bool isRestoreProducers() const { 00134 return this->restoreProducers; 00135 } 00136 00137 void setRestoreProducers( bool restoreProducers ) { 00138 this->restoreProducers = restoreProducers; 00139 } 00140 00141 bool isRestoreSessions() const { 00142 return this->restoreSessions; 00143 } 00144 00145 void setRestoreSessions( bool restoreSessions ) { 00146 this->restoreSessions = restoreSessions; 00147 } 00148 00149 bool isTrackTransactions() const { 00150 return this->trackTransactions; 00151 } 00152 00153 void setTrackTransactions( bool trackTransactions ) { 00154 this->trackTransactions = trackTransactions; 00155 } 00156 00157 bool isRestoreTransaction() const { 00158 return this->restoreTransaction; 00159 } 00160 00161 void setRestoreTransaction( bool restoreTransaction ) { 00162 this->restoreTransaction = restoreTransaction; 00163 } 00164 00165 bool isTrackMessages() const { 00166 return this->trackMessages; 00167 } 00168 00169 void setTrackMessages( bool trackMessages ) { 00170 this->trackMessages = trackMessages; 00171 } 00172 00173 int getMaxCacheSize() const { 00174 return this->maxCacheSize; 00175 } 00176 00177 void setMaxCacheSize( int maxCacheSize ) { 00178 this->maxCacheSize = maxCacheSize; 00179 } 00180 00181 bool isTrackTransactionProducers() const { 00182 return this->trackTransactionProducers; 00183 } 00184 00185 void setTrackTransactionProducers( bool trackTransactionProducers ) { 00186 this->trackTransactionProducers = trackTransactionProducers; 00187 } 00188 00189 private: 00190 00191 void doRestoreTransactions( const Pointer<transport::Transport>& transport, 00192 const Pointer<ConnectionState>& connectionState ); 00193 00194 void doRestoreSessions( const Pointer<transport::Transport>& transport, 00195 const Pointer<ConnectionState>& connectionState ); 00196 00197 void doRestoreConsumers( const Pointer<transport::Transport>& transport, 00198 const Pointer<SessionState>& sessionState ); 00199 00200 void doRestoreProducers( const Pointer<transport::Transport>& transport, 00201 const Pointer<SessionState>& sessionState ); 00202 00203 void doRestoreTempDestinations( const Pointer<transport::Transport>& transport, 00204 const Pointer<ConnectionState>& connectionState ); 00205 00206 }; 00207 00208 }} 00209 00210 #endif /*_ACTIVEMQ_STATE_CONNECTIONSTATETRACKER_H_*/