/** * Rns the server with the given {@code args}. * * @param args the arguments array */ public static void main(String[] args) { Service<Request, Response> client = ClientBuilder.safeBuild( ClientBuilder.get().codec(Http.get()).hosts("localhost:10000").hostConnectionLimit(1)); Request request = Request.apply("/"); Future<Response> response = client.apply(request); response.addEventListener( new FutureEventListener<Response>() { public void onSuccess(Response response) { System.out.println("received response: " + response); throw new RuntimeException(); } public void onFailure(Throwable cause) { System.out.println("failed with cause: " + cause); throw new RuntimeException(); } }); /* If the following compiles, variance annotations work (maybe!). */ Promise<List<Integer>> promise = new Promise<List<Integer>>(); promise.addEventListener( new FutureEventListener<Collection<Integer>>() { public void onSuccess(Collection<Integer> coll) {} public void onFailure(Throwable cause) {} }); /* The following should *not* compile. Uncomment to test manually. */ /* Promise<Collection<Integer>> badPromise = new Promise(); badPromise.addEventListener( new FutureEventListener<List<Integer>>() { public void onSuccess(List<Integer> coll) {} public void onFailure(Throwable cause) {} }); */ // New APIs com.twitter.finagle.Http.newClient(":80"); Client<Request, Response> newStyleClient = com.twitter.finagle.Http.client().withTls("foo.com"); }
void testParams() { StackClient<String, String> client = ClientBuilder.<String, String>stackClientOfCodec(null) .configured(new FailureDetector.Param(FailureDetectors.GLOBAL_FLAG_CONFIG).mk()) .configured(new FailureDetector.Param(FailureDetectors.NULL_CONFIG).mk()) .configured( new FailureDetector.Param( new FailureDetector.ThresholdConfig(Duration.Top(), 2, 5, Duration.Top())) .mk()); }
@Test public ReadHandle make() { ArrayList<SocketAddress> clusterMembers = new ArrayList<SocketAddress>(); clusterMembers.add(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0)); Var<Addr> cluster = Var$.MODULE$.apply(Addr.Bound$.MODULE$.apply(clusterMembers)); return MultiReader.apply(cluster, "the-queue") .clientBuilder( ClientBuilder.get() .codec(new Kestrel()) .hostConnectionLimit(1) .requestTimeout(Duration.fromTimeUnit(30, TimeUnit.SECONDS))) .build(); }