update Launcher to start either rest or grpc server
package com.quorum.tessera;
import com.quorum.tessera.api.Tessera;
+import com.quorum.tessera.config.CommunicationType;
import com.quorum.tessera.config.Config;
import com.quorum.tessera.config.ServerConfig;
import com.quorum.tessera.config.cli.CliDelegate;
@@ -92,9 +93,6 @@ public class Launcher {
final RestServer restServer = RestServerFactory.create().createServer(serverUri, tessera, serverConfig);
- final Optional<GrpcServer> gRPCServer;
-
- if (Objects.nonNull(serverConfig.getGrpcPort())) {
final Set<Object> gRPCBeans =
tessera.getSingletons()
.stream()
@@ -103,18 +101,18 @@ public class Launcher {
.getName()
.startsWith("com.quorum.tessera.api.grpc"))
.collect(Collectors.toSet());
- gRPCServer = Optional.of(
- GrpcServerFactory.create().createGRPCServer(serverUri, serverConfig.getGrpcPort(), gRPCBeans));
- } else {
- gRPCServer = Optional.empty();
- }
+ final GrpcServer gRPCServer = GrpcServerFactory.create()
+ .createGRPCServer(serverUri, serverConfig.getPort(), gRPCBeans);
CountDownLatch countDown = new CountDownLatch(1);
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
try {
+ if (serverConfig.getCommunicationType() == CommunicationType.GRPC) {
+ gRPCServer.stop();
+ } else {
restServer.stop();
- gRPCServer.ifPresent(GrpcServer::stop);
+ }
} catch (Exception ex) {
LOGGER.error(null, ex);
} finally {
@@ -122,8 +120,11 @@ public class Launcher {
}
}));
+ if (serverConfig.getCommunicationType() == CommunicationType.GRPC) {
+ gRPCServer.start();
+ } else {
restServer.start();
- gRPCServer.ifPresent(GrpcServer::start);
+ }
countDown.await();
}
