From a6b830dcac3d6ae763ccc8902b2920559367a6a6 Mon Sep 17 00:00:00 2001 From: Morten Kjetland Date: Fri, 27 May 2011 17:01:28 +0200 Subject: [PATCH] [#873] now renderArgs survive await() --- framework/src/play/mvc/ActionInvoker.java | 3 ++- framework/src/play/mvc/Controller.java | 17 +++++++++++++++++ .../app/controllers/WithContinuations.java | 12 ++++++++++++ .../test/continuations.test.html | 4 ++-- 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/framework/src/play/mvc/ActionInvoker.java b/framework/src/play/mvc/ActionInvoker.java index 3d19da2536..cf64ed3641 100644 --- a/framework/src/play/mvc/ActionInvoker.java +++ b/framework/src/play/mvc/ActionInvoker.java @@ -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 diff --git a/framework/src/play/mvc/Controller.java b/framework/src/play/mvc/Controller.java index a85a93a846..573a4ac769 100644 --- a/framework/src/play/mvc/Controller.java +++ b/framework/src/play/mvc/Controller.java @@ -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); @@ -906,6 +922,7 @@ protected static void await(int millis, F.Action0 callback) { @SuppressWarnings("unchecked") protected static T await(Future future) { + storeOrRestoreDataStateForContinuations(); if(future != null) { Request.current().args.put(ActionInvoker.F, future); } else if(Request.current().args.containsKey(ActionInvoker.F)) { diff --git a/samples-and-tests/just-test-cases/app/controllers/WithContinuations.java b/samples-and-tests/just-test-cases/app/controllers/WithContinuations.java index 9af1a04df2..d8e411b3cc 100644 --- a/samples-and-tests/just-test-cases/app/controllers/WithContinuations.java +++ b/samples-and-tests/just-test-cases/app/controllers/WithContinuations.java @@ -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 ); + } } diff --git a/samples-and-tests/just-test-cases/test/continuations.test.html b/samples-and-tests/just-test-cases/test/continuations.test.html index 1fc4ee38c8..35dced743e 100644 --- a/samples-and-tests/just-test-cases/test/continuations.test.html +++ b/samples-and-tests/just-test-cases/test/continuations.test.html @@ -95,8 +95,8 @@ open('@{WithContinuations.useAwaitInWebSocketControllerWithoutContinuations()}') assertTextPresent('failCount: 1') - - + open('@{WithContinuations.usingRenderArgsAndAwait()}') + assertBodyText('true') #{/selenium} \ No newline at end of file