本文整理汇总了Java中io.grpc.ServerBuilder类的典型用法代码示例。如果您正苦于以下问题:Java ServerBuilder类的具体用法?Java ServerBuilder怎么用?Java ServerBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ServerBuilder类属于io.grpc包,在下文中一共展示了ServerBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: newInstance
import io.grpc.ServerBuilder; //导入依赖的package包/类
@Override
public Lifecycle newInstance(KernelContext kernelContext, final Dependencies dependencies) throws Throwable {
return new LifecycleAdapter() {
private Server server;
@Override
public void start() throws Throwable {
server = ServerBuilder.forPort(9999).addService(new Neo4jGRPCService(dependencies.getGraphDatabaseService())).build();
server.start();
System.out.println("Started gRPC Server.");
}
@Override
public void shutdown() throws Throwable {
server.shutdown();
}
};
}
示例2: start
import io.grpc.ServerBuilder; //导入依赖的package包/类
private void start() throws IOException {
/* The port on which the server should run */
int port = 50051;
server = ServerBuilder.forPort(port).addService(new GreeterImpl()).build().start();
logger.info("Server started, listening on " + port);
Runtime.getRuntime()
.addShutdownHook(
new Thread() {
@Override
public void run() {
// Use stderr here since the logger may have been reset by its JVM shutdown hook.
System.err.println("*** shutting down gRPC server since JVM is shutting down");
HelloWorldServer.this.stop();
System.err.println("*** server shut down");
}
});
}
示例3: start
import io.grpc.ServerBuilder; //导入依赖的package包/类
private void start() throws IOException {
/* The port on which the server should run */
int port = 8888;
server = ServerBuilder.forPort(port).addService(new GraphQlServiceImpl()).build().start();
logger.info("Server started, listening on " + port);
Runtime.getRuntime()
.addShutdownHook(
new Thread() {
@Override
public void run() {
// Use stderr here since the logger may have been reset by its JVM shutdown hook.
System.err.println("*** shutting down gRPC server since JVM is shutting down");
GraphQlGrpcServer.this.stop();
System.err.println("*** server shut down");
}
});
}
示例4: start
import io.grpc.ServerBuilder; //导入依赖的package包/类
public void start() throws IOException {
System.err.println("*** starting gRPC server...");
grpcServer = ServerBuilder.forPort(GRPC_PORT).addService(new GraphflowQueryImpl()).build().
start();
System.err.println("*** gRPC server running.");
System.err.println("*** starting http server...");
final PlanViewerHttpServer graphflowUIHttpServer = new PlanViewerHttpServer(GRPC_HOST,
GRPC_PORT);
graphflowUIHttpServer.start();
System.err.println("*** http server running.");
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
System.err.println("*** shutting down gRPC grpcServer...");
GraphflowServer.this.stop();
System.err.println("*** grpcServer shut down.");
}
});
}
示例5: start
import io.grpc.ServerBuilder; //导入依赖的package包/类
/**
* Starts the server
* @param port the port that the server listens to
* @throws IOException
* @throws IllegalStateException
*/
private void start(int port) throws IOException {
deviceHubImpl = new DeviceHubImpl();
try {
server = ServerBuilder.forPort(port).addService(deviceHubImpl).build().start();
} catch (IOException | IllegalStateException e) {
stop();
throw e;
}
logger.info("Server started, listening on " + port);
Runtime.getRuntime()
.addShutdownHook(
new Thread() {
@Override
public void run() {
// Use stderr here since the logger may have been reset by its JVM shutdown hook.
System.err.println("*** shutting down gRPC server since JVM is shutting down");
DeviceHubServer.this.stop();
System.err.println("*** server shut down");
}
});
}
示例6: start
import io.grpc.ServerBuilder; //导入依赖的package包/类
public void start(File certChainFile, File privateKeyFile, int port) throws IOException {
ServerBuilder builder = ServerBuilder.forPort(port).useTransportSecurity(certChainFile, privateKeyFile);
if (mAuthenticator != null) {
builder.addService(ServerInterceptors.intercept(
mSdkService, new AuthenticationInterceptor(this.mAuthenticator)));
} else {
builder.addService(mSdkService);
}
mGrpc = builder.build();
mGrpc.start();
}
示例7: serverRunsAndRespondsCorrectly
import io.grpc.ServerBuilder; //导入依赖的package包/类
@Test
public void serverRunsAndRespondsCorrectly() throws ExecutionException,
IOException,
InterruptedException,
TimeoutException {
final String name = UUID.randomUUID().toString();
Server server = ServerBuilder.forPort(9999)
.addService(new GreeterImpl())
.build();
server.start();
ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", server.getPort())
.usePlaintext(true)
.build();
GreeterGrpc8.GreeterCompletableFutureStub stub = GreeterGrpc8.newCompletableFutureStub(channel);
CompletableFuture<HelloResponse> response = stub.sayHello(HelloRequest.newBuilder().setName(name).build());
await().atMost(3, TimeUnit.SECONDS).until(() -> response.isDone() && response.get().getMessage().contains(name));
channel.shutdown();
channel.awaitTermination(1, TimeUnit.MINUTES);
channel.shutdownNow();
server.shutdown();
server.awaitTermination(1, TimeUnit.MINUTES);
server.shutdownNow();
}
示例8: SeldonGrpcServer
import io.grpc.ServerBuilder; //导入依赖的package包/类
@Autowired
public SeldonGrpcServer(PredictionService predictionService)
{
{ // setup the server port using the env vars
String engineServerPortString = System.getenv().get(ENGINE_SERVER_PORT_KEY);
if (engineServerPortString == null) {
logger.error("FAILED to find env var [{}], will use defaults for engine server port {}", ENGINE_SERVER_PORT_KEY,SERVER_PORT);
port = SERVER_PORT;
} else {
port = Integer.parseInt(engineServerPortString);
logger.info("FOUND env var [{}], will use engine server port {}", ENGINE_SERVER_PORT_KEY,port);
}
}
this.predictionService = predictionService;
server = ServerBuilder
.forPort(port)
.addService(new SeldonService(this))
.build();
}
示例9: main
import io.grpc.ServerBuilder; //导入依赖的package包/类
public static void main(String[] args) throws InterruptedException {
Server server=ServerBuilder.forPort(Config.getLocalPortProvider())
.addService(new AddService())
.build();
try {
server.start();
ProviderBootstrap.init();
server.awaitTermination();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
示例10: start
import io.grpc.ServerBuilder; //导入依赖的package包/类
private void start() throws IOException {
server = ServerBuilder.forPort(port)
.addService(bindService(new GreeterImpl()))
.build()
.start();
logger.info("Server started, listening on " + port);
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
// Use stderr here since the logger may have been reset by its JVM shutdown hook.
System.err.println("*** shutting down gRPC server since JVM is shutting down");
HelloJsonServer.this.stop();
System.err.println("*** server shut down");
}
});
}
示例11: start
import io.grpc.ServerBuilder; //导入依赖的package包/类
private void start() throws IOException {
server = ServerBuilder.forPort(port)
.addService(ServerInterceptors.intercept(new GreeterImpl(), new HeaderServerInterceptor()))
.build()
.start();
logger.info("Server started, listening on " + port);
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
// Use stderr here since the logger may have been reset by its JVM shutdown hook.
System.err.println("*** shutting down gRPC server since JVM is shutting down");
CustomHeaderServer.this.stop();
System.err.println("*** server shut down");
}
});
}
示例12: start
import io.grpc.ServerBuilder; //导入依赖的package包/类
private void start() throws IOException {
server = ServerBuilder.forPort(port)
.addService(new HelloServiceImpl())
.build()
.start();
System.out.println("service start...");
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
System.err.println("*** shutting down gRPC server since JVM is shutting down");
HelloWorldServer.this.stop();
System.err.println("*** server shut down");
}
});
}
示例13: main
import io.grpc.ServerBuilder; //导入依赖的package包/类
public static void main(String[] args) throws IOException, InterruptedException {
RxMetricsServiceGrpc.MetricsServiceImplBase service = new RxMetricsServiceGrpc.MetricsServiceImplBase() {
@Override
public Single<Streaming.Average> collect(Flowable<Streaming.Metric> request) {
return request.map(m -> m.getMetric())
.map(m -> new State(m, 1))
.reduce((a, b) -> new State(a.sum + b.sum, a.count + b.count))
.map(s -> Streaming.Average.newBuilder().setVal(s.sum / s.count).build())
.toSingle();
}
};
Server server = ServerBuilder.forPort(8080)
.addService(service)
.build();
server.start();
server.awaitTermination();
}
示例14: start
import io.grpc.ServerBuilder; //导入依赖的package包/类
private void start() throws Exception {
logger.info("Starting the grpc server");
server = ServerBuilder.forPort(port)
.addService(new GreeterImpl())
.build()
.start();
logger.info("Server started. Listening on port " + port);
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
System.err.println("*** JVM is shutting down. Turning off grpc server as well ***");
HelloWorldServer.this.stop();
System.err.println("*** shutdown complete ***");
}));
}
示例15: start
import io.grpc.ServerBuilder; //导入依赖的package包/类
private void start(int id) throws IOException {
server = ServerBuilder.forPort((port + id))
.addService(new GoogleImpl(id))
.build()
.start();
logger.info("Server started, listening on " + (port + id));
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
// Use stderr here since the logger may have been reset by its JVM shutdown hook.
System.err.println("*** shutting down gRPC server since JVM is shutting down");
Backend.this.stop();
System.err.println("*** server shut down");
}
});
}