@SuppressWarnings("unchecked") private ClientBuilder setDefaultSettings(ClientBuilder builder) { return builder.name(clientName) .codec(ThriftClientFramedCodec.apply(Option.apply(clientId))) .failFast(false) .noFailureAccrual() // disable retries on finagle client builder, as there is only one host per finagle client // we should throw exception immediately on first failure, so DL client could quickly detect // failures and retry other proxies. .retries(1) .keepAlive(true); }
private ClientBuilder getDefaultClientBuilder() { return ClientBuilder.get() .hostConnectionLimit(1) .tcpConnectTimeout(Duration.fromMilliseconds(200)) .connectTimeout(Duration.fromMilliseconds(200)) .requestTimeout(Duration.fromSeconds(1)); }
static DistributedLogClientBuilder createDistributedLogClientBuilder(ServerSet serverSet) { return DistributedLogClientBuilder.newBuilder() .name("rebalancer_tool") .clientId(ClientId$.MODULE$.apply("rebalancer_tool")) .maxRedirects(2) .serverSet(serverSet) .clientBuilder(ClientBuilder.get() .connectionTimeout(Duration.fromSeconds(2)) .tcpConnectTimeout(Duration.fromSeconds(2)) .requestTimeout(Duration.fromSeconds(10)) .hostConnectionLimit(1) .hostConnectionCoresize(1) .keepAlive(true) .failFast(false)); }
.streamNameRegex(streamRegex) .handshakeWithClientInfo(handshakeWithClientInfo) .clientBuilder(ClientBuilder.get() .connectTimeout(Duration.fromSeconds(1)) .tcpConnectTimeout(Duration.fromSeconds(1)) .requestTimeout(Duration.fromSeconds(2)) .hostConnectionLimit(2) .hostConnectionCoresize(2) .keepAlive(true) .failFast(false)) .statsReceiver(monitorReceiver.scope("client")) .buildMonitorClient();
private DistributedLogClient buildDlogClient() { ClientBuilder clientBuilder = ClientBuilder.get() .hostConnectionLimit(hostConnectionLimit) .hostConnectionCoresize(hostConnectionCoreSize) .tcpConnectTimeout(Duration$.MODULE$.fromMilliseconds(200)) .connectTimeout(Duration$.MODULE$.fromMilliseconds(200)) .requestTimeout(Duration$.MODULE$.fromSeconds(10)) .sendBufferSize(sendBufferSize) .recvBufferSize(recvBufferSize);
.clientBuilder(ClientBuilder.get() .hostConnectionLimit(10) .hostConnectionCoresize(10) .tcpConnectTimeout(Duration$.MODULE$.fromSeconds(1)) .requestTimeout(Duration$.MODULE$.fromSeconds(2))) .redirectBackoffStartMs(100) .redirectBackoffMaxMs(500)
StatsLogger serviceStatsLogger = provider.getStatsLogger("service"); ServerBuilder serverBuilder = ServerBuilder.get() .name("DistributedLogServer") .codec(ThriftServerFramedCodec.get()) .reportTo(statsReceiver) .keepAlive(true) .bindTo(new InetSocketAddress(port)); 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())); Server server = ServerBuilder.safeBuild( new ClientIdRequiredFilter<byte[], byte[]>(serviceStatsReceiver).andThen( new StatsFilter<byte[], byte[]>(serviceStatsLogger).andThen(
@Override @SuppressWarnings("unchecked") public ProxyClient build(SocketAddress address) { Service<ThriftClientRequest, byte[]> client = ClientBuilder.safeBuildFactory( clientBuilder .hosts((InetSocketAddress) address) .reportTo(clientStats.getFinagleStatsReceiver(address)) ).toService(); DistributedLogService.ServiceIface service = new DistributedLogService.ServiceToClient(client, new TBinaryProtocol.Factory()); return new ProxyClient(address, client, service); }
static void closeServer(Pair<DistributedLogServiceImpl, Server> pair, long gracefulShutdownPeriod, TimeUnit timeUnit) { if (null != pair.getLeft()) { pair.getLeft().shutdown(); if (gracefulShutdownPeriod > 0) { try { timeUnit.sleep(gracefulShutdownPeriod); } catch (InterruptedException e) { logger.info("Interrupted on waiting service shutting down state propagated to all clients : ", e); } } } if (null != pair.getRight()) { logger.info("Closing dl thrift server."); pair.getRight().close(); logger.info("Closed dl thrift server."); } }
@SuppressWarnings("unchecked") private ClientBuilder enableThriftMux(ClientBuilder builder, ClientId clientId) { return builder.stack(ThriftMux.client().withClientId(clientId)); }
@Test(timeout = 60000) public void testBuildClientsFromSameBuilder() throws Exception { DistributedLogClientBuilder builder = DistributedLogClientBuilder.newBuilder() .name("build-clients-from-same-builder") .clientId(ClientId$.MODULE$.apply("test-builder")) .finagleNameStr("inet!127.0.0.1:7001") .streamNameRegex(".*") .handshakeWithClientInfo(true) .clientBuilder(ClientBuilder.get() .hostConnectionLimit(1) .connectTimeout(Duration.fromSeconds(1)) .tcpConnectTimeout(Duration.fromSeconds(1)) .requestTimeout(Duration.fromSeconds(10))); DistributedLogClient client1 = builder.build(); DistributedLogClient client2 = builder.build(); assertFalse(client1 == client2); } }
@Override protected int runCmd(CommandLine commandLine) throws Exception { try { parseCommandLine(commandLine); } catch (ParseException pe) { System.err.println("ERROR: failed to parse commandline : '" + pe.getMessage() + "'"); printUsage(); return -1; } DistributedLogClientBuilder clientBuilder = DistributedLogClientBuilder.newBuilder() .name("proxy_tool") .clientId(ClientId$.MODULE$.apply("proxy_tool")) .maxRedirects(2) .host(address) .clientBuilder(ClientBuilder.get() .connectionTimeout(Duration.fromSeconds(2)) .tcpConnectTimeout(Duration.fromSeconds(2)) .requestTimeout(Duration.fromSeconds(10)) .hostConnectionLimit(1) .hostConnectionCoresize(1) .keepAlive(true) .failFast(false)); Pair<DistributedLogClient, MonitorServiceClient> clientPair = ClientUtils.buildClient(clientBuilder); try { return runCmd(clientPair); } finally { clientPair.getLeft().close(); } }
@SuppressWarnings("unchecked") private ClientBuilder setDefaultSettings(ClientBuilder builder) { return builder.name(clientName) .failFast(false) .noFailureAccrual() // disable retries on finagle client builder, as there is only one host per finagle client // we should throw exception immediately on first failure, so DL client could quickly detect // failures and retry other proxies. .retries(1) .keepAlive(true); }
@Override public void run() { LOG.info("Try to shut down the server gracefully: {}", gracePeriod); server.close(gracePeriod); LOG.info("Finished server graceful shutdown"); } });
@SuppressWarnings("unchecked") private ClientBuilder enableThriftMux(ClientBuilder builder, ClientId clientId) { return builder.stack(ThriftMux.client().withClientId(clientId)); }
private ClientBuilder getDefaultClientBuilder() { return ClientBuilder.get() .hostConnectionLimit(1) .tcpConnectTimeout(Duration.fromMilliseconds(200)) .connectTimeout(Duration.fromMilliseconds(200)) .requestTimeout(Duration.fromSeconds(1)); }
.maxRedirects(2) .serverSet(serverSet.getServerSet()) .clientBuilder(ClientBuilder.get() .connectionTimeout(Duration.fromSeconds(2)) .tcpConnectTimeout(Duration.fromSeconds(2)) .requestTimeout(Duration.fromSeconds(10)) .hostConnectionLimit(1) .hostConnectionCoresize(1) .keepAlive(true) .failFast(false)) .build(); try {
@SuppressWarnings("unchecked") private ClientBuilder setDefaultSettings(ClientBuilder builder) { return builder.name(clientName) .codec(ThriftClientFramedCodec.apply(Option.apply(clientId))) .failFast(false) .noFailureAccrual() // disable retries on finagle client builder, as there is only one host per finagle client // we should throw exception immediately on first failure, so DL client could quickly detect // failures and retry other proxies. .retries(1) .keepAlive(true); }
public void shutdown(Duration timeout){ if (server != null) { Future<?> future = server.close(); if (timeout != null) { future.apply(timeout); } else { future.apply(); } } }
private ClientBuilder getDefaultClientBuilder(ClientConfig clientConfig) { ClientBuilder builder = ClientBuilder.get() .tcpConnectTimeout(Duration.fromMilliseconds(200)) .connectTimeout(Duration.fromMilliseconds(200)) .requestTimeout(Duration.fromSeconds(1)); if (!clientConfig.getThriftMux()) { builder = builder.hostConnectionLimit(1); } return builder; }