MCPcopy Create free account
hub / github.com/directwebremoting/dwr / Callback

Class Callback

core/api/main/java/org/directwebremoting/ui/Callback.java:32–91  ·  view source on GitHub ↗

A way to call functions in JavaScript that return data using a reverse ajax proxy. @author Joe Walker [joe at getahead dot ltd dot uk]

Source from the content-addressed store, hash-verified

30 * @author Joe Walker [joe at getahead dot ltd dot uk]
31 */
32public abstract class Callback<T>
33{
34 /**
35 * Create a Callback from a DWR thread,
36 * i.e. where {@link WebContextFactory#get()} =! null
37 */
38 public Callback()
39 {
40 WebContext context = WebContextFactory.get();
41 if (context == null)
42 {
43 throw new IllegalStateException("Attempt to use Callback without any ScriptSessions, from a non DWR thread. There is nowhere for replies to go.");
44 }
45
46 sessions.add(context.getScriptSession());
47 }
48
49 /**
50 * Used when you need to specify the browser that will be providing the
51 * response
52 * @param session The browser to answer the question
53 */
54 public Callback(ScriptSession session)
55 {
56 sessions.add(session);
57 }
58
59 /**
60 * Used when you need to specify a group of browsers that will be providing
61 * the responses. The callback will be executed once per browser that
62 * replies.
63 * @param sessionList The browsers to answer the question
64 */
65 public Callback(Collection<ScriptSession> sessionList)
66 {
67 sessions.addAll(sessionList);
68 }
69
70 /**
71 * A browser has completed some remote call as has data for you
72 * @param data The data returned by the browser
73 */
74 public abstract void dataReturned(T data);
75
76 /**
77 * Accessor for the ScriptSessions that will reply to the question.
78 * This method is generally for DWR internal use, but only because it's
79 * unlikely to be useful to others.
80 * @return An immutable list of browsers that may reply to the question.
81 */
82 public Collection<ScriptSession> getScriptSessions()
83 {
84 return Collections.unmodifiableCollection(sessions);
85 }
86
87 /**
88 * We store the ScriptSessions that we send replies to, here.
89 */

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…