本文整理汇总了Java中io.grpc.netty.NettyServerBuilder.build方法的典型用法代码示例。如果您正苦于以下问题:Java NettyServerBuilder.build方法的具体用法?Java NettyServerBuilder.build怎么用?Java NettyServerBuilder.build使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.grpc.netty.NettyServerBuilder
的用法示例。
在下文中一共展示了NettyServerBuilder.build方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: startServer
import io.grpc.netty.NettyServerBuilder; //导入方法依赖的package包/类
public Server startServer() throws IOException {
ServerInterceptor headersInterceptor = new TracingMetadataUtils.ServerHeadersInterceptor();
NettyServerBuilder b =
NettyServerBuilder.forPort(workerOptions.listenPort)
.addService(ServerInterceptors.intercept(actionCacheServer, headersInterceptor))
.addService(ServerInterceptors.intercept(bsServer, headersInterceptor))
.addService(ServerInterceptors.intercept(casServer, headersInterceptor));
if (execServer != null) {
b.addService(ServerInterceptors.intercept(execServer, headersInterceptor));
b.addService(ServerInterceptors.intercept(watchServer, headersInterceptor));
} else {
logger.info("Execution disabled, only serving cache requests.");
}
Server server = b.build();
logger.log(INFO, "Starting gRPC server on port {0,number,#}.", workerOptions.listenPort);
server.start();
return server;
}
示例2: start
import io.grpc.netty.NettyServerBuilder; //导入方法依赖的package包/类
@EventListener(ContextStartedEvent.class)
public void start() throws Exception {
int port = properties.getPort();
NettyServerBuilder builder = NettyServerBuilder.forPort(port);
bindableServices.forEach(builder::addService);
if (properties.isSecure()) {
configureSsl(builder);
}
grpcServer = builder.build();
try {
grpcServer.start();
} catch (IOException e) {
if (e.getCause() instanceof BindException) {
throw new BindException("Address already in use: " + port);
}
throw new RuntimeException(e);
}
if (properties.getHealthCheckPort() > 0) {
log.info("Starting health check at port {}", properties.getHealthCheckPort());
healthCheckSocket = new ServerSocket(properties.getHealthCheckPort());
healthChecker = new Thread(this::healthCheck, "Health Checker");
healthChecker.setDaemon(true);
healthChecker.start();
}
log.info("Server started, GRPC API listening on {}", grpcServer.getPort());
String endpointUrl = properties.getEndpointUrl();
if (endpointUrl == null) {
log.warn("No endpoint url provided");
} else {
for (Address address : ethereumConfig.getAddresses()) {
ContractsManager contractManager = factory.getContractManager(address);
EndpointRegistry registry = new EndpointRegistry(contractManager.endpointRegistry());
registry.registerEndpoint(address, endpointUrl);
}
}
}
示例3: main
import io.grpc.netty.NettyServerBuilder; //导入方法依赖的package包/类
public static void main(String... args) throws Exception {
System.out.println("starting server");
String host = System.getProperty("host", "0.0.0.0");
int port = Integer.getInteger("port", 8001);
boolean useEpoll = Boolean.getBoolean("usePoll");
Class channel;
if (useEpoll) {
channel = EpollServerSocketChannel.class;
} else {
channel = NioServerSocketChannel.class;
}
ThreadFactory tf = new DefaultThreadFactory("server-elg-", true /*daemon */);
NioEventLoopGroup boss = new NioEventLoopGroup(1, tf);
NioEventLoopGroup worker = new NioEventLoopGroup(0, tf);
NettyServerBuilder builder =
NettyServerBuilder.forPort(port)
.bossEventLoopGroup(boss)
.workerEventLoopGroup(worker)
.channelType(channel)
.addService(new DefaultService())
.directExecutor()
.maxConcurrentCallsPerConnection(Runtime.getRuntime().availableProcessors() * 256)
.flowControlWindow(NettyChannelBuilder.DEFAULT_FLOW_CONTROL_WINDOW * 10);
io.grpc.Server start = builder.build();
start.start();
System.out.println("server started");
start.awaitTermination();
}
示例4: createServer
import io.grpc.netty.NettyServerBuilder; //导入方法依赖的package包/类
@Override
public Server createServer() {
NettyServerBuilder builder = NettyServerBuilder.forAddress(
new InetSocketAddress(InetAddresses.forString(getAddress()), getPort()));
Collection<GrpcServiceDefinition> definitions = discoverer.findGrpcServices();
for (GrpcServiceDefinition definition : definitions) {
ServiceDescriptor descriptor = definition.getService().bindService().getServiceDescriptor();
logger.info("Registered gRPC service: " + descriptor.getName()
+ ", bean: " + definition.getBeanName() + ", class: "
+ definition.getService().getClass().getName());
builder.addService(definition.getService());
}
return builder.build();
}