use of com.twitter.finagle.stats.StatsReceiver in project distributedlog by twitter.
the class MonitorServiceApp method runCmd.
void runCmd(CommandLine cmdline) throws IOException {
StatsProvider statsProvider = new NullStatsProvider();
if (cmdline.hasOption("p")) {
String providerClass = cmdline.getOptionValue("p");
statsProvider = ReflectionUtils.newInstance(providerClass, StatsProvider.class);
}
StatsReceiver statsReceiver = NullStatsReceiver.get();
final MonitorService monitorService = new MonitorService(getOptionalStringArg(cmdline, "u"), getOptionalStringArg(cmdline, "c"), getOptionalStringArg(cmdline, "s"), getOptionalIntegerArg(cmdline, "i"), getOptionalIntegerArg(cmdline, "d"), getOptionalStringArg(cmdline, "f"), getOptionalIntegerArg(cmdline, "n"), getOptionalIntegerArg(cmdline, "t"), getOptionalIntegerArg(cmdline, "hck"), getOptionalBooleanArg(cmdline, "hsci"), getOptionalBooleanArg(cmdline, "w"), statsReceiver, statsProvider);
monitorService.runServer();
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
logger.info("Closing monitor service.");
monitorService.close();
logger.info("Closed monitor service.");
}
});
try {
monitorService.join();
} catch (InterruptedException ie) {
logger.warn("Interrupted when waiting monitor service to be finished : ", ie);
}
}
use of com.twitter.finagle.stats.StatsReceiver 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);
}
use of com.twitter.finagle.stats.StatsReceiver in project distributedlog by twitter.
the class DistributedLogServerApp method runCmd.
private void runCmd(CommandLine cmdline) throws IllegalArgumentException, IOException, ConfigurationException {
final StatsReceiver statsReceiver = NullStatsReceiver.get();
Optional<String> confOptional = getOptionalStringArg(cmdline, "c");
DistributedLogConfiguration dlConf = new DistributedLogConfiguration();
if (confOptional.isPresent()) {
String configFile = confOptional.get();
try {
dlConf.loadConf(new File(configFile).toURI().toURL());
} catch (ConfigurationException e) {
throw new IllegalArgumentException("Failed to load distributedlog configuration from " + configFile + ".");
} catch (MalformedURLException e) {
throw new IllegalArgumentException("Failed to load distributedlog configuration from malformed " + configFile + ".");
}
}
// load the stats provider
final StatsProvider statsProvider = getOptionalStringArg(cmdline, "pd").transform(new Function<String, StatsProvider>() {
@Nullable
@Override
public StatsProvider apply(@Nullable String name) {
return ReflectionUtils.newInstance(name, StatsProvider.class);
}
}).or(new NullStatsProvider());
final DistributedLogServer server = DistributedLogServer.runServer(getOptionalStringArg(cmdline, "u"), confOptional, getOptionalStringArg(cmdline, "sc"), getOptionalIntegerArg(cmdline, "p"), getOptionalIntegerArg(cmdline, "sp"), getOptionalIntegerArg(cmdline, "si"), getOptionalBooleanArg(cmdline, "a"), getOptionalBooleanArg(cmdline, "mx"), statsReceiver, statsProvider);
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
logger.info("Closing DistributedLog Server.");
server.close();
logger.info("Closed DistributedLog Server.");
statsProvider.stop();
}
});
try {
server.join();
} catch (InterruptedException e) {
logger.warn("Interrupted when waiting distributedlog server to be finished : ", e);
}
logger.info("DistributedLog Service Interrupted.");
server.close();
logger.info("Closed DistributedLog Server.");
statsProvider.stop();
}
Aggregations