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_ACTIVEMQTRANSACTIONCONTEXT_H_ 00018 #define _ACTIVEMQ_CORE_ACTIVEMQTRANSACTIONCONTEXT_H_ 00019 00020 #include <memory> 00021 00022 #include <cms/Message.h> 00023 #include <cms/XAResource.h> 00024 #include <cms/CMSException.h> 00025 #include <cms/XAException.h> 00026 00027 #include <activemq/util/Config.h> 00028 #include <activemq/exceptions/ActiveMQException.h> 00029 #include <activemq/commands/LocalTransactionId.h> 00030 #include <activemq/core/Synchronization.h> 00031 #include <activemq/util/LongSequenceGenerator.h> 00032 00033 #include <decaf/lang/exceptions/InvalidStateException.h> 00034 #include <decaf/util/StlSet.h> 00035 #include <decaf/util/Properties.h> 00036 #include <decaf/util/concurrent/Mutex.h> 00037 00038 namespace activemq { 00039 namespace core { 00040 namespace kernels { 00041 class ActiveMQSessionKernel; 00042 } 00043 00044 using decaf::lang::Pointer; 00045 00046 class LocalTransactionEventListener; 00047 class ActiveMQConnection; 00048 class TxContextData; 00049 00059 class AMQCPP_API ActiveMQTransactionContext : public cms::XAResource { 00060 private: 00061 00062 // Internal structure to hold all class TX data. 00063 TxContextData* context; 00064 00065 // Session this Transaction is associated with 00066 activemq::core::kernels::ActiveMQSessionKernel* session; 00067 00068 // The Connection that is the parent of the Session. 00069 ActiveMQConnection* connection; 00070 00071 // List of Registered Synchronizations 00072 decaf::util::StlSet< Pointer<Synchronization> > synchronizations; 00073 00074 private: 00075 00076 ActiveMQTransactionContext(const ActiveMQTransactionContext&); 00077 ActiveMQTransactionContext& operator=(const ActiveMQTransactionContext&); 00078 00079 public: 00080 00089 ActiveMQTransactionContext(activemq::core::kernels::ActiveMQSessionKernel* session, 00090 const decaf::util::Properties& properties); 00091 00092 virtual ~ActiveMQTransactionContext(); 00093 00098 virtual void addSynchronization(const Pointer<Synchronization>& sync); 00099 00104 virtual void removeSynchronization(const Pointer<Synchronization>& sync); 00105 00110 virtual void begin(); 00111 00116 virtual void commit(); 00117 00122 virtual void rollback(); 00123 00130 virtual const decaf::lang::Pointer<commands::TransactionId>& getTransactionId() const; 00131 00138 virtual bool isInTransaction() const; 00139 00146 virtual bool isInLocalTransaction() const; 00147 00154 virtual bool isInXATransaction() const; 00155 00156 public: // XAResource implementation. 00157 00158 virtual void commit(const cms::Xid* xid, bool onePhase); 00159 00160 virtual void end(const cms::Xid* xid, int flags); 00161 00162 virtual void forget(const cms::Xid* xid); 00163 00164 virtual int getTransactionTimeout() const; 00165 00166 virtual bool isSameRM(const cms::XAResource* theXAResource); 00167 00168 virtual int prepare(const cms::Xid* xid); 00169 00170 virtual int recover(int flag, cms::Xid** recovered); 00171 00172 virtual void rollback(const cms::Xid* xid); 00173 00174 virtual bool setTransactionTimeout(int seconds); 00175 00176 virtual void start(const cms::Xid* xid, int flags); 00177 00178 private: 00179 00180 std::string getResourceManagerId() const; 00181 void setXid(const cms::Xid* xid); 00182 bool equals(const cms::Xid* local, const cms::Xid* remote); 00183 cms::XAException toXAException(cms::CMSException& ex); 00184 cms::XAException toXAException(decaf::lang::Exception& ex); 00185 00186 void beforeEnd(); 00187 void afterCommit(); 00188 void afterRollback(); 00189 00190 }; 00191 00192 }} 00193 00194 #endif /*_ACTIVEMQ_CORE_ACTIVEMQTRANSACTIONCONTEXT_H_*/
1.6.1