|
1 | 1 | package org.jenkinsci.plugins.workflow.steps; |
2 | 2 |
|
| 3 | +import com.google.common.base.Function; |
3 | 4 | import com.google.common.util.concurrent.Futures; |
4 | 5 | import com.google.common.util.concurrent.ListenableFuture; |
5 | 6 | import java.io.Serializable; |
|
9 | 10 | import java.util.concurrent.Callable; |
10 | 11 | import java.util.concurrent.Future; |
11 | 12 | import java.util.concurrent.TimeUnit; |
12 | | -import java.util.function.Function; |
13 | 13 | import java.util.logging.Level; |
14 | 14 | import java.util.logging.Logger; |
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,51 +169,48 @@ 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 |
|
184 | 186 | /** |
185 | | - * @deprecated use {@link #applyAll(Function)} |
| 187 | + * @deprecated use {@link #acceptAll(Consumer)} |
186 | 188 | */ |
187 | 189 | @Deprecated |
188 | | - public static ListenableFuture<?> applyAll(com.google.common.base.Function<StepExecution, Void> f) { |
189 | | - return applyAll(fromGuava(f)); |
| 190 | + public static ListenableFuture<?> applyAll(Function<StepExecution, Void> f) { |
| 191 | + return acceptAll(fromGuava(f)); |
190 | 192 | } |
191 | 193 |
|
192 | 194 | /** |
193 | 195 | * Applies only to the specific subtypes. |
194 | 196 | */ |
195 | | - public static <T extends StepExecution> ListenableFuture<?> applyAll(final Class<T> type, final Function<T,Void> f) { |
196 | | - return applyAll(new Function<StepExecution, Void>() { |
197 | | - @Override |
198 | | - public Void apply(StepExecution e) { |
199 | | - if (type.isInstance(e)) |
200 | | - f.apply(type.cast(e)); |
201 | | - 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)); |
202 | 201 | } |
203 | 202 | }); |
204 | 203 | } |
205 | 204 |
|
206 | 205 | /** |
207 | | - * @deprecated use {@link #applyAll(Class, Function)} |
| 206 | + * @deprecated use {@link #acceptAll(Class, Consumer)} |
208 | 207 | */ |
209 | 208 | @Deprecated |
210 | | - public static <T extends StepExecution> ListenableFuture<?> applyAll( |
211 | | - final Class<T> type, final com.google.common.base.Function<T, Void> f) { |
212 | | - return applyAll(type, fromGuava(f)); |
| 209 | + public static <T extends StepExecution> ListenableFuture<?> applyAll(Class<T> type, Function<T, Void> f) { |
| 210 | + return acceptAll(type, fromGuava(f)); |
213 | 211 | } |
214 | 212 |
|
215 | | - private static <T, R> Function<T, R> fromGuava(com.google.common.base.Function<T, R> func) { |
| 213 | + private static <T> Consumer<T> fromGuava(Function<T, Void> func) { |
216 | 214 | return func::apply; |
217 | 215 | } |
218 | 216 |
|
|
0 commit comments