-
Notifications
You must be signed in to change notification settings - Fork 4.6k
/
WorkerExecutor.java
104 lines (94 loc) · 3.99 KB
/
WorkerExecutor.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
* Copyright 2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.gradle.workers;
import org.gradle.api.Action;
import org.gradle.internal.service.scopes.Scopes;
import org.gradle.internal.service.scopes.ServiceScope;
/**
* Allows work to be submitted for asynchronous execution. This api allows for safe, concurrent execution of work items and enables:
*
* <ul>
* <li>Parallel execution of work items within a single task</li>
* <li>Execution in isolated contexts such as an isolated classloader or even a separate process</li>
* <li>Safe execution of multiple tasks in parallel</li>
* </ul>
*
* <p>Work should be submitted with a {@link WorkAction} class representing the implementation of the unit of work
* and an action to configure the parameters of the unit of work (via {@link WorkParameters}).
*
* <pre>
* workerExecutor.noIsolation().submit(MyWorkActionImpl.class) { MyWorkParameters parameters ->
* parameters.inputFile = project.file('foo')
* parameters.outputFile = project.layout.buildDirectory.file('bar')
* }
* </pre>
*
* <p>
* An instance of the executor can be injected into a task by annotating a public constructor or property getter method with {@code javax.inject.Inject}.
*
* @since 3.5
*/
@ServiceScope(Scopes.Project.class)
public interface WorkerExecutor {
/**
* Creates a {@link WorkQueue} to submit work for asynchronous execution with no isolation.
*
* @since 5.6
*/
WorkQueue noIsolation();
/**
* Creates a {@link WorkQueue} to submit work for asynchronous execution with an isolated classloader.
*
* @since 5.6
*/
WorkQueue classLoaderIsolation();
/**
* Creates a {@link WorkQueue} to submit work for asynchronous execution in a daemon process.
*
* Work will execute in an idle daemon, if available. If no idle daemons are available, a new daemon will be started.
*
* @since 5.6
*/
WorkQueue processIsolation();
/**
* Creates a {@link WorkQueue} to submit work for asynchronous execution with no isolation and the requirements specified in the supplied {@link WorkerSpec}.
*
* @since 5.6
*/
WorkQueue noIsolation(Action<? super WorkerSpec> action);
/**
* Creates a {@link WorkQueue} to submit work for asynchronous execution with an isolated classloader and the requirements specified in the supplied {@link ClassLoaderWorkerSpec}.
*
* @since 5.6
*/
WorkQueue classLoaderIsolation(Action<? super ClassLoaderWorkerSpec> action);
/**
* Creates a {@link WorkQueue} to submit work for asynchronous execution in a daemon process.
*
* Work will execute in an idle daemon matching the requirements specified in the supplied {@link ProcessWorkerSpec}, if available. If no idle daemons are available, a new daemon will be started.
*
* @since 5.6
*/
WorkQueue processIsolation(Action<? super ProcessWorkerSpec> action);
/**
* Blocks until all work associated with the current build operation is complete. Note that when using this method inside
* a task action, it will block completion of the task action until all submitted work is complete. This means that other
* tasks from the same project cannot be run in parallel while the task action is still executing.
*
* @throws WorkerExecutionException when a failure occurs while executing the work.
*/
void await() throws WorkerExecutionException;
}