10
10
11
11
/**
12
12
* Asynchronous task created by {@link AsyncManager#register(Component, AsyncAction)} or
13
- * {@link AsyncManager#register(Component, boolean, AsyncAction)}.
13
+ * {@link AsyncManager#register(Component, AsyncAction)}.
14
14
*
15
15
* @author Artem Godin
16
16
* @see AsyncManager
@@ -22,24 +22,6 @@ public class AsyncTask {
22
22
AsyncTask () {
23
23
}
24
24
25
- /**
26
- * Perform command in {@code VaadinRequest} context. That requires the AsyncTask to be registered
27
- * in a polling mode. The command will be executed in PollEvent listener meaning that
28
- * {@link UI#accessSynchronously(Command)} is not needed.
29
- *
30
- * @param command Command to run
31
- */
32
- public void sync (Command command ) {
33
- if (parentUI == null ) return ;
34
- if (missedPolls == PUSH_ACTIVE ) {
35
- throw new IllegalStateException ("Sync is called but task is not in polling mode" );
36
- }
37
- if (syncCommand != null ) {
38
- throw new IllegalStateException ("Sync can be used only once" );
39
- }
40
- syncCommand = command ;
41
- }
42
-
43
25
/**
44
26
* Perform command in UI context. It uses {@link UI#accessSynchronously(Command)} internally.
45
27
*
@@ -49,9 +31,9 @@ public void push(Command command) {
49
31
if (parentUI == null ) return ;
50
32
if (missedPolls == PUSH_ACTIVE && parentUI .getPushConfiguration ().getPushMode () == PushMode .MANUAL ) {
51
33
parentUI .accessSynchronously (() -> {
52
- command .execute ();
34
+ command .execute ();
53
35
parentUI .push ();
54
- });
36
+ });
55
37
} else {
56
38
// Automatic -- changes will be pushed automatically
57
39
// Disabled -- we're using polling and this is called
@@ -107,11 +89,6 @@ private void execute() {
107
89
*/
108
90
private Registration beforeLeaveListenerRegistration ;
109
91
110
- /**
111
- * Command that needs to be executed in VaadinRequest context
112
- */
113
- private Command syncCommand ;
114
-
115
92
/**
116
93
* Number of poll events happened while action is executing, or {@link #PUSH_ACTIVE} if
117
94
* push is used for current task
@@ -121,13 +98,12 @@ private void execute() {
121
98
/**
122
99
* Register action
123
100
*
124
- * @param ui UI owning current view
125
- * @param forcePolling <tt>true</tt> if polling must be used
126
- * @param action Action
101
+ * @param ui UI owning current view
102
+ * @param action Action
127
103
*/
128
- void register (UI ui , Component component , boolean forcePolling , AsyncAction action ) {
104
+ void register (UI ui , Component component , AsyncAction action ) {
129
105
this .parentUI = ui ;
130
- if (! forcePolling && ui .getPushConfiguration ().getPushMode ().isEnabled ()) {
106
+ if (ui .getPushConfiguration ().getPushMode ().isEnabled ()) {
131
107
registerPush (component , action );
132
108
} else {
133
109
registerPoll (component , action );
@@ -191,9 +167,7 @@ private FutureTask<AsyncTask> createFutureTask(AsyncAction action) {
191
167
// Dump
192
168
AsyncManager .handleException (e );
193
169
} finally {
194
- if (syncCommand == null && !Thread .currentThread ().isInterrupted ()) {
195
- remove ();
196
- }
170
+ remove ();
197
171
}
198
172
}, this );
199
173
}
@@ -213,17 +187,19 @@ private synchronized void remove() {
213
187
AsyncManager .removeAsyncTask (parentUI , this );
214
188
// Polling interval needs to be adjusted if task is finished
215
189
try {
216
- parentUI .accessSynchronously (() -> AsyncManager .adjustPollingInterval (parentUI ));
190
+ parentUI .accessSynchronously (() -> {
191
+ AsyncManager .adjustPollingInterval (parentUI );
192
+
193
+ if (componentDetachListenerRegistration != null ) componentDetachListenerRegistration .remove ();
194
+ if (uiDetachListenerRegistration != null ) uiDetachListenerRegistration .remove ();
195
+ if (pollingListenerRegistration != null ) pollingListenerRegistration .remove ();
196
+ if (beforeLeaveListenerRegistration != null ) beforeLeaveListenerRegistration .remove ();
197
+ });
217
198
} catch (UIDetachedException ignore ) {
218
199
// ignore detached ui -- there will be no polling events for them anyway
219
200
}
220
201
221
202
parentUI = null ;
222
-
223
- if (componentDetachListenerRegistration != null ) componentDetachListenerRegistration .remove ();
224
- if (uiDetachListenerRegistration != null ) uiDetachListenerRegistration .remove ();
225
- if (pollingListenerRegistration != null ) pollingListenerRegistration .remove ();
226
- if (beforeLeaveListenerRegistration != null ) beforeLeaveListenerRegistration .remove ();
227
203
}
228
204
}
229
205
@@ -276,13 +252,5 @@ private void onPollEvent(PollEvent event) {
276
252
missedPolls ++;
277
253
AsyncManager .adjustPollingInterval (parentUI );
278
254
}
279
- if (syncCommand != null ) {
280
- try {
281
- syncCommand .execute ();
282
- } catch (RuntimeException e ) {
283
- AsyncManager .handleException (e );
284
- }
285
- remove ();
286
- }
287
255
}
288
256
}
0 commit comments