|
6 | 6 | * %%
|
7 | 7 | * Redistribution and use in source and binary forms, with or without
|
8 | 8 | * modification, are permitted provided that the following conditions are met:
|
9 |
| - * |
| 9 | + * |
10 | 10 | * 1. Redistributions of source code must retain the above copyright notice,
|
11 | 11 | * this list of conditions and the following disclaimer.
|
12 | 12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
|
13 | 13 | * this list of conditions and the following disclaimer in the documentation
|
14 | 14 | * and/or other materials provided with the distribution.
|
15 |
| - * |
| 15 | + * |
16 | 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
17 | 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
18 | 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
@@ -84,18 +84,19 @@ public class DefaultTask implements Task {
|
84 | 84 |
|
85 | 85 | /**
|
86 | 86 | * Creates a new task.
|
87 |
| - * |
| 87 | + * |
88 | 88 | * @param threadService Service to use for launching the task in its own
|
89 | 89 | * thread. Required.
|
90 | 90 | * @param eventService Service to use for reporting status updates as
|
91 | 91 | * {@link TaskEvent}s. May be null, in which case no events are
|
92 | 92 | * reported.
|
93 | 93 | */
|
94 | 94 | public DefaultTask(final ThreadService threadService,
|
95 |
| - final EventService eventService) |
| 95 | + final EventService eventService) |
96 | 96 | {
|
97 | 97 | this.threadService = threadService;
|
98 | 98 | this.eventService = eventService;
|
| 99 | + cancelCallBack = this::defaultCancelCallback; |
99 | 100 | }
|
100 | 101 |
|
101 | 102 | // -- Task methods --
|
@@ -176,17 +177,25 @@ public void cancel(final String reason) {
|
176 | 177 | canceled = true;
|
177 | 178 | cancelReason = reason;
|
178 | 179 | if (cancelCallBack!=null) cancelCallBack.run();
|
| 180 | + fireTaskEvent(); |
| 181 | + } |
| 182 | + |
| 183 | + void defaultCancelCallback() { |
179 | 184 | if (future!=null) {
|
180 | 185 | isDone = future.cancel(true);
|
181 | 186 | }
|
182 |
| - fireTaskEvent(); |
183 | 187 | }
|
184 | 188 |
|
185 | 189 | @Override
|
186 | 190 | public void setCancelCallBack(Runnable r) {
|
187 | 191 | this.cancelCallBack = r;
|
188 | 192 | }
|
189 | 193 |
|
| 194 | + @Override |
| 195 | + public Runnable getCancelCallBack() { |
| 196 | + return this.cancelCallBack; |
| 197 | + } |
| 198 | + |
190 | 199 | @Override
|
191 | 200 | public String getCancelReason() {
|
192 | 201 | return cancelReason;
|
|
0 commit comments