18
18
import com .google .devtools .build .lib .events .Reporter ;
19
19
import com .google .devtools .build .lib .vfs .Path ;
20
20
import com .google .devtools .build .lib .vfs .PathFragment ;
21
+ import java .util .Objects ;
21
22
import java .util .Optional ;
22
23
import java .util .TreeSet ;
23
24
import java .util .concurrent .atomic .AtomicInteger ;
@@ -35,23 +36,19 @@ class WorkerFactory extends BaseKeyedPooledObjectFactory<WorkerKey, Worker> {
35
36
// request_id (which is indistinguishable from 0 in proto3).
36
37
private static final AtomicInteger pidCounter = new AtomicInteger (1 );
37
38
38
- private WorkerOptions workerOptions ;
39
39
private final Path workerBaseDir ;
40
40
private Reporter reporter ;
41
+ private final boolean workerSandboxing ;
41
42
42
- public WorkerFactory (WorkerOptions workerOptions , Path workerBaseDir ) {
43
- this .workerOptions = workerOptions ;
43
+ public WorkerFactory (Path workerBaseDir , boolean workerSandboxing ) {
44
44
this .workerBaseDir = workerBaseDir ;
45
+ this .workerSandboxing = workerSandboxing ;
45
46
}
46
47
47
48
public void setReporter (Reporter reporter ) {
48
49
this .reporter = reporter ;
49
50
}
50
51
51
- public void setOptions (WorkerOptions workerOptions ) {
52
- this .workerOptions = workerOptions ;
53
- }
54
-
55
52
@ Override
56
53
public Worker create (WorkerKey key ) {
57
54
int workerId = pidCounter .getAndIncrement ();
@@ -60,7 +57,7 @@ public Worker create(WorkerKey key) {
60
57
workerBaseDir .getRelative (workTypeName + "-" + workerId + "-" + key .getMnemonic () + ".log" );
61
58
62
59
Worker worker ;
63
- boolean sandboxed = workerOptions . workerSandboxing || key .isSpeculative ();
60
+ boolean sandboxed = workerSandboxing || key .isSpeculative ();
64
61
if (sandboxed ) {
65
62
Path workDir = getSandboxedWorkerPath (key , workerId );
66
63
worker = new SandboxedWorker (key , workerId , workDir , logFile );
@@ -70,7 +67,7 @@ public Worker create(WorkerKey key) {
70
67
} else {
71
68
worker = new SingleplexWorker (key , workerId , key .getExecRoot (), logFile );
72
69
}
73
- if (workerOptions . workerVerbose ) {
70
+ if (reporter != null ) {
74
71
reporter .handle (
75
72
Event .info (
76
73
String .format (
@@ -91,9 +88,7 @@ Path getSandboxedWorkerPath(WorkerKey key, int workerId) {
91
88
.getRelative (workspaceName );
92
89
}
93
90
94
- /**
95
- * Use the DefaultPooledObject implementation.
96
- */
91
+ /** Use the DefaultPooledObject implementation. */
97
92
@ Override
98
93
public PooledObject <Worker > wrap (Worker worker ) {
99
94
return new DefaultPooledObject <>(worker );
@@ -102,7 +97,7 @@ public PooledObject<Worker> wrap(Worker worker) {
102
97
/** When a worker process is discarded, destroy its process, too. */
103
98
@ Override
104
99
public void destroyObject (WorkerKey key , PooledObject <Worker > p ) {
105
- if (workerOptions . workerVerbose ) {
100
+ if (reporter != null ) {
106
101
int workerId = p .getObject ().getWorkerId ();
107
102
reporter .handle (
108
103
Event .info (
@@ -122,7 +117,7 @@ public boolean validateObject(WorkerKey key, PooledObject<Worker> p) {
122
117
Worker worker = p .getObject ();
123
118
Optional <Integer > exitValue = worker .getExitValue ();
124
119
if (exitValue .isPresent ()) {
125
- if (workerOptions . workerVerbose && worker .diedUnexpectedly ()) {
120
+ if (reporter != null && worker .diedUnexpectedly ()) {
126
121
String msg =
127
122
String .format (
128
123
"%s %s (id %d) has unexpectedly died with exit code %d." ,
@@ -140,7 +135,7 @@ public boolean validateObject(WorkerKey key, PooledObject<Worker> p) {
140
135
boolean filesChanged =
141
136
!key .getWorkerFilesCombinedHash ().equals (worker .getWorkerFilesCombinedHash ());
142
137
143
- if (workerOptions . workerVerbose && reporter != null && filesChanged ) {
138
+ if (reporter != null && filesChanged ) {
144
139
StringBuilder msg = new StringBuilder ();
145
140
msg .append (
146
141
String .format (
@@ -167,4 +162,21 @@ public boolean validateObject(WorkerKey key, PooledObject<Worker> p) {
167
162
168
163
return !filesChanged ;
169
164
}
165
+
166
+ @ Override
167
+ public boolean equals (Object o ) {
168
+ if (this == o ) {
169
+ return true ;
170
+ }
171
+ if (!(o instanceof WorkerFactory )) {
172
+ return false ;
173
+ }
174
+ WorkerFactory that = (WorkerFactory ) o ;
175
+ return workerSandboxing == that .workerSandboxing && workerBaseDir .equals (that .workerBaseDir );
176
+ }
177
+
178
+ @ Override
179
+ public int hashCode () {
180
+ return Objects .hash (workerBaseDir , workerSandboxing );
181
+ }
170
182
}
0 commit comments