Author: chirino
Date: Mon Dec 13 15:27:16 2010
New Revision: 1045171
URL: http://svn.apache.org/viewvc?rev=1045171&view=rev
Log:
Move the shared apollo thread pool into the util module so it can get used by
the SSL transport. Fixes a hang in a test.
Added:
activemq/activemq-apollo/trunk/apollo-util/src/main/scala/org/apache/activemq/apollo/util/ApolloThreadPool.java
Modified:
activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Broker.scala
activemq/activemq-apollo/trunk/apollo-tcp/src/main/java/org/apache/activemq/apollo/transport/tcp/SslTransport.java
Modified:
activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Broker.scala
URL:
http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Broker.scala?rev=1045171&r1=1045170&r2=1045171&view=diff
==============================================================================
---
activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Broker.scala
(original)
+++
activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Broker.scala
Mon Dec 13 15:27:16 2010
@@ -106,11 +106,7 @@ object BrokerRegistry {
object Broker extends Log {
- val BLOCKABLE_THREAD_POOL = Executors.newCachedThreadPool(new
ThreadFactory(){
- def newThread(r: Runnable) = new Thread(r, "Apollo Worker") {
- setDaemon(true)
- }
- })
+ val BLOCKABLE_THREAD_POOL = ApolloThreadPool.INSTANCE
val broker_id_counter = new AtomicLong()
Modified:
activemq/activemq-apollo/trunk/apollo-tcp/src/main/java/org/apache/activemq/apollo/transport/tcp/SslTransport.java
URL:
http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-tcp/src/main/java/org/apache/activemq/apollo/transport/tcp/SslTransport.java?rev=1045171&r1=1045170&r2=1045171&view=diff
==============================================================================
---
activemq/activemq-apollo/trunk/apollo-tcp/src/main/java/org/apache/activemq/apollo/transport/tcp/SslTransport.java
(original)
+++
activemq/activemq-apollo/trunk/apollo-tcp/src/main/java/org/apache/activemq/apollo/transport/tcp/SslTransport.java
Mon Dec 13 15:27:16 2010
@@ -1,5 +1,6 @@
package org.apache.activemq.apollo.transport.tcp;
+import org.apache.activemq.apollo.util.ApolloThreadPool;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -39,8 +40,6 @@ public class SslTransport extends TcpTra
private ByteBuffer readOverflowBuffer;
- private ExecutorService blockingExecutor;
-
public void setSSLContext(SSLContext ctx) {
this.sslContext = ctx;
}
@@ -248,15 +247,12 @@ public class SslTransport extends TcpTra
case NEED_TASK:
final Runnable task = engine.getDelegatedTask();
if( task!=null ) {
- if( blockingExecutor==null ) {
- blockingExecutor =
Executors.newSingleThreadExecutor();
- }
- blockingExecutor.execute(new Runnable(){
+ ApolloThreadPool.INSTANCE.execute(new Runnable() {
public void run() {
task.run();
- dispatchQueue.execute(new Runnable(){
+ dispatchQueue.execute(new Runnable() {
public void run() {
- if( isConnected() ) {
+ if (isConnected()) {
handshake_done();
}
}
@@ -293,10 +289,6 @@ public class SslTransport extends TcpTra
break;
case FINISHED:
- if( blockingExecutor!=null ) {
- blockingExecutor.shutdown();
- blockingExecutor = null;
- }
case NOT_HANDSHAKING:
return true;
Added:
activemq/activemq-apollo/trunk/apollo-util/src/main/scala/org/apache/activemq/apollo/util/ApolloThreadPool.java
URL:
http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-util/src/main/scala/org/apache/activemq/apollo/util/ApolloThreadPool.java?rev=1045171&view=auto
==============================================================================
---
activemq/activemq-apollo/trunk/apollo-util/src/main/scala/org/apache/activemq/apollo/util/ApolloThreadPool.java
(added)
+++
activemq/activemq-apollo/trunk/apollo-util/src/main/scala/org/apache/activemq/apollo/util/ApolloThreadPool.java
Mon Dec 13 15:27:16 2010
@@ -0,0 +1,41 @@
+/**
+ * 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.
+ */
+package org.apache.activemq.apollo.util;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadFactory;
+
+/**
+ * <p>
+ * Holds a singleton instance to a cached thread pool that can be used
+ * to execute blocking tasks.
+ * </p>
+ *
+ * @author <a href="http://hiramchirino.com">Hiram Chirino</a>
+ */
+public class ApolloThreadPool {
+
+ public static final ExecutorService INSTANCE =
Executors.newCachedThreadPool(new ThreadFactory() {
+ public Thread newThread(Runnable r) {
+ Thread rc = new Thread(r, "Apollo Worker");
+ rc.setDaemon(true);
+ return rc;
+ }
+ });
+
+}