Example #1
0
 public void shutdown(Duration timeout) {
   if (server != null) {
     Future<?> future = server.close();
     try {
       if (timeout != null) {
         future.toJavaFuture().get(timeout.inMillis(), TimeUnit.MILLISECONDS);
       } else {
         future.toJavaFuture().get();
       }
     } catch (Exception e) {
       logger.error("problem shutting down", e);
     }
   }
 }
Example #2
0
  public void processLines(List<String> lines) {
    for (String line : lines) {
      Future<String> future = client.echo(line);
      future.addEventListener(
          new FutureEventListener<String>() {
            public void onSuccess(String msg) {
              System.out.println("response: " + msg);
            }

            public void onFailure(Throwable cause) {
              System.out.println("Error: " + cause);
            }
          });
    }
  }
Example #3
0
  /**
   * 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");
  }
 @Test(timeout = 60000)
 public void testConcurrentAllocation() throws Exception {
   String allcationPath = "/" + runtime.getMethodName();
   SimpleLedgerAllocator allocator = createAllocator(allcationPath);
   allocator.allocate();
   ZKTransaction txn1 = newTxn();
   Future<LedgerHandle> obtainFuture1 = allocator.tryObtain(txn1, NULL_LISTENER);
   ZKTransaction txn2 = newTxn();
   Future<LedgerHandle> obtainFuture2 = allocator.tryObtain(txn2, NULL_LISTENER);
   assertTrue(obtainFuture2.isDefined());
   assertTrue(obtainFuture2.isThrow());
   try {
     FutureUtils.result(obtainFuture2);
     fail(
         "Should fail the concurrent obtain since there is already a transaction obtaining the ledger handle");
   } catch (SimpleLedgerAllocator.ConcurrentObtainException cbe) {
     // expected
   }
 }
  @Override
  public Future<BoxedUnit> apply(Seq<Span> input) {
    List<io.zipkin.Span> spans =
        JavaConversions.asJavaCollection(input)
            .stream()
            .map(ScalaSpanStoreAdapter::invert)
            .filter(i -> i != null)
            .collect(toList());

    this.spanStore.accept(spans);
    return Future.Unit();
  }
 static Future<Seq<Seq<Span>>> toSeqFuture(List<List<io.zipkin.Span>> traces) {
   List<Seq<Span>> result = new ArrayList<>(traces.size());
   for (List<io.zipkin.Span> trace : traces) {
     List<Span> spans = new ArrayList<>(trace.size());
     for (io.zipkin.Span span : trace) {
       Span converted = convert(span);
       if (converted != null) {
         spans.add(converted);
       }
     }
     result.add(JavaConversions.asScalaBuffer(spans));
   }
   return Future.value(JavaConversions.asScalaBuffer(result).seq());
 }
 @Override
 public Future<String> apply(String req) {
   logger.debug("received : {}", req);
   return Future.value(req);
 }
 @Override
 public Future<Seq<String>> getAllServiceNames() {
   return Future.value(JavaConversions.asScalaBuffer(this.spanStore.getServiceNames()).seq());
 }