@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); }
@Override public Service<Req, Res> decorate(InetSocketAddress addr) { if (addr == null) { throw new IllegalArgumentException("address is null"); } ThriftClientFramedCodecFactory codec = new ThriftClientFramedCodecFactory(ClientId.current(), false, new TCompactProtocol.Factory()); Stopwatch sw = new Stopwatch(); sw.start(); Service<ThriftClientRequest, byte[]> client = ClientBuilder.safeBuild(ClientBuilder.get().hosts(addr) .codec(codec) .requestTimeout(timeout) .hostConnectionLimit(numThreads)); sw.stop(); logger.info(String.format("building finagle client took %s ms", sw.elapsedMillis())); return svc.wrap(client); }
@SuppressWarnings("unchecked") private ClientBuilder configureThriftMux(ClientBuilder builder, ClientId clientId, ClientConfig clientConfig) { if (clientConfig.getThriftMux()) { return builder.stack(ThriftMux.client().withClientId(clientId)); } else { return builder.codec(ThriftClientFramedCodec.apply(Option.apply(clientId))); } }
/** * initialise a {@link Client} instance using {@link ServiceFactory} from a * {@link ClientBuilder} * * @param addr */ public SimpleKestrelClient(InetSocketAddress addr) { final ClientBuilder<Command, Response, Yes, Yes, Yes> builder = ClientBuilder.get() .codec(Kestrel.get()) .hosts(addr) .hostConnectionLimit(1); final ServiceFactory<Command, Response> kestrelClientBuilder = ClientBuilder.safeBuildFactory(builder); client = Client.newInstance(kestrelClientBuilder); }
/** * initialise a {@link Client} instance using {@link ServiceFactory} from a * {@link ClientBuilder} * * @param addr */ public SimpleKestrelClient(InetSocketAddress addr) { final ClientBuilder<Command, Response, Yes, Yes, Yes> builder = ClientBuilder.get() .codec(Kestrel.get()) .hosts(addr) .hostConnectionLimit(1); final ServiceFactory<Command, Response> kestrelClientBuilder = ClientBuilder.safeBuildFactory(builder); client = Client.newInstance(kestrelClientBuilder); }
@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 static void main(String[] args) { Service<Command, Response> service = ClientBuilder.safeBuild( ClientBuilder .get() .hosts("localhost:11211") .hostConnectionLimit(1) .codec(new Memcached())); Client client = Client.newInstance(service); testClient(client); // cache client with cluster CachePoolCluster cluster = CachePoolClusterUtil.newStaticCluster( ImmutableSet.of(new CacheNode("localhost", 11211, 1))); ClientBuilder builder = ClientBuilder.get().codec(new Memcached(null)); com.twitter.finagle.memcached.Client memcachedClient = KetamaClientBuilder.get() .cachePoolCluster(cluster) .clientBuilder(builder) .build(); client = new ClientBase(memcachedClient); testClient(client); }
ServiceFactory<Command, Response> factory = ClientBuilder.safeBuildFactory(ClientBuilder.get() .codec(Kestrel.get()) .hosts(args[i]) .hostConnectionLimit(1));
public static void main(String[] args) throws Exception { Service<Command, Response> service = ClientBuilder.safeBuild( ClientBuilder .get() .hosts("localhost:11211") .hostConnectionLimit(1) .codec(new Memcached())); Client client = Client.newInstance(service); testClient(client); // cache client with cluster CachePoolCluster cluster = CachePoolClusterUtil.newStaticCluster( ImmutableSet.of(new CacheNode("localhost", 11211, 1))); ClientBuilder builder = ClientBuilder.get().codec(new Memcached(null)); com.twitter.finagle.memcachedx.Client memcachedClient = KetamaClientBuilder.get() .cachePoolCluster(cluster) .clientBuilder(builder) .build(); client = new ClientBase(memcachedClient); testClient(client); }
public static void main(String[] args) { Service<ThriftClientRequest, byte[]> client = ClientBuilder.safeBuild(ClientBuilder.get() .hosts(new InetSocketAddress(8080)) .codec(new ThriftClientFramedCodecFactory()) .hostConnectionLimit(100)); // IMPORTANT: this determines how many rpc's are sent in at once.
public PinLaterClient(String host, int port, int concurrency) { this.service = ClientBuilder.safeBuild( ClientBuilder.get() .hosts(new InetSocketAddress(host, port)) .codec(ThriftClientFramedCodec.apply(Option.apply(new ClientId("pinlaterclient")))) .hostConnectionLimit(concurrency) .tcpConnectTimeout(Duration.apply(2, TimeUnit.SECONDS)) .requestTimeout(Duration.apply(10, TimeUnit.SECONDS)) .retries(1)); this.iface = new PinLater.ServiceToClient(service, new TBinaryProtocol.Factory()); }
public PinLaterClient(ServerSet serverSet, int concurrency) { ZookeeperServerSetCluster cluster = new ZookeeperServerSetCluster(serverSet); ClientBuilder builder = ClientBuilder.get().cluster(cluster); this.service = ClientBuilder.safeBuild( builder.codec(ThriftClientFramedCodec.get()) .tcpConnectTimeout(Duration.apply(2, TimeUnit.SECONDS)) .requestTimeout(Duration.apply(10, TimeUnit.SECONDS)) .hostConnectionLimit(concurrency)); this.iface = new PinLater.ServiceToClient(service, new TBinaryProtocol.Factory()); }
.codec(ThriftClientFramedCodec.get()) .timeout(Duration.apply(2, TimeUnit.SECONDS)) .retries(4)
builder = builder.stack(ThriftMux.client().withClientId(clientId)); } else { builder = builder.codec(ThriftClientFramedCodec.apply(Option.apply(clientId)));