forked from bazelbuild/bazel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor WorkRequestHandler to be an interface, of which Proto is one…
… implementation. This lays the foundation for WorkRequestHandler to be used for JSON workers as well. RELNOTES: None. PiperOrigin-RevId: 341078345
- Loading branch information
1 parent
50013dd
commit a4251ea
Showing
5 changed files
with
138 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/main/java/com/google/devtools/build/lib/worker/ProtoWorkerMessageProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright 2020 The Bazel Authors. All rights reserved. | ||
// | ||
// 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 com.google.devtools.build.lib.worker; | ||
|
||
import com.google.devtools.build.lib.worker.WorkerProtocol.WorkRequest; | ||
import com.google.devtools.build.lib.worker.WorkerProtocol.WorkResponse; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
|
||
/** Implementation of the Worker Protocol using Proto to communicate with Bazel. */ | ||
public final class ProtoWorkerMessageProcessor | ||
implements WorkRequestHandler.WorkerMessageProcessor { | ||
|
||
/** This worker's stdin. */ | ||
private final InputStream stdin; | ||
|
||
/** This worker's stdout. Only {@link WorkRequest}s should be written here. */ | ||
private final OutputStream stdout; | ||
|
||
/** Constructs a {@link WorkRequestHandler} that reads and writes Protocol Buffers. */ | ||
public ProtoWorkerMessageProcessor(InputStream stdin, OutputStream stdout) { | ||
this.stdin = stdin; | ||
this.stdout = stdout; | ||
} | ||
|
||
@Override | ||
public WorkRequest readWorkRequest() throws IOException { | ||
return WorkRequest.parseDelimitedFrom(stdin); | ||
} | ||
|
||
@Override | ||
public void writeWorkResponse(WorkResponse workResponse) throws IOException { | ||
try { | ||
workResponse.writeDelimitedTo(stdout); | ||
} finally { | ||
stdout.flush(); | ||
} | ||
} | ||
|
||
@Override | ||
public void close() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters