@Override
 public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
   if (!(msg instanceof FullHttpRequest)) {
     Action<Object> subscriber = channelSubscriptions.get(ctx.channel());
     if (subscriber != null) {
       subscriber.execute(msg);
       return;
     }
   }
   super.channelRead(ctx, msg);
 }
Exemple #2
0
 default void build(Action<? super BaseDirBuilder> contents, Action<? super Path> use)
     throws Exception {
   try {
     use.execute(build(contents));
   } finally {
     close();
   }
 }
Exemple #3
0
 default Path build(Action<? super BaseDirBuilder> contents) throws Exception {
   contents.execute(this);
   return build();
 }
 @Override
 public RequestFixture registry(Action<? super RegistrySpec> action) throws Exception {
   action.execute(registryBuilder);
   return this;
 }
 @Override
 public RequestFixture serverConfig(Action<? super ServerConfigBuilder> action) throws Exception {
   serverConfigBuilder = ServerConfig.builder();
   action.execute(serverConfigBuilder);
   return this;
 }
 /**
  * Creates a URL by building a URL based on the public address.
  *
  * @param ctx the handling context at the time the public address is needed
  * @param action the additions to the public address
  * @return the built url
  * @throws Exception any thrown by {@code action}
  */
 default URI get(Context ctx, Action<? super HttpUrlBuilder> action) throws Exception {
   return action.with(builder(ctx)).build();
 }
  public ReceivedResponse request(URI uri, Duration duration, Action<? super RequestSpec> action)
      throws Throwable {
    CountDownLatch latch = new CountDownLatch(1);
    AtomicReference<ExecResult<ReceivedResponse>> result = new AtomicReference<>();

    try (ExecController execController = new DefaultExecController(2)) {
      execController
          .fork()
          .onComplete(e -> {})
          .start(
              e -> {
                HttpClient.httpClient(UnpooledByteBufAllocator.DEFAULT, Integer.MAX_VALUE)
                    .request(uri, action.prepend(s -> s.readTimeout(Duration.ofHours(1))))
                    .map(
                        response -> {
                          TypedData responseBody = response.getBody();
                          ByteBuf responseBodyBuffer = responseBody.getBuffer();
                          responseBodyBuffer =
                              Unpooled.unreleasableBuffer(responseBodyBuffer.retain());

                          return new DefaultReceivedResponse(
                              response.getStatus(),
                              response.getHeaders(),
                              new ByteBufBackedTypedData(
                                  responseBodyBuffer, responseBody.getContentType()));
                        })
                    .connect(
                        new Downstream<DefaultReceivedResponse>() {
                          @Override
                          public void success(DefaultReceivedResponse value) {
                            result.set(ExecResult.of(Result.success(value)));
                            latch.countDown();
                          }

                          @Override
                          public void error(Throwable throwable) {
                            result.set(ExecResult.of(Result.error(throwable)));
                            latch.countDown();
                          }

                          @Override
                          public void complete() {
                            result.set(ExecResult.complete());
                            latch.countDown();
                          }
                        });
              });

      try {
        if (!latch.await(duration.toNanos(), TimeUnit.NANOSECONDS)) {
          TemporalUnit unit = duration.getUnits().get(0);
          throw new IllegalStateException(
              "Request to "
                  + uri
                  + " took more than "
                  + duration.get(unit)
                  + " "
                  + unit.toString()
                  + " to complete");
        }
      } catch (InterruptedException e) {
        throw Exceptions.uncheck(e);
      }

      return result.get().getValueOrThrow();
    }
  }