1818package io.bazel.worker
1919
2020import com.google.devtools.build.lib.worker.ProtoWorkerMessageProcessor
21- import com.google.devtools.build.lib.worker.WorkRequestHandler.WorkRequestCallback
22- import com.google.devtools.build.lib.worker.WorkRequestHandler.WorkRequestHandlerBuilder
23- import com.google.devtools.build.lib.worker.WorkerProtocol.WorkRequest
21+ import com.google.devtools.build.lib.worker.WorkRequestHandler
22+ import com.google.devtools.build.lib.worker.WorkerProtocol
2423import java.io.IOException
2524import java.io.PrintWriter
2625import java.time.Duration
@@ -36,17 +35,16 @@ class PersistentWorker : Worker {
3635 return WorkerContext .run {
3736 val realStdErr = System .err
3837 try {
39- val workerHandler =
40- WorkRequestHandlerBuilder (
41- WorkRequestCallback { request: WorkRequest , pw: PrintWriter ->
42- return @WorkRequestCallback doTask(
43- name = " request ${request.requestId} " ,
44- task = request.workTo(execute),
45- ).asResponse(pw)
46- },
47- realStdErr,
48- ProtoWorkerMessageProcessor (System .`in `, System .out ),
49- ).setCpuUsageBeforeGc(Duration .ofSeconds(10 )).build()
38+ val workerHandler: WorkRequestHandler = WorkRequestHandler .WorkRequestHandlerBuilder (
39+ WorkRequestHandler .WorkRequestCallback { request: WorkerProtocol .WorkRequest , pw: PrintWriter ->
40+ return @WorkRequestCallback doTask(
41+ name = " request ${request.requestId} " ,
42+ task = request.workTo(execute),
43+ ).asResponse(pw)
44+ },
45+ realStdErr,
46+ ProtoWorkerMessageProcessor (System .`in `, System .out ),
47+ ).setCpuUsageBeforeGc(Duration .ofSeconds(10 )).build()
5048 workerHandler.processRequests()
5149 } catch (e: IOException ) {
5250 this .error(e, { " Unknown IO exception" })
@@ -57,8 +55,11 @@ class PersistentWorker : Worker {
5755 }
5856 }
5957
60- private fun WorkRequest.workTo (execute : Work ): (sub: WorkerContext .TaskContext ) -> Status =
61- { ctx -> execute(ctx, argumentsList.toList()) }
58+ private fun WorkerProtocol.WorkRequest.workTo (execute : Work ): (sub: WorkerContext .TaskContext ) -> Status {
59+ return { ctx ->
60+ execute(ctx, argumentsList.toList())
61+ }
62+ }
6263
6364 private fun TaskResult.asResponse (pw : PrintWriter ): Int {
6465 pw.print (log.out .toString())
0 commit comments