use of com.twitter.finagle.builder.ServerBuilder in project distributedlog by twitter.
the class DistributedLogServer method runServer.
static Pair<DistributedLogServiceImpl, Server> runServer(ServerConfiguration serverConf, DistributedLogConfiguration dlConf, DynamicDistributedLogConfiguration dynDlConf, URI dlUri, StreamPartitionConverter partitionConverter, StatsProvider provider, int port, CountDownLatch keepAliveLatch, StatsReceiver statsReceiver, boolean thriftmux, StreamConfigProvider streamConfProvider) throws IOException {
logger.info("Running server @ uri {}.", dlUri);
boolean perStreamStatsEnabled = serverConf.isPerStreamStatEnabled();
StatsLogger perStreamStatsLogger;
if (perStreamStatsEnabled) {
perStreamStatsLogger = provider.getStatsLogger("stream");
} else {
perStreamStatsLogger = NullStatsLogger.INSTANCE;
}
// dl service
DistributedLogServiceImpl dlService = new DistributedLogServiceImpl(serverConf, dlConf, dynDlConf, streamConfProvider, dlUri, partitionConverter, provider.getStatsLogger(""), perStreamStatsLogger, keepAliveLatch);
StatsReceiver serviceStatsReceiver = statsReceiver.scope("service");
StatsLogger serviceStatsLogger = provider.getStatsLogger("service");
ServerBuilder serverBuilder = ServerBuilder.get().name("DistributedLogServer").codec(ThriftServerFramedCodec.get()).reportTo(statsReceiver).keepAlive(true).bindTo(new InetSocketAddress(port));
if (thriftmux) {
logger.info("Using thriftmux.");
Tuple2<Transport.Liveness, Stack.Param<Transport.Liveness>> livenessParam = new Transport.Liveness(Duration.Top(), Duration.Top(), Option.apply((Object) Boolean.valueOf(true))).mk();
serverBuilder = serverBuilder.stack(ThriftMuxServer$.MODULE$.configured(livenessParam._1(), livenessParam._2()));
}
logger.info("DistributedLogServer running with the following configuration : \n{}", dlConf.getPropsAsString());
// starts dl server
Server server = ServerBuilder.safeBuild(new ClientIdRequiredFilter<byte[], byte[]>(serviceStatsReceiver).andThen(new StatsFilter<byte[], byte[]>(serviceStatsLogger).andThen(new DistributedLogService.Service(dlService, new TBinaryProtocol.Factory()))), serverBuilder);
logger.info("Started DistributedLog Server.");
return Pair.of(dlService, server);
}
Aggregations