use of com.google.devtools.build.lib.server.RPCServer in project bazel by bazelbuild.
the class BlazeRuntime method createBlazeRPCServer.
/**
* Creates and returns a new Blaze RPCServer. Call {@link RPCServer#serve()} to start the server.
*/
private static RPCServer createBlazeRPCServer(Iterable<BlazeModule> modules, List<String> args) throws IOException, OptionsParsingException, AbruptExitException {
final RPCServer[] rpcServer = new RPCServer[1];
Runnable prepareForAbruptShutdown = new Runnable() {
@Override
public void run() {
rpcServer[0].prepareForAbruptShutdown();
}
};
BlazeRuntime runtime = newRuntime(modules, args, prepareForAbruptShutdown);
BlazeCommandDispatcher dispatcher = new BlazeCommandDispatcher(runtime);
CommandExecutor commandExecutor = new CommandExecutor(runtime, dispatcher);
BlazeServerStartupOptions startupOptions = runtime.getStartupOptionsProvider().getOptions(BlazeServerStartupOptions.class);
try {
// This is necessary so that Bazel kind of works during bootstrapping, at which time the
// gRPC server is not compiled in so that we don't need gRPC for bootstrapping.
Class<?> factoryClass = Class.forName("com.google.devtools.build.lib.server.GrpcServerImpl$Factory");
RPCServer.Factory factory = (RPCServer.Factory) factoryClass.getConstructor().newInstance();
rpcServer[0] = factory.create(commandExecutor, runtime.getClock(), startupOptions.commandPort, runtime.getWorkspace().getWorkspace(), runtime.getServerDirectory(), startupOptions.maxIdleSeconds);
return rpcServer[0];
} catch (ReflectiveOperationException | IllegalArgumentException e) {
throw new AbruptExitException("gRPC server not compiled in", ExitCode.BLAZE_INTERNAL_ERROR);
}
}
use of com.google.devtools.build.lib.server.RPCServer in project bazel by bazelbuild.
the class BlazeRuntime method serverMain.
/**
* A main method that does not send email. The return value indicates the desired exit status of
* the program.
*/
private static int serverMain(Iterable<BlazeModule> modules, OutErr outErr, String[] args) {
InterruptSignalHandler sigintHandler = null;
try {
final RPCServer blazeServer = createBlazeRPCServer(modules, Arrays.asList(args));
// Register the signal handler.
sigintHandler = new InterruptSignalHandler() {
@Override
public void run() {
LOG.severe("User interrupt");
blazeServer.interrupt();
}
};
blazeServer.serve();
return ExitCode.SUCCESS.getNumericExitCode();
} catch (OptionsParsingException e) {
outErr.printErr(e.getMessage());
return ExitCode.COMMAND_LINE_ERROR.getNumericExitCode();
} catch (IOException e) {
outErr.printErr("I/O Error: " + e.getMessage());
return ExitCode.BUILD_FAILURE.getNumericExitCode();
} catch (AbruptExitException e) {
outErr.printErr(e.getMessage());
return e.getExitCode().getNumericExitCode();
} finally {
if (sigintHandler != null) {
sigintHandler.uninstall();
}
}
}
Aggregations