Skip to content

Commit

Permalink
[playframework#873] now renderArgs survive await()
Browse files Browse the repository at this point in the history
  • Loading branch information
mbknor committed May 28, 2011
1 parent e8a5bfe commit a6b830d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
3 changes: 2 additions & 1 deletion framework/src/play/mvc/ActionInvoker.java
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,8 @@ static Object invoke(Method method, Object instance, Object[] realArgs) throws E
static final String C = "__continuation";
static final String A = "__callback";
static final String F = "__future";
static final String LV = "__localVariableNames";
static final String CONTINUATIONS_STORE_LOCAL_VARIABLE_NAMES = "__CONTINUATIONS_STORE_LOCAL_VARIABLE_NAMES";
static final String CONTINUATIONS_STORE_RENDER_ARGS = "__CONTINUATIONS_STORE_RENDER_ARGS";

static Object invokeWithContinuation(Method method, Object instance, Object[] realArgs) throws Exception {
// Callback case
Expand Down
17 changes: 17 additions & 0 deletions framework/src/play/mvc/Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -895,9 +895,25 @@ protected static void await(String timeout, F.Action0 callback) {
protected static void await(int millis) {
Request.current().isNew = false;
verifyContinuationsEnhancement();
storeOrRestoreDataStateForContinuations();
Continuation.suspend(millis);
}

private static void storeOrRestoreDataStateForContinuations() {

//renderArgs
Scope.RenderArgs renderArgs = (Scope.RenderArgs) Request.current().args.remove(ActionInvoker.CONTINUATIONS_STORE_RENDER_ARGS);
if ( renderArgs!=null ) {
//we are restoring after suspend
Scope.RenderArgs.current.set( renderArgs);
} else {
// we are capturing before suspend
Request.current().args.put(ActionInvoker.CONTINUATIONS_STORE_RENDER_ARGS, Scope.RenderArgs.current());
}


}

protected static void await(int millis, F.Action0 callback) {
Request.current().isNew = false;
Request.current().args.put(ActionInvoker.A, callback);
Expand All @@ -906,6 +922,7 @@ protected static void await(int millis, F.Action0 callback) {

@SuppressWarnings("unchecked")
protected static <T> T await(Future<T> future) {
storeOrRestoreDataStateForContinuations();
if(future != null) {
Request.current().args.put(ActionInvoker.F, future);
} else if(Request.current().args.containsKey(ActionInvoker.F)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,18 @@ protected static String useAwaitViaOtherClass() {
}


public static void usingRenderArgsAndAwait() {
renderArgs.put("a", "1");
int size = Scope.RenderArgs.current().data.size();
await(10);
renderArgs.put("b", "2");
size++;


boolean res = "1".equals(renderArgs.get("a")) && "2".equals(renderArgs.get("b")) && size == Scope.RenderArgs.current().data.size();

renderText( res );
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@
open('@{WithContinuations.useAwaitInWebSocketControllerWithoutContinuations()}')
assertTextPresent('failCount: 1')



open('@{WithContinuations.usingRenderArgsAndAwait()}')
assertBodyText('true')


#{/selenium}

0 comments on commit a6b830d

Please sign in to comment.