Hi,
there is a problem in the Push TimerChannelService implementation:
Callbacks do not work reliable when they are invoked from non-Web
threads. The "There is no application attached to current thread"
WicketRuntimeException will occur in such a case. The attached patch
fixes this issue.
Regards,
Seb
Index: push/src/main/java/org/wicketstuff/push/timer/TimerChannelBehavior.java
===================================================================
--- push/src/main/java/org/wicketstuff/push/timer/TimerChannelBehavior.java
(revision 5552)
+++ push/src/main/java/org/wicketstuff/push/timer/TimerChannelBehavior.java
(working copy)
@@ -50,6 +50,7 @@
* appropriately the resources associated with the page.
*
* @author Xavier Hanin
+ * @author Sebastian Thomschke fixed "There is no application attached to
current thread"
*
* @see IChannelService
* @see TimerChannelService
@@ -157,12 +158,12 @@
*/
public void invoke(final Object o) throws
IllegalArgumentException,
IllegalAccessException,
InvocationTargetException {
- final Application originalApplication =
Application.get();
+ final Application originalApplication =
Application.exists() ? Application.get() : null;
try {
Application.set(_application);
methods[m].invoke(o, parameters);
} finally {
- Application.set(originalApplication);
+ if (originalApplication != null)
Application.set(originalApplication);
}
}
}
@@ -175,8 +176,8 @@
/**
* Construct.
*/
- public DelayedMethodCallList() {
- _application = Application.get();
+ public DelayedMethodCallList(final Application application) {
+ _application = application;
calls = new ArrayList<DelayedMethodCall>();
}
@@ -185,8 +186,8 @@
*
* @param dmcl
*/
- public DelayedMethodCallList(final DelayedMethodCallList dmcl) {
- _application = Application.get();
+ public DelayedMethodCallList(final DelayedMethodCallList dmcl,
final Application application) {
+ _application = application;
calls = new ArrayList<DelayedMethodCall>(dmcl.calls);
}
@@ -253,7 +254,7 @@
* A trigger currently being constructed, waiting for a call to
trigger
* to go to the triggers list.
*/
- private final DelayedMethodCallList currentTrigger = new
DelayedMethodCallList();
+ private final DelayedMethodCallList currentTrigger;
/**
* The Wicket Application in which this target is used
*/
@@ -275,6 +276,7 @@
this.application = application;
this.id = id;
this.timeout = timeout;
+ this.currentTrigger = new
DelayedMethodCallList(application);
}
/**
@@ -337,7 +339,7 @@
if (currentTrigger.isEmpty()) {
return;
}
- trigger = new
DelayedMethodCallList(currentTrigger);
+ trigger = new
DelayedMethodCallList(currentTrigger, application);
currentTrigger.clear();
}
final List<DelayedMethodCallList> triggers =
getTriggers();
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org