public static void main(String[] args) {
    SecurityService.FutureIface processor = new SecurityServiceImpl();

    final Server server =
        ServerBuilder.safeBuild(
            new SecurityService.FinagledService(processor, new TBinaryProtocol.Factory()),
            ServerBuilder.get()
                .name(NAME)
                .codec(ThriftServerFramedCodec.get())
                .bindTo(new InetSocketAddress(PORT)));

    System.out.println(String.format("Server %s running", NAME));

    Runtime.getRuntime()
        .addShutdownHook(
            new Thread() {
              public void run() {

                System.out.println("Closing server " + NAME);

                if (server != null) {
                  server.close(new Duration(TimeUnit.SECONDS.toNanos(10)));
                }
              }
            });
  }
Example #2
0
  public void start() {
    Stopwatch sw = new Stopwatch();
    sw.start();

    ServerCodecConfig codeConfig = new ServerCodecConfig(name, addr);
    ThriftServerFramedCodec codec =
        new ThriftServerFramedCodec(codeConfig, new TCompactProtocol.Factory());

    server =
        ServerBuilder.safeBuild(
            svc,
            ServerBuilder.get()
                .codec(codec)
                .name(name)
                .maxConcurrentRequests(maxConcurrentRequests)
                .bindTo(addr));
    sw.stop();
    logger.info(
        String.format("building finagle server took %s ms", sw.elapsed(TimeUnit.MILLISECONDS)));
  }
Example #3
0
  private static void runServer() {
    Service<Request, Response> service =
        new Service<Request, Response>() {
          public Future<Response> apply(Request request) {
            Response response = Response.apply();
            // Respond right away.
            response.setContent(ChannelBuffers.wrappedBuffer("yo".getBytes()));

            Future<Response> future = Future.value(response);
            return future;
          }
        };

    ServerBuilder.safeBuild(
        service,
        ServerBuilder.get()
            .codec(Http.get())
            .bindTo(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0))
            .name("HttpServer"));
  }