You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2013/01/11 18:26:50 UTC
[2/3] git commit: Deprecate ThreadCleanupListener,
replace with a Runnable callback
Deprecate ThreadCleanupListener, replace with a Runnable callback
Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/33d23b6d
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/33d23b6d
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/33d23b6d
Branch: refs/heads/master
Commit: 33d23b6dddcbf620e56c3b3f02a9cee3c5a2c867
Parents: 8b72296
Author: Howard M. Lewis Ship <hl...@apache.org>
Authored: Thu Jan 10 13:43:40 2013 -0500
Committer: Howard M. Lewis Ship <hl...@apache.org>
Committed: Thu Jan 10 13:43:40 2013 -0500
----------------------------------------------------------------------
.../internal/services/PerthreadManagerImpl.java | 43 ++++++++++-----
.../tapestry5/ioc/services/PerthreadManager.java | 18 +++++--
.../ioc/services/ThreadCleanupListener.java | 4 +-
.../ioc/specs/PerthreadManagerImplSpec.groovy | 2 +-
4 files changed, 48 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/33d23b6d/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/PerthreadManagerImpl.java
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/PerthreadManagerImpl.java b/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/PerthreadManagerImpl.java
index 8646a57..843d465 100644
--- a/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/PerthreadManagerImpl.java
+++ b/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/PerthreadManagerImpl.java
@@ -1,4 +1,4 @@
-// Copyright 2006-2012 The Apache Software Foundation
+// Copyright 2006-2013 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -34,7 +34,7 @@ public class PerthreadManagerImpl implements PerthreadManager
{
private final Lock lock = JDKUtils.createLockForThreadLocalCreation();
- private final PerThreadValue<List<ThreadCleanupListener>> listenersValue;
+ private final PerThreadValue<List<Runnable>> callbacksValue;
private static class MapHolder extends ThreadLocal<Map>
{
@@ -57,7 +57,7 @@ public class PerthreadManagerImpl implements PerthreadManager
{
this.logger = logger;
- listenersValue = createValue();
+ callbacksValue = createValue();
}
public void registerForShutdown(RegistryShutdownHub hub)
@@ -93,22 +93,39 @@ public class PerthreadManagerImpl implements PerthreadManager
}
}
- private List<ThreadCleanupListener> getListeners()
+ private List<Runnable> getCallbacks()
{
- List<ThreadCleanupListener> result = listenersValue.get();
+ List<Runnable> result = callbacksValue.get();
if (result == null)
{
result = CollectionFactory.newList();
- listenersValue.set(result);
+ callbacksValue.set(result);
}
return result;
}
- public void addThreadCleanupListener(ThreadCleanupListener listener)
+ public void addThreadCleanupListener(final ThreadCleanupListener listener)
{
- getListeners().add(listener);
+ assert listener != null;
+
+ addThreadCleanupCallback(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ listener.threadDidCleanup();
+ }
+ });
+ }
+
+ @Override
+ public void addThreadCleanupCallback(Runnable callback)
+ {
+ assert callback != null;
+
+ getCallbacks().add(callback);
}
/**
@@ -117,18 +134,18 @@ public class PerthreadManagerImpl implements PerthreadManager
*/
public void cleanup()
{
- List<ThreadCleanupListener> listeners = getListeners();
+ List<Runnable> callbacks = getCallbacks();
- listenersValue.set(null);
+ callbacksValue.set(null);
- for (ThreadCleanupListener listener : listeners)
+ for (Runnable callback : callbacks)
{
try
{
- listener.threadDidCleanup();
+ callback.run();
} catch (Exception ex)
{
- logger.warn(String.format("Error invoking listener %s: %s", listener, ex),
+ logger.warn(String.format("Error invoking callback %s: %s", callback, ex),
ex);
}
}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/33d23b6d/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/PerthreadManager.java
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/PerthreadManager.java b/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/PerthreadManager.java
index 7961c01..0db6020 100644
--- a/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/PerthreadManager.java
+++ b/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/PerthreadManager.java
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007, 2008, 2010, 2011 The Apache Software Foundation
+// Copyright 2006-2013 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -30,13 +30,23 @@ public interface PerthreadManager
/**
* Adds a listener to the hub. All listeners are discarded at the {@link #cleanup()}.
*
- * @param listener to add
+ * @param listener
+ * to add
+ * @deprecated Deprecated in 5.4, use {@link #addThreadCleanupCallback(Runnable)} instead.
*/
void addThreadCleanupListener(ThreadCleanupListener listener);
/**
- * Immediately performs a cleanup of the thread, notifying all listeners, then discarding all per-thread data
- * stored by the manager.
+ * Adds a callback to be invoked when {@link #cleanup()} is invoked; callbacks are then removed.
+ *
+ * @param callback
+ * @since 5.4
+ */
+ void addThreadCleanupCallback(Runnable callback);
+
+ /**
+ * Immediately performs a cleanup of the thread, invoking all callback, then discarding all per-thread data
+ * stored by the manager (including the list of callbacks).
*/
void cleanup();
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/33d23b6d/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/ThreadCleanupListener.java
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/ThreadCleanupListener.java b/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/ThreadCleanupListener.java
index 6af799a..b465b4f 100644
--- a/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/ThreadCleanupListener.java
+++ b/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/ThreadCleanupListener.java
@@ -1,4 +1,4 @@
-// Copyright 2006, 2008 The Apache Software Foundation
+// Copyright 2006, 2008, 2013 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -21,6 +21,8 @@ import java.util.EventListener;
* <p/>
* Note that registration with the {@link org.apache.tapestry5.ioc.services.PerthreadManager} is a one-shot affair; it
* lasts no longer than the next cleanup.
+ *
+ * @deprecated Deprecated in 5.4, use {@link PerthreadManager#addThreadCleanupCallback(Runnable)} instead.
*/
public interface ThreadCleanupListener extends EventListener
{
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/33d23b6d/tapestry-ioc/src/test/groovy/ioc/specs/PerthreadManagerImplSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/ioc/specs/PerthreadManagerImplSpec.groovy b/tapestry-ioc/src/test/groovy/ioc/specs/PerthreadManagerImplSpec.groovy
index f172728..ea01ebf 100644
--- a/tapestry-ioc/src/test/groovy/ioc/specs/PerthreadManagerImplSpec.groovy
+++ b/tapestry-ioc/src/test/groovy/ioc/specs/PerthreadManagerImplSpec.groovy
@@ -65,7 +65,7 @@ class PerthreadManagerImplSpec extends Specification {
then:
1 * l1.threadDidCleanup() >> { throw t }
- 1 * logger.warn({ it.contains "Error invoking listener"}, t)
+ 1 * logger.warn({ it.contains "Error invoking callback"}, t)
then: