A collection of APIs that manage reverse ajax APIs. See #withAllSessions for a menu of the various different with methods. The Runnables that are passed to the with methods may be executed any number of times between 0 (nothing passes the filter) 1 (where {@link Browser#getTar
| 39 | * @author Joe Walker [joe at getahead dot ltd dot uk] |
| 40 | */ |
| 41 | public class Browser |
| 42 | { |
| 43 | /** |
| 44 | * Execute some task (represented by a {@link Runnable}) and aim the output |
| 45 | * at all browser window open at all pages in this web application. |
| 46 | * It is likely that a more fine-grained broadcast method will be applicable |
| 47 | * to most situations. The other with* methods in this class provide extra |
| 48 | * ways to filter the set of pages to broadcast to. This option could be |
| 49 | * useful if all pages contain an 'update' area, or to broadcast status |
| 50 | * information: Window.alert("System reboot in 20mins. Please log off"); |
| 51 | * To send UI code to browser windows looking at a specific page, see the |
| 52 | * {@link #withPage} method. To send to a custom set of browser windows, |
| 53 | * see the {@link #withAllSessionsFiltered} method. To send to a specific |
| 54 | * session, use {@link #withSession}. |
| 55 | * @param task A code block to execute |
| 56 | */ |
| 57 | public static void withAllSessions(Runnable task) |
| 58 | { |
| 59 | withAllSessions(getServerContext(), task); |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * As {@link #withAllSessions(Runnable)}, but for use when there is more |
| 64 | * than one copy of DWR in the ServletContext. |
| 65 | * <p> |
| 66 | * For 99% of cases the former method will be much simpler to use. |
| 67 | * @param serverContext The specific DWR context in which to execute |
| 68 | */ |
| 69 | public static void withAllSessions(ServerContext serverContext, Runnable task) |
| 70 | { |
| 71 | currentServerContext.set(serverContext); |
| 72 | try { |
| 73 | TaskDispatcher taskDispatcher = TaskDispatcherFactory.get(serverContext); |
| 74 | taskDispatcher.dispatchTask(new AllScriptSessionFilter(), task); |
| 75 | } finally { |
| 76 | currentServerContext.remove(); |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Execute a task an send the output to a subset of the total list of users. |
| 82 | * The {@link ScriptSessionFilter} defines which subset. |
| 83 | * This method could be used to alert administrators wherever they are on a |
| 84 | * site about urgent action that need attention. |
| 85 | * @param filter Used to define the set of browser windows which should |
| 86 | * receive the update. |
| 87 | * @param task A code block to execute |
| 88 | */ |
| 89 | public static void withAllSessionsFiltered(ScriptSessionFilter filter, Runnable task) |
| 90 | { |
| 91 | withAllSessionsFiltered(getServerContext(), filter, task); |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * As {@link #withAllSessionsFiltered(ScriptSessionFilter, Runnable)}, but |
| 96 | * for use when there is more than one copy of DWR in the ServletContext. |
| 97 | * <p> |
| 98 | * For 99% of cases the former method will be much simpler to use. |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…