|
15 | 15 | import edu.umd.cs.findbugs.annotations.CheckForNull; |
16 | 16 | import edu.umd.cs.findbugs.annotations.NonNull; |
17 | 17 | import jakarta.inject.Inject; |
| 18 | +import java.util.function.Consumer; |
18 | 19 | import jenkins.model.queue.AsynchronousExecution; |
19 | 20 | import jenkins.util.Timer; |
20 | 21 |
|
@@ -168,32 +169,50 @@ public boolean blocksRestart() { |
168 | 169 | } |
169 | 170 |
|
170 | 171 | /** |
171 | | - * Apply the given function to all the active running {@link StepExecution}s in the system. |
| 172 | + * Apply the given action to all the active running {@link StepExecution}s in the system. |
172 | 173 | * |
173 | 174 | * @return |
174 | | - * Future object that signals when the function application is complete. |
| 175 | + * Future object that signals when the calls are complete. |
175 | 176 | * @see StepExecutionIterator |
176 | 177 | */ |
177 | | - public static ListenableFuture<?> applyAll(Function<StepExecution,Void> f) { |
| 178 | + public static ListenableFuture<?> acceptAll(Consumer<StepExecution> c) { |
178 | 179 | List<ListenableFuture<?>> futures = new ArrayList<>(); |
179 | | - for (StepExecutionIterator i : StepExecutionIterator.all()) |
180 | | - futures.add(i.apply(f)); |
| 180 | + for (StepExecutionIterator i : StepExecutionIterator.all()) { |
| 181 | + futures.add(i.accept(c)); |
| 182 | + } |
181 | 183 | return Futures.allAsList(futures); |
182 | 184 | } |
183 | 185 |
|
| 186 | + /** |
| 187 | + * @deprecated use {@link #acceptAll(Consumer)} |
| 188 | + */ |
| 189 | + @Deprecated |
| 190 | + public static ListenableFuture<?> applyAll(Function<StepExecution, Void> f) { |
| 191 | + return acceptAll(fromGuava(f)); |
| 192 | + } |
| 193 | + |
184 | 194 | /** |
185 | 195 | * Applies only to the specific subtypes. |
186 | 196 | */ |
187 | | - public static <T extends StepExecution> ListenableFuture<?> applyAll(final Class<T> type, final Function<T,Void> f) { |
188 | | - return applyAll(new Function<StepExecution, Void>() { |
189 | | - @Override |
190 | | - public Void apply(StepExecution e) { |
191 | | - if (type.isInstance(e)) |
192 | | - f.apply(type.cast(e)); |
193 | | - return null; |
| 197 | + public static <T extends StepExecution> ListenableFuture<?> acceptAll(Class<T> type, Consumer<T> c) { |
| 198 | + return acceptAll(e -> { |
| 199 | + if (type.isInstance(e)) { |
| 200 | + c.accept(type.cast(e)); |
194 | 201 | } |
195 | 202 | }); |
196 | 203 | } |
197 | 204 |
|
| 205 | + /** |
| 206 | + * @deprecated use {@link #acceptAll(Class, Consumer)} |
| 207 | + */ |
| 208 | + @Deprecated |
| 209 | + public static <T extends StepExecution> ListenableFuture<?> applyAll(Class<T> type, Function<T, Void> f) { |
| 210 | + return acceptAll(type, fromGuava(f)); |
| 211 | + } |
| 212 | + |
| 213 | + private static <T> Consumer<T> fromGuava(Function<T, Void> func) { |
| 214 | + return func::apply; |
| 215 | + } |
| 216 | + |
198 | 217 | private static final long serialVersionUID = 1L; |
199 | 218 | } |
0 commit comments