summaryrefslogtreecommitdiffstats
path: root/branches/sca-java-1.x
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-06-04 23:43:05 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-06-04 23:43:05 +0000
commit6a9f8b2718697d444e4413166465cf2c5f1ef533 (patch)
treede7f3a06be12730ffc72150c3fc809938b7bc10a /branches/sca-java-1.x
parentffe36f15ffc3cb9115e25ed24e9208aa8d8642f9 (diff)
Fix for TUSCANY-3077. Allow the thread pool for conversation manager to be shutdown
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@781872 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-rw-r--r--branches/sca-java-1.x/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ConversationManager.java14
-rw-r--r--branches/sca-java-1.x/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ConversationManagerImpl.java43
-rw-r--r--branches/sca-java-1.x/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/RuntimeBootStrapper.java15
3 files changed, 45 insertions, 27 deletions
diff --git a/branches/sca-java-1.x/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ConversationManager.java b/branches/sca-java-1.x/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ConversationManager.java
index 28e22b4f2c..f928f91a02 100644
--- a/branches/sca-java-1.x/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ConversationManager.java
+++ b/branches/sca-java-1.x/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ConversationManager.java
@@ -6,22 +6,22 @@
* 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.
+ * under the License.
*/
package org.apache.tuscany.sca.core.conversation;
/**
* The manager of conversations
- *
+ *
* @version $Rev$ $Date$
*/
public interface ConversationManager {
@@ -58,14 +58,16 @@ public interface ConversationManager {
* @param listener
*/
void removeListener(ConversationListener listener);
-
+
/**
* @return the default max age for a conversation
*/
long getMaxAge();
-
+
/**
* @return the default max idle time for a conversation
*/
long getMaxIdleTime();
+
+ void destroy();
}
diff --git a/branches/sca-java-1.x/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ConversationManagerImpl.java b/branches/sca-java-1.x/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ConversationManagerImpl.java
index 8a883f8e15..3bea79b076 100644
--- a/branches/sca-java-1.x/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ConversationManagerImpl.java
+++ b/branches/sca-java-1.x/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ConversationManagerImpl.java
@@ -6,15 +6,15 @@
* 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.
+ * under the License.
*/
package org.apache.tuscany.sca.core.conversation;
@@ -35,7 +35,7 @@ import java.util.concurrent.TimeUnit;
* @version $Rev$ $Date$
*/
public class ConversationManagerImpl implements ConversationManager {
-
+
private List<ConversationListener> listeners = Collections.synchronizedList(new ArrayList<ConversationListener>());
private Map<Object, ExtendedConversation> conversations = new ConcurrentHashMap<Object, ExtendedConversation>();
@@ -43,12 +43,12 @@ public class ConversationManagerImpl implements ConversationManager {
* the default max age. this is set to 1 hour
*/
private static final long DEFAULT_MAX_AGE = 60 * 60 * 1000; ;
-
+
/**
* the default max idle time. this is set to 1 hour
*/
- private static final long DEFAULT_MAX_IDLE_TIME = 60 * 60 * 1000;
-
+ private static final long DEFAULT_MAX_IDLE_TIME = 60 * 60 * 1000;
+
/**
* the globally used max age
*/
@@ -57,20 +57,22 @@ public class ConversationManagerImpl implements ConversationManager {
/**
* the globally used max idle time
*/
- private final long maxIdleTime;
+ private final long maxIdleTime;
/**
* the reaper thread
*/
- private final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
-
+ private final ScheduledExecutorService scheduler;
+
/**
* constructor
*/
public ConversationManagerImpl() {
long mit = DEFAULT_MAX_IDLE_TIME;
long ma = DEFAULT_MAX_AGE;
-
+
+ scheduler = Executors.newSingleThreadScheduledExecutor();
+
// Allow privileged access to read system property. Requires PropertyPermission in security
// policy.
String aProperty = AccessController.doPrivileged(new PrivilegedAction<String>() {
@@ -104,7 +106,7 @@ public class ConversationManagerImpl implements ConversationManager {
maxAge = ma;
maxIdleTime = mit;
}
-
+
/**
* @see org.apache.tuscany.sca.core.conversation.ConversationManager#addListener(org.apache.tuscany.sca.core.conversation.ConversationListener)
*/
@@ -170,17 +172,17 @@ public class ConversationManagerImpl implements ConversationManager {
*/
public synchronized void stopReaper() {
- // Prevent the scheduler from submitting any additional reapers,
- // initiate an orderly shutdown if a reaper task is in progress.
+ // Prevent the scheduler from submitting any additional reapers,
+ // initiate an orderly shutdown if a reaper task is in progress.
this.scheduler.shutdown();
}
-
+
/**
* @see org.apache.tuscany.sca.core.conversation.ConversationManager#startConversation(java.lang.Object)
*/
public ExtendedConversation startConversation(Object conversationID) {
-
+
if (conversationID == null) {
conversationID = UUID.randomUUID().toString();
}
@@ -188,7 +190,7 @@ public class ConversationManagerImpl implements ConversationManager {
if (conversation != null && conversation.getState() != ConversationState.ENDED) {
throw new IllegalStateException(conversation + " already exists.");
}
-
+
conversation = new ExtendedConversationImpl(
this, conversationID, ConversationState.STARTED);
conversations.put(conversationID, conversation);
@@ -213,4 +215,11 @@ public class ConversationManagerImpl implements ConversationManager {
public long getMaxAge(){
return maxAge;
}
+
+ public void destroy() {
+ // REVIEW: A more graceful way?
+ scheduler.shutdownNow();
+ this.listeners.clear();
+ this.conversations.clear();
+ }
}
diff --git a/branches/sca-java-1.x/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/RuntimeBootStrapper.java b/branches/sca-java-1.x/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/RuntimeBootStrapper.java
index 1338b3a27c..349548c08c 100644
--- a/branches/sca-java-1.x/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/RuntimeBootStrapper.java
+++ b/branches/sca-java-1.x/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/RuntimeBootStrapper.java
@@ -6,15 +6,15 @@
* 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.
+ * under the License.
*/
package org.apache.tuscany.sca.node.impl;
@@ -50,6 +50,7 @@ import org.apache.tuscany.sca.core.UtilityExtensionPoint;
import org.apache.tuscany.sca.core.assembly.ActivationException;
import org.apache.tuscany.sca.core.assembly.CompositeActivator;
import org.apache.tuscany.sca.core.assembly.RuntimeAssemblyFactory;
+import org.apache.tuscany.sca.core.conversation.ConversationManager;
import org.apache.tuscany.sca.core.invocation.ExtensibleProxyFactory;
import org.apache.tuscany.sca.core.invocation.ProxyFactory;
import org.apache.tuscany.sca.core.invocation.ProxyFactoryExtensionPoint;
@@ -96,6 +97,7 @@ public class RuntimeBootStrapper {
private List<SCADefinitions> policyDefinitions;
private ModelResolver policyDefinitionsResolver;
private Monitor monitor;
+ private ConversationManager conversationManager;
public RuntimeBootStrapper(ClassLoader classLoader) {
this.classLoader = classLoader;
@@ -111,6 +113,8 @@ public class RuntimeBootStrapper {
// Get work scheduler
workScheduler = utilities.getUtility(WorkScheduler.class);
+ conversationManager = utilities.getUtility(ConversationManager.class);
+
// Create an interface contract mapper
InterfaceContractMapper mapper = utilities.getUtility(InterfaceContractMapper.class);
@@ -165,7 +169,7 @@ public class RuntimeBootStrapper {
policyDefinitions,
policyDefinitionsResolver,
monitor);
-
+
// add the contribution service into the utility extension point
utilities.addUtility(contributionService);
@@ -201,6 +205,9 @@ public class RuntimeBootStrapper {
// Stop and destroy the work manager
workScheduler.destroy();
+ conversationManager.destroy();
+ conversationManager = null;
+
// Cleanup
modules = null;
registry = null;