You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2012/05/16 18:02:06 UTC
svn commit: r1339242 [2/2] -
/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/ConnectionStateTracker.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/ConnectionStateTracker.h?rev=1339242&r1=1339241&r2=1339242&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/ConnectionStateTracker.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/ConnectionStateTracker.h Wed May 16 16:02:06 2012
@@ -40,24 +40,22 @@ namespace state {
using decaf::lang::Pointer;
using decaf::util::concurrent::ConcurrentStlMap;
- class AMQCPP_API ConnectionStateTracker : public CommandVisitorAdapter {
+ class AMQCPP_API ConnectionStateTracker: public CommandVisitorAdapter {
private:
/** Creates a unique marker for this state tracker */
const Pointer<Tracked> TRACKED_RESPONSE_MARKER;
/** Map holding the ConnectionStates, indexed by the ConnectionId */
- ConcurrentStlMap< Pointer<ConnectionId>, Pointer<ConnectionState>,
- ConnectionId::COMPARATOR > connectionStates;
+ ConcurrentStlMap<Pointer<ConnectionId>, Pointer<ConnectionState>, ConnectionId::COMPARATOR> connectionStates;
// TODO - The Map doesn't have a way to automatically remove the eldest Entry
// Either we need to implement something similar to LinkedHashMap or find
// some other way of tracking the eldest entry into the map and removing it
// if the cache size is exceeded.
- ConcurrentStlMap< Pointer<MessageId>, Pointer<Command>,
- MessageId::COMPARATOR > messageCache;
+ ConcurrentStlMap<Pointer<MessageId>, Pointer<Command>, MessageId::COMPARATOR> messageCache;
- ConcurrentStlMap< std::string, Pointer<Command> > messagePullCache;
+ ConcurrentStlMap<std::string, Pointer<Command> > messagePullCache;
bool trackTransactions;
bool restoreSessions;
@@ -77,60 +75,58 @@ namespace state {
virtual ~ConnectionStateTracker();
- Pointer<Tracked> track( const Pointer<Command>& command );
+ Pointer<Tracked> track(Pointer<Command> command);
- void trackBack( const Pointer<Command>& command );
+ void trackBack(Pointer<Command> command);
- void restore( const Pointer<transport::Transport>& transport );
+ void restore(Pointer<transport::Transport> transport);
void connectionInterruptProcessingComplete(
- transport::Transport* transport, const Pointer<ConnectionId>& connectionId );
+ transport::Transport* transport, Pointer<ConnectionId> connectionId);
void transportInterrupted();
- virtual Pointer<Command> processDestinationInfo( DestinationInfo* info );
+ virtual Pointer<Command> processDestinationInfo(DestinationInfo* info);
- virtual Pointer<Command> processRemoveDestination( DestinationInfo* info );
+ virtual Pointer<Command> processRemoveDestination(DestinationInfo* info);
- virtual Pointer<Command> processProducerInfo( ProducerInfo* info );
+ virtual Pointer<Command> processProducerInfo(ProducerInfo* info);
- virtual Pointer<Command> processRemoveProducer( ProducerId* id );
+ virtual Pointer<Command> processRemoveProducer(ProducerId* id);
- virtual Pointer<Command> processConsumerInfo( ConsumerInfo* info );
+ virtual Pointer<Command> processConsumerInfo(ConsumerInfo* info);
- virtual Pointer<Command> processRemoveConsumer( ConsumerId* id );
+ virtual Pointer<Command> processRemoveConsumer(ConsumerId* id);
- virtual Pointer<Command> processSessionInfo( SessionInfo* info );
+ virtual Pointer<Command> processSessionInfo(SessionInfo* info);
- virtual Pointer<Command> processRemoveSession( SessionId* id );
+ virtual Pointer<Command> processRemoveSession(SessionId* id);
- virtual Pointer<Command> processConnectionInfo( ConnectionInfo* info );
+ virtual Pointer<Command> processConnectionInfo(ConnectionInfo* info);
- virtual Pointer<Command> processRemoveConnection( ConnectionId* id );
+ virtual Pointer<Command> processRemoveConnection(ConnectionId* id);
- virtual Pointer<Command> processMessage( Message* message );
+ virtual Pointer<Command> processMessage(Message* message);
- virtual Pointer<Command> processMessageAck( MessageAck* ack );
+ virtual Pointer<Command> processBeginTransaction(TransactionInfo* info);
- virtual Pointer<Command> processBeginTransaction( TransactionInfo* info );
+ virtual Pointer<Command> processPrepareTransaction(TransactionInfo* info);
- virtual Pointer<Command> processPrepareTransaction( TransactionInfo* info );
+ virtual Pointer<Command> processCommitTransactionOnePhase(TransactionInfo* info);
- virtual Pointer<Command> processCommitTransactionOnePhase( TransactionInfo* info );
+ virtual Pointer<Command> processCommitTransactionTwoPhase(TransactionInfo* info);
- virtual Pointer<Command> processCommitTransactionTwoPhase( TransactionInfo* info );
+ virtual Pointer<Command> processRollbackTransaction(TransactionInfo* info);
- virtual Pointer<Command> processRollbackTransaction( TransactionInfo* info );
+ virtual Pointer<Command> processEndTransaction(TransactionInfo* info);
- virtual Pointer<Command> processEndTransaction( TransactionInfo* info );
-
- virtual Pointer<Command> processMessagePull( MessagePull* pull );
+ virtual Pointer<Command> processMessagePull(MessagePull* pull);
bool isRestoreConsumers() const {
return this->restoreConsumers;
}
- void setRestoreConsumers( bool restoreConsumers ) {
+ void setRestoreConsumers(bool restoreConsumers) {
this->restoreConsumers = restoreConsumers;
}
@@ -138,7 +134,7 @@ namespace state {
return this->restoreProducers;
}
- void setRestoreProducers( bool restoreProducers ) {
+ void setRestoreProducers(bool restoreProducers) {
this->restoreProducers = restoreProducers;
}
@@ -146,7 +142,7 @@ namespace state {
return this->restoreSessions;
}
- void setRestoreSessions( bool restoreSessions ) {
+ void setRestoreSessions(bool restoreSessions) {
this->restoreSessions = restoreSessions;
}
@@ -154,7 +150,7 @@ namespace state {
return this->trackTransactions;
}
- void setTrackTransactions( bool trackTransactions ) {
+ void setTrackTransactions(bool trackTransactions) {
this->trackTransactions = trackTransactions;
}
@@ -162,7 +158,7 @@ namespace state {
return this->restoreTransaction;
}
- void setRestoreTransaction( bool restoreTransaction ) {
+ void setRestoreTransaction(bool restoreTransaction) {
this->restoreTransaction = restoreTransaction;
}
@@ -170,7 +166,7 @@ namespace state {
return this->trackMessages;
}
- void setTrackMessages( bool trackMessages ) {
+ void setTrackMessages(bool trackMessages) {
this->trackMessages = trackMessages;
}
@@ -178,7 +174,7 @@ namespace state {
return this->maxCacheSize;
}
- void setMaxCacheSize( int maxCacheSize ) {
+ void setMaxCacheSize(int maxCacheSize) {
this->maxCacheSize = maxCacheSize;
}
@@ -186,26 +182,21 @@ namespace state {
return this->trackTransactionProducers;
}
- void setTrackTransactionProducers( bool trackTransactionProducers ) {
+ void setTrackTransactionProducers(bool trackTransactionProducers) {
this->trackTransactionProducers = trackTransactionProducers;
}
private:
- void doRestoreTransactions( const Pointer<transport::Transport>& transport,
- const Pointer<ConnectionState>& connectionState );
+ void doRestoreTransactions(Pointer<transport::Transport> transport, Pointer<ConnectionState> connectionState);
- void doRestoreSessions( const Pointer<transport::Transport>& transport,
- const Pointer<ConnectionState>& connectionState );
+ void doRestoreSessions(Pointer<transport::Transport> transport, Pointer<ConnectionState> connectionState);
- void doRestoreConsumers( const Pointer<transport::Transport>& transport,
- const Pointer<SessionState>& sessionState );
+ void doRestoreConsumers(Pointer<transport::Transport> transport, Pointer<SessionState> sessionState);
- void doRestoreProducers( const Pointer<transport::Transport>& transport,
- const Pointer<SessionState>& sessionState );
+ void doRestoreProducers(Pointer<transport::Transport> transport, Pointer<SessionState> sessionState);
- void doRestoreTempDestinations( const Pointer<transport::Transport>& transport,
- const Pointer<ConnectionState>& connectionState );
+ void doRestoreTempDestinations(Pointer<transport::Transport> transport, Pointer<ConnectionState> connectionState);
};
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/ConsumerState.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/ConsumerState.cpp?rev=1339242&r1=1339241&r2=1339242&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/ConsumerState.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/ConsumerState.cpp Wed May 16 16:02:06 2012
@@ -23,7 +23,7 @@ using namespace activemq::commands;
using namespace decaf::lang;
////////////////////////////////////////////////////////////////////////////////
-ConsumerState::ConsumerState( const Pointer<ConsumerInfo>& info ) : info( info ) {
+ConsumerState::ConsumerState(Pointer<ConsumerInfo> info) : info(info) {
}
////////////////////////////////////////////////////////////////////////////////
@@ -33,7 +33,7 @@ ConsumerState::~ConsumerState() {
////////////////////////////////////////////////////////////////////////////////
std::string ConsumerState::toString() const {
- if( this->info != NULL ) {
+ if (this->info != NULL) {
return this->info->toString();
}
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/ConsumerState.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/ConsumerState.h?rev=1339242&r1=1339241&r2=1339242&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/ConsumerState.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/ConsumerState.h Wed May 16 16:02:06 2012
@@ -37,15 +37,20 @@ namespace state {
Pointer<ConsumerInfo> info;
+ private:
+
+ ConsumerState(const ConsumerState&);
+ ConsumerState& operator=(const ConsumerState&);
+
public:
- ConsumerState( const Pointer<ConsumerInfo>& info );
+ ConsumerState(Pointer<ConsumerInfo> info);
virtual ~ConsumerState();
std::string toString() const;
- const Pointer<ConsumerInfo>& getInfo() const {
+ const Pointer<ConsumerInfo> getInfo() const {
return this->info;
}
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/ProducerState.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/ProducerState.cpp?rev=1339242&r1=1339241&r2=1339242&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/ProducerState.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/ProducerState.cpp Wed May 16 16:02:06 2012
@@ -25,7 +25,7 @@ using namespace activemq::commands;
using namespace decaf::lang;
////////////////////////////////////////////////////////////////////////////////
-ProducerState::ProducerState( const Pointer<ProducerInfo>& info ) : info(info), transactionState() {
+ProducerState::ProducerState(Pointer<ProducerInfo> info) : info(info), transactionState() {
}
////////////////////////////////////////////////////////////////////////////////
@@ -35,7 +35,7 @@ ProducerState::~ProducerState() {
////////////////////////////////////////////////////////////////////////////////
std::string ProducerState::toString() const {
- if( this->info != NULL ) {
+ if (this->info != NULL) {
return this->info->toString();
}
@@ -43,7 +43,7 @@ std::string ProducerState::toString() co
}
////////////////////////////////////////////////////////////////////////////////
-void ProducerState::setTransactionState( const Pointer<TransactionState>& transactionState ) {
+void ProducerState::setTransactionState(Pointer<TransactionState> transactionState) {
this->transactionState = transactionState;
}
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/ProducerState.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/ProducerState.h?rev=1339242&r1=1339241&r2=1339242&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/ProducerState.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/ProducerState.h Wed May 16 16:02:06 2012
@@ -40,19 +40,24 @@ namespace state {
Pointer<ProducerInfo> info;
Pointer<TransactionState> transactionState;
+ private:
+
+ ProducerState(const ProducerState&);
+ ProducerState& operator=(const ProducerState&);
+
public:
- ProducerState( const Pointer<ProducerInfo>& info );
+ ProducerState(Pointer<ProducerInfo> info);
virtual ~ProducerState();
std::string toString() const;
- const Pointer<ProducerInfo>& getInfo() const {
+ const Pointer<ProducerInfo> getInfo() const {
return this->info;
}
- void setTransactionState( const Pointer<TransactionState>& transactionState );
+ void setTransactionState(Pointer<TransactionState> transactionState);
Pointer<TransactionState> getTransactionState() const;
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/SessionState.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/SessionState.cpp?rev=1339242&r1=1339241&r2=1339242&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/SessionState.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/SessionState.cpp Wed May 16 16:02:06 2012
@@ -28,7 +28,7 @@ using namespace decaf;
using namespace decaf::lang;
////////////////////////////////////////////////////////////////////////////////
-SessionState::SessionState( const Pointer<SessionInfo>& info ) :
+SessionState::SessionState(Pointer<SessionInfo> info) :
info(info), producers(), consumers(), disposed(false) {
}
@@ -39,7 +39,7 @@ SessionState::~SessionState() {
////////////////////////////////////////////////////////////////////////////////
std::string SessionState::toString() const {
- if( this->info.get() != NULL ) {
+ if (this->info.get() != NULL) {
return this->info->toString();
}
@@ -49,27 +49,29 @@ std::string SessionState::toString() con
////////////////////////////////////////////////////////////////////////////////
void SessionState::checkShutdown() const {
- if( this->disposed.get() ) {
+ if (this->disposed.get()) {
throw decaf::lang::exceptions::IllegalStateException(
- __FILE__, __LINE__, "Session already Disposed" );
+ __FILE__, __LINE__, "Session already Disposed");
}
}
////////////////////////////////////////////////////////////////////////////////
-void SessionState::addProducer( const Pointer<ProducerInfo>& info ) {
+void SessionState::addProducer(Pointer<ProducerInfo> info) {
checkShutdown();
- producers.put( info->getProducerId(),
- Pointer<ProducerState>( new ProducerState( info ) ) );
+ producers.put(info->getProducerId(), Pointer<ProducerState>(new ProducerState(info)));
}
////////////////////////////////////////////////////////////////////////////////
-Pointer<ProducerState> SessionState::removeProducer( const Pointer<ProducerId>& id ) {
+Pointer<ProducerState> SessionState::removeProducer(Pointer<ProducerId> id) {
- Pointer<ProducerState> producerState = producers.remove( id );
- if( producerState != NULL ) {
- if( producerState->getTransactionState() != NULL ) {
- // allow the transaction to recreate dependent producer on recovery
- producerState->getTransactionState()->addProducerState( producerState );
+ Pointer<ProducerState> producerState = producers.remove(id);
+ if (producerState != NULL) {
+ if (producerState->getTransactionState() != NULL) {
+ // allow the transaction to recreate dependent producer on recovery, we
+ // hand off the producer state to the Transaction and NULL the producer's
+ // reference to avoid a circular link to it.
+ producerState->getTransactionState()->addProducerState(producerState);
+ producerState->getTransactionState().reset(NULL);
}
}
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/SessionState.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/SessionState.h?rev=1339242&r1=1339241&r2=1339242&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/SessionState.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/SessionState.h Wed May 16 16:02:06 2012
@@ -44,19 +44,24 @@ namespace state {
Pointer<SessionInfo> info;
- ConcurrentStlMap< Pointer<ProducerId>,
- Pointer<ProducerState>,
- ProducerId::COMPARATOR > producers;
-
- ConcurrentStlMap< Pointer<ConsumerId>,
- Pointer<ConsumerState>,
- ConsumerId::COMPARATOR > consumers;
+ ConcurrentStlMap<Pointer<ProducerId>,
+ Pointer<ProducerState>,
+ ProducerId::COMPARATOR> producers;
+
+ ConcurrentStlMap<Pointer<ConsumerId>,
+ Pointer<ConsumerState>,
+ ConsumerId::COMPARATOR> consumers;
AtomicBoolean disposed;
+ private:
+
+ SessionState(const SessionState&);
+ SessionState& operator=(const SessionState&);
+
public:
- SessionState( const Pointer<SessionInfo>& info );
+ SessionState(Pointer<SessionInfo> info);
virtual ~SessionState();
@@ -66,40 +71,39 @@ namespace state {
return this->info;
}
- void addProducer( const Pointer<ProducerInfo>& info );
+ void addProducer(Pointer<ProducerInfo> info);
- Pointer<ProducerState> removeProducer( const Pointer<ProducerId>& id );
+ Pointer<ProducerState> removeProducer(Pointer<ProducerId> id);
- void addConsumer( const Pointer<ConsumerInfo>& info ) {
+ void addConsumer(const Pointer<ConsumerInfo>& info) {
checkShutdown();
- consumers.put( info->getConsumerId(),
- Pointer<ConsumerState>( new ConsumerState( info ) ) );
+ consumers.put(info->getConsumerId(), Pointer<ConsumerState>(new ConsumerState(info)));
}
- Pointer<ConsumerState> removeConsumer( const Pointer<ConsumerId>& id ) {
- return consumers.remove( id );
+ Pointer<ConsumerState> removeConsumer(Pointer<ConsumerId> id) {
+ return consumers.remove(id);
}
- std::vector< Pointer<ProducerState> > getProducerStates() const {
+ std::vector<Pointer<ProducerState> > getProducerStates() const {
return producers.values();
}
- Pointer<ProducerState> getProducerState( const Pointer<ProducerId>& id ) {
- return producers.get( id );
+ Pointer<ProducerState> getProducerState(Pointer<ProducerId> id) {
+ return producers.get(id);
}
- std::vector< Pointer<ConsumerState> > getConsumerStates() const {
+ std::vector<Pointer<ConsumerState> > getConsumerStates() const {
return consumers.values();
}
- Pointer<ConsumerState> getConsumerState( const Pointer<ConsumerId>& id ) {
- return consumers.get( id );
+ Pointer<ConsumerState> getConsumerState(Pointer<ConsumerId> id) {
+ return consumers.get(id);
}
void checkShutdown() const;
void shutdown() {
- this->disposed.set( true );
+ this->disposed.set(true);
}
};
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/Tracked.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/Tracked.cpp?rev=1339242&r1=1339241&r2=1339242&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/Tracked.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/Tracked.cpp Wed May 16 16:02:06 2012
@@ -26,21 +26,19 @@ using namespace decaf;
using namespace decaf::lang;
////////////////////////////////////////////////////////////////////////////////
-Tracked::Tracked() : runnable() {
+Tracked::Tracked() : commands::Response(), runnable() {
}
////////////////////////////////////////////////////////////////////////////////
-Tracked::Tracked( const Pointer<Runnable>& runnable ) : runnable( runnable ) {
+Tracked::Tracked(Pointer<Runnable> runnable) : commands::Response(), runnable(runnable) {
}
////////////////////////////////////////////////////////////////////////////////
void Tracked::onResponse() {
-
try {
-
- if( this->runnable != NULL ) {
+ if (this->runnable != NULL) {
this->runnable->run();
- this->runnable.reset( NULL );
+ this->runnable.reset(NULL);
}
}
AMQ_CATCH_RETHROW( ActiveMQException )
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/Tracked.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/Tracked.h?rev=1339242&r1=1339241&r2=1339242&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/Tracked.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/Tracked.h Wed May 16 16:02:06 2012
@@ -26,17 +26,15 @@
namespace activemq {
namespace state {
- using decaf::lang::Pointer;
-
class AMQCPP_API Tracked : public commands::Response {
private:
- Pointer<decaf::lang::Runnable> runnable;
+ decaf::lang::Pointer<decaf::lang::Runnable> runnable;
public:
Tracked();
- Tracked( const Pointer<decaf::lang::Runnable>& runnable );
+ Tracked(decaf::lang::Pointer<decaf::lang::Runnable> runnable);
virtual ~Tracked() {}
@@ -45,7 +43,6 @@ namespace state {
bool isWaitingForResponse() const {
return runnable != NULL;
}
-
};
}}
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/TransactionState.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/TransactionState.cpp?rev=1339242&r1=1339241&r2=1339242&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/TransactionState.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/TransactionState.cpp Wed May 16 16:02:06 2012
@@ -29,19 +29,19 @@ using namespace decaf::util;
using namespace decaf::lang;
////////////////////////////////////////////////////////////////////////////////
-TransactionState::TransactionState( const Pointer<TransactionId>& id ) :
+TransactionState::TransactionState(Pointer<TransactionId> id) :
commands(), id(id), disposed(false), prepared(false), preparedResult(0), producers() {
}
////////////////////////////////////////////////////////////////////////////////
TransactionState::~TransactionState() {
- this->commands.clear();
+ clear();
}
////////////////////////////////////////////////////////////////////////////////
std::string TransactionState::toString() const {
- if( this->id != NULL ) {
+ if (this->id != NULL) {
return this->id->toString();
}
@@ -49,30 +49,39 @@ std::string TransactionState::toString()
}
////////////////////////////////////////////////////////////////////////////////
-void TransactionState::addCommand( const Pointer<Command>& operation ) {
+void TransactionState::clear() {
+ this->commands.clear();
+ this->producers.clear();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void TransactionState::addCommand(Pointer<Command> operation) {
checkShutdown();
- commands.add( operation );
+ commands.add(operation);
}
////////////////////////////////////////////////////////////////////////////////
void TransactionState::checkShutdown() const {
- if( this->disposed.get() ) {
+ if (this->disposed.get()) {
throw decaf::lang::exceptions::IllegalStateException(
- __FILE__, __LINE__, "Transaction already Disposed" );
+ __FILE__, __LINE__, "Transaction already Disposed");
}
}
////////////////////////////////////////////////////////////////////////////////
-void TransactionState::addProducerState( const Pointer<ProducerState>& producerState ) {
+void TransactionState::addProducerState(Pointer<ProducerState> producerState) {
- if( producerState != NULL ) {
- producers.put( producerState->getInfo()->getProducerId(), producerState );
+ if (producerState != NULL) {
+ // Ensure the producer doesn't hold a link to this TX state to avoid a
+ // circular reference that could lead to memory leaks.
+ producerState->getTransactionState().reset(NULL);
+ producers.put(producerState->getInfo()->getProducerId(), producerState);
}
}
////////////////////////////////////////////////////////////////////////////////
-std::vector< Pointer<ProducerState> > TransactionState::getProducerStates() {
+std::vector<Pointer<ProducerState> > TransactionState::getProducerStates() {
return this->producers.values();
}
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/TransactionState.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/TransactionState.h?rev=1339242&r1=1339241&r2=1339242&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/TransactionState.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/state/TransactionState.h Wed May 16 16:02:06 2012
@@ -50,34 +50,41 @@ namespace state {
AtomicBoolean disposed;
bool prepared;
int preparedResult;
- ConcurrentStlMap< Pointer<ProducerId>, Pointer<ProducerState>,
- ProducerId::COMPARATOR > producers;
+ ConcurrentStlMap<Pointer<ProducerId>, Pointer<ProducerState>,
+ ProducerId::COMPARATOR> producers;
+
+ private:
+
+ TransactionState(const TransactionState&);
+ TransactionState& operator=(const TransactionState&);
public:
- TransactionState( const Pointer<TransactionId>& id );
+ TransactionState(Pointer<TransactionId> id);
virtual ~TransactionState();
std::string toString() const;
- void addCommand( const Pointer<Command>& operation );
+ void addCommand(Pointer<Command> operation);
void checkShutdown() const;
void shutdown() {
- this->disposed.set( true );
+ this->disposed.set(true);
}
- const LinkedList< Pointer<Command> >& getCommands() const {
+ void clear();
+
+ const LinkedList<Pointer<Command> >& getCommands() const {
return commands;
}
- const Pointer<TransactionId>& getId() const {
+ const Pointer<TransactionId> getId() const {
return id;
}
- void setPrepared( bool prepared ) {
+ void setPrepared(bool prepared) {
this->prepared = prepared;
}
@@ -85,7 +92,7 @@ namespace state {
return this->prepared;
}
- void setPreparedResult( int preparedResult ) {
+ void setPreparedResult(int preparedResult) {
this->preparedResult = preparedResult;
}
@@ -93,9 +100,9 @@ namespace state {
return this->preparedResult;
}
- void addProducerState( const Pointer<ProducerState>& producerState );
+ void addProducerState(Pointer<ProducerState> producerState);
- std::vector< Pointer<ProducerState> > getProducerStates();
+ std::vector<Pointer<ProducerState> > getProducerStates();
};