activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r757933 - in /activemq/activemq-cpp/trunk/src/main/activemq/transport/failover: CloseTransportsTask.cpp CloseTransportsTask.h FailoverTransport.cpp FailoverTransport.h
Date Tue, 24 Mar 2009 18:20:47 GMT
Author: tabish
Date: Tue Mar 24 18:20:45 2009
New Revision: 757933

URL: http://svn.apache.org/viewvc?rev=757933&view=rev
Log:
http://issues.apache.org/activemq/browse/AMQCPP-100

Close failed transports in a separate thread owned by a Composite task runner that will eventually
be the task runner for all work in the Failover Transport, reducing the number of threads
from two back down to one.

Added:
    activemq/activemq-cpp/trunk/src/main/activemq/transport/failover/CloseTransportsTask.cpp
  (with props)
    activemq/activemq-cpp/trunk/src/main/activemq/transport/failover/CloseTransportsTask.h
  (with props)
Modified:
    activemq/activemq-cpp/trunk/src/main/activemq/transport/failover/FailoverTransport.cpp
    activemq/activemq-cpp/trunk/src/main/activemq/transport/failover/FailoverTransport.h

Added: activemq/activemq-cpp/trunk/src/main/activemq/transport/failover/CloseTransportsTask.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/transport/failover/CloseTransportsTask.cpp?rev=757933&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/transport/failover/CloseTransportsTask.cpp
(added)
+++ activemq/activemq-cpp/trunk/src/main/activemq/transport/failover/CloseTransportsTask.cpp
Tue Mar 24 18:20:45 2009
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "CloseTransportsTask.h"
+
+#include <activemq/exceptions/ActiveMQException.h>
+
+using namespace activemq;
+using namespace activemq::threads;
+using namespace activemq::exceptions;
+using namespace activemq::transport;
+using namespace activemq::transport::failover;
+using namespace decaf;
+using namespace decaf::lang;
+using namespace decaf::util;
+using namespace decaf::util::concurrent;
+
+////////////////////////////////////////////////////////////////////////////////
+void CloseTransportsTask::add( const Pointer<Transport>& transport ) {
+    synchronized( &transports ) {
+        transports.push( transport );
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool CloseTransportsTask::isPending() const {
+    synchronized( &transports ) {
+        return !transports.empty();
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool CloseTransportsTask::iterate() {
+
+    synchronized( &transports ) {
+
+        if( !transports.empty() ) {
+            Pointer<Transport> transport = transports.pop();
+
+            try{
+                transport->close();
+            }
+            AMQ_CATCHALL_NOTHROW()
+
+            transport.reset( NULL );
+
+            return !transports.empty();
+        }
+
+    }
+
+    return false;
+}

Propchange: activemq/activemq-cpp/trunk/src/main/activemq/transport/failover/CloseTransportsTask.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/activemq-cpp/trunk/src/main/activemq/transport/failover/CloseTransportsTask.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/transport/failover/CloseTransportsTask.h?rev=757933&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/transport/failover/CloseTransportsTask.h
(added)
+++ activemq/activemq-cpp/trunk/src/main/activemq/transport/failover/CloseTransportsTask.h
Tue Mar 24 18:20:45 2009
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _ACTIVEMQ_TRANSPORT_FAILOVER_CLOSETRANSPORTSTASK_H_
+#define _ACTIVEMQ_TRANSPORT_FAILOVER_CLOSETRANSPORTSTASK_H_
+
+#include <activemq/util/Config.h>
+#include <activemq/threads/CompositeTask.h>
+#include <activemq/transport/Transport.h>
+
+#include <decaf/util/StlQueue.h>
+#include <decaf/lang/Pointer.h>
+
+namespace activemq {
+namespace transport {
+namespace failover {
+
+    using decaf::lang::Pointer;
+    using decaf::util::StlQueue;
+
+    class AMQCPP_API CloseTransportsTask: public activemq::threads::CompositeTask {
+    private:
+
+        mutable StlQueue< Pointer<Transport> > transports;
+
+    public:
+
+        CloseTransportsTask() {}
+        virtual ~CloseTransportsTask() {}
+
+        /**
+         * Add a new Transport to close.
+         */
+        void add( const Pointer<Transport>& transport );
+
+        /**
+         * This Task is pending if there are transports in the Queue that need to be
+         * closed.
+         *
+         * @return true if there is a transport in the queue that needs closed.
+         */
+        virtual bool isPending() const;
+
+        /**
+         * Return true until all transports have been closed and removed from the queue.
+         */
+        virtual bool iterate();
+
+    };
+
+}}}
+
+#endif /* _ACTIVEMQ_TRANSPORT_FAILOVER_CLOSETRANSPORTSTASK_H_ */

Propchange: activemq/activemq-cpp/trunk/src/main/activemq/transport/failover/CloseTransportsTask.h
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: activemq/activemq-cpp/trunk/src/main/activemq/transport/failover/FailoverTransport.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/transport/failover/FailoverTransport.cpp?rev=757933&r1=757932&r2=757933&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/transport/failover/FailoverTransport.cpp
(original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/transport/failover/FailoverTransport.cpp
Tue Mar 24 18:20:45 2009
@@ -22,6 +22,7 @@
 #include <activemq/commands/RemoveInfo.h>
 #include <activemq/transport/TransportRegistry.h>
 #include <activemq/threads/DedicatedTaskRunner.h>
+#include <activemq/threads/CompositeTaskRunner.h>
 #include <decaf/util/Random.h>
 #include <decaf/lang/System.h>
 #include <decaf/lang/Integer.h>
@@ -66,7 +67,11 @@
     this->stateTracker.setTrackTransactions( true );
     this->myTransportListener.reset( new FailoverTransportListener( this ) );
     this->reconnectTask.reset( new ReconnectTask( this ) );
+    this->closeTask.reset( new CloseTransportsTask() );
     this->taskRunner.reset( new DedicatedTaskRunner( reconnectTask.get() ) );
+    this->compositeTaskRunner.reset( new CompositeTaskRunner() );
+
+    this->compositeTaskRunner->addTask( this->closeTask.get() );
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -400,7 +405,8 @@
         sleepMutex.notifyAll();
     }
 
-    taskRunner->shutdown( 500 );
+    taskRunner->shutdown( 1000 );
+    compositeTaskRunner->shutdown( 1000 );
 
     if( transportToStop != NULL ) {
         transportToStop->close();
@@ -459,10 +465,9 @@
             transport->setTransportListener( disposedListener.get() );
         }
 
-        try{
-            transport->close();
-        }
-        AMQ_CATCHALL_NOTHROW()
+        // Hand off to the close task so it gets done in a different thread.
+        closeTask->add( transport );
+        compositeTaskRunner->wakeup();
 
         synchronized( &reconnectMutex ) {
             bool reconnectOk = started;

Modified: activemq/activemq-cpp/trunk/src/main/activemq/transport/failover/FailoverTransport.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/transport/failover/FailoverTransport.h?rev=757933&r1=757932&r2=757933&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/transport/failover/FailoverTransport.h (original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/transport/failover/FailoverTransport.h Tue
Mar 24 18:20:45 2009
@@ -22,10 +22,12 @@
 
 #include <activemq/commands/Command.h>
 #include <activemq/threads/TaskRunner.h>
+#include <activemq/threads/CompositeTaskRunner.h>
 #include <activemq/state/ConnectionStateTracker.h>
 #include <activemq/transport/CompositeTransport.h>
 #include <activemq/transport/failover/BackupTransport.h>
 #include <activemq/transport/failover/ReconnectTask.h>
+#include <activemq/transport/failover/CloseTransportsTask.h>
 #include <activemq/transport/failover/FailoverTransportListener.h>
 #include <activemq/wireformat/WireFormat.h>
 
@@ -89,7 +91,9 @@
         Pointer<Transport> connectedTransport;
         Pointer<Exception> connectionFailure;
         Pointer<ReconnectTask> reconnectTask;
+        Pointer<CloseTransportsTask> closeTask;
         Pointer<TaskRunner> taskRunner;
+        Pointer<CompositeTaskRunner> compositeTaskRunner;
         Pointer<TransportListener> disposedListener;
         Pointer<TransportListener> myTransportListener;
         TransportListener* transportListener;



Mime
View raw message