diff options
author | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-06-04 23:43:05 +0000 |
---|---|---|
committer | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-06-04 23:43:05 +0000 |
commit | 6a9f8b2718697d444e4413166465cf2c5f1ef533 (patch) | |
tree | de7f3a06be12730ffc72150c3fc809938b7bc10a /branches/sca-java-1.x/modules/core/src/main/java | |
parent | ffe36f15ffc3cb9115e25ed24e9208aa8d8642f9 (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 'branches/sca-java-1.x/modules/core/src/main/java')
2 files changed, 34 insertions, 23 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(); + } } |