activemq-cpp-3.3.0

src/main/activemq/core/ActiveMQTransactionContext.h

Go to the documentation of this file.
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 
00041     using decaf::lang::Pointer;
00042 
00043     class LocalTransactionEventListener;
00044     class ActiveMQSession;
00045     class ActiveMQConnection;
00046     class TxContextData;
00047 
00057     class AMQCPP_API ActiveMQTransactionContext : public cms::XAResource {
00058     private:
00059 
00060         // Internal structure to hold all class TX data.
00061         TxContextData* context;
00062 
00063         // Session this Transaction is associated with
00064         ActiveMQSession* session;
00065 
00066         // The Connection that is the parent of the Session.
00067         ActiveMQConnection* connection;
00068 
00069         // List of Registered Synchronizations
00070         decaf::util::StlSet< Pointer<Synchronization> > synchronizations;
00071 
00072     private:
00073 
00074         ActiveMQTransactionContext( const ActiveMQTransactionContext& );
00075         ActiveMQTransactionContext& operator= ( const ActiveMQTransactionContext& );
00076 
00077     public:
00078 
00087         ActiveMQTransactionContext( ActiveMQSession* session,
00088                                     const decaf::util::Properties& properties );
00089 
00090         virtual ~ActiveMQTransactionContext();
00091 
00096         virtual void addSynchronization( const Pointer<Synchronization>& sync );
00097 
00102         virtual void removeSynchronization( const Pointer<Synchronization>& sync );
00103 
00108         virtual void begin();
00109 
00114         virtual void commit();
00115 
00120         virtual void rollback();
00121 
00128         virtual const decaf::lang::Pointer<commands::TransactionId>& getTransactionId() const;
00129 
00136         virtual bool isInTransaction() const;
00137 
00144         virtual bool isInLocalTransaction() const;
00145 
00152         virtual bool isInXATransaction() const;
00153 
00154     public:  // XAResource implementation.
00155 
00156         virtual void commit( const cms::Xid* xid, bool onePhase );
00157 
00158         virtual void end( const cms::Xid* xid, int flags );
00159 
00160         virtual void forget( const cms::Xid* xid );
00161 
00162         virtual int getTransactionTimeout() const;
00163 
00164         virtual bool isSameRM( const cms::XAResource* theXAResource );
00165 
00166         virtual int prepare( const cms::Xid* xid );
00167 
00168         virtual int recover(int flag, cms::Xid** recovered );
00169 
00170         virtual void rollback( const cms::Xid* xid );
00171 
00172         virtual bool setTransactionTimeout( int seconds );
00173 
00174         virtual void start( const cms::Xid* xid, int flags );
00175 
00176     private:
00177 
00178         std::string getResourceManagerId() const;
00179         void setXid( const cms::Xid* xid );
00180         bool equals( const cms::Xid* local, const cms::Xid* remote );
00181         cms::XAException toXAException( cms::CMSException& ex );
00182         cms::XAException toXAException( decaf::lang::Exception& ex );
00183 
00184         void beforeEnd();
00185         void afterCommit();
00186         void afterRollback();
00187 
00188     };
00189 
00190 }}
00191 
00192 #endif /*_ACTIVEMQ_CORE_ACTIVEMQTRANSACTIONCONTEXT_H_*/