Example usage for io.netty.channel ChannelPromise awaitUninterruptibly

List of usage examples for io.netty.channel ChannelPromise awaitUninterruptibly

Introduction

In this page you can find the example usage for io.netty.channel ChannelPromise awaitUninterruptibly.

Prototype

boolean awaitUninterruptibly(long timeout, TimeUnit unit);

Source Link

Document

Waits for this future to be completed within the specified time limit without interruption.

Usage

From source file:ccwihr.client.t2.HttpResponseHandler.java

License:Apache License

/**
 * Wait (sequentially) for a time duration for each anticipated response
 *
 * @param timeout Value of time to wait for each response
 * @param unit Units associated with {@code timeout}
 * @see HttpResponseHandler#put(int, io.netty.channel.ChannelFuture, io.netty.channel.ChannelPromise)
 *//*  ww w  .  ja va2  s  .co m*/
public void awaitResponses(long timeout, TimeUnit unit) {
    Iterator<Entry<Integer, Entry<ChannelFuture, ChannelPromise>>> itr = streamidPromiseMap.entrySet()
            .iterator();
    while (itr.hasNext()) {
        Entry<Integer, Entry<ChannelFuture, ChannelPromise>> entry = itr.next();
        ChannelFuture writeFuture = entry.getValue().getKey();
        if (!writeFuture.awaitUninterruptibly(timeout, unit)) {
            throw new IllegalStateException("Timed out waiting to write for stream id " + entry.getKey());
        }
        if (!writeFuture.isSuccess()) {
            throw new RuntimeException(writeFuture.cause());
        }
        ChannelPromise promise = entry.getValue().getValue();
        if (!promise.awaitUninterruptibly(timeout, unit)) {
            throw new IllegalStateException("Timed out waiting for response on stream id " + entry.getKey());
        }
        if (!promise.isSuccess()) {
            throw new RuntimeException(promise.cause());
        }
        System.out.println("---Stream id: " + entry.getKey() + " received---");
        itr.remove();
    }
}

From source file:cn.jpush.api.common.connection.HttpResponseHandler.java

License:Apache License

/**
 * Wait (sequentially) for a time duration for each anticipated response
 *
 * @param timeout Value of time to wait for each response
 * @param unit Units associated with {@code timeout}
 * @see HttpResponseHandler#put(int, ChannelFuture, ChannelPromise)
 *//*  www  . j av a 2s  .c  o m*/
public void awaitResponses(long timeout, TimeUnit unit) {
    Iterator<Entry<Integer, Entry<ChannelFuture, ChannelPromise>>> itr = streamidPromiseMap.entrySet()
            .iterator();
    while (itr.hasNext()) {
        Entry<Integer, Entry<ChannelFuture, ChannelPromise>> entry = itr.next();
        ChannelFuture writeFuture = entry.getValue().getKey();
        if (!writeFuture.awaitUninterruptibly(timeout, unit)) {
            throw new IllegalStateException("Timed out waiting to write for stream id " + entry.getKey());
        }
        if (!writeFuture.isSuccess()) {
            throw new RuntimeException(writeFuture.cause());
        }
        ChannelPromise promise = entry.getValue().getValue();
        if (!promise.awaitUninterruptibly(timeout, unit)) {
            throw new IllegalStateException("Timed out waiting for response on stream id " + entry.getKey());
        }
        if (!promise.isSuccess()) {
            throw new RuntimeException(promise.cause());
        }
        System.out.println("---Stream id: " + entry.getKey() + " received---");
        System.out.println("---Stream id: " + promise.toString());
        itr.remove();
    }
}

From source file:http.HTTPResponseHandler.java

License:Open Source License

/**
 * Provide asynchronous response to HTTP2 request
 *
 * @param streamId StreamID//w w  w  . j  ava 2 s.c  o  m
 * @return Response string
 */
public String getResponse(int streamId) {

    String message = streamIdResponseMap.get(streamId);
    if (message != null) {
        return message;
    } else {
        Entry<ChannelFuture, ChannelPromise> channelFutureChannelPromiseEntry = streamIdPromiseMap
                .get(streamId);
        if (channelFutureChannelPromiseEntry != null) {
            ChannelFuture writeFuture = channelFutureChannelPromiseEntry.getKey();
            if (!writeFuture.awaitUninterruptibly(ServerUtil.HTTP2_RESPONSE_TIME_OUT,
                    ServerUtil.HTTP2_RESPONSE_TIME_UNIT)) {
                streamIdPromiseMap.remove(streamId);
                throw new IllegalStateException("Timed out waiting to write for stream id " + streamId);
            }
            if (!writeFuture.isSuccess()) {
                streamIdPromiseMap.remove(streamId);
                throw new RuntimeException(writeFuture.cause());
            }
            ChannelPromise promise = channelFutureChannelPromiseEntry.getValue();
            if (!promise.awaitUninterruptibly(ServerUtil.HTTP2_RESPONSE_TIME_OUT,
                    ServerUtil.HTTP2_RESPONSE_TIME_UNIT)) {
                streamIdPromiseMap.remove(streamId);
                throw new IllegalStateException("Timed out waiting for response on stream id " + streamId);
            }
            if (!promise.isSuccess()) {
                streamIdPromiseMap.remove(streamId);
                throw new RuntimeException(promise.cause());
            }
        }
    }
    return streamIdResponseMap.get(streamId);
}

From source file:http2.client.HttpResponseHandler.java

License:Apache License

/**
 * anticipated : ?//w  w w.  j ava 2 s  .co  m
 * Wait (sequentially) for a time duration for each anticipated response
 *
 * @param timeout Value of time to wait for each response
 * @param unit Units associated with {@code timeout}
 * @see HttpResponseHandler#put(int, ChannelFuture, ChannelPromise)
 */
public void awaitResponses(long timeout, TimeUnit unit) {
    Iterator<Entry<Integer, Entry<ChannelFuture, ChannelPromise>>> itr = streamidPromiseMap.entrySet()
            .iterator();
    while (itr.hasNext()) {
        Entry<Integer, Entry<ChannelFuture, ChannelPromise>> entry = itr.next();
        ChannelFuture writeFuture = entry.getValue().getKey();
        //
        if (!writeFuture.awaitUninterruptibly(timeout, unit)) {
            throw new IllegalStateException("Timed out waiting to write for stream id " + entry.getKey());
        }
        //
        if (!writeFuture.isSuccess()) {
            throw new RuntimeException(writeFuture.cause());
        }
        //
        ChannelPromise promise = entry.getValue().getValue();
        if (!promise.awaitUninterruptibly(timeout, unit)) {
            throw new IllegalStateException("Timed out waiting for response on stream id " + entry.getKey());
        }
        if (!promise.isSuccess()) {
            throw new RuntimeException(promise.cause());
        }
        System.out.println("---Stream id: " + entry.getKey() + " received---");
        itr.remove();
    }
}

From source file:io.aos.netty5.http2.client.HttpResponseHandler.java

License:Apache License

/**
 * Wait (sequentially) for a time duration for each anticipated response
 *
 * @param timeout Value of time to wait for each response
 * @param unit Units associated with {@code timeout}
 * @see {@link io.netty.example.http2.client.HttpResponseHandler#put put}
 *//* w  w  w  .  j  a  v  a2  s .co m*/
public void awaitResponses(long timeout, TimeUnit unit) {
    Iterator<Entry<Integer, ChannelPromise>> itr = streamidPromiseMap.entrySet().iterator();
    while (itr.hasNext()) {
        Entry<Integer, ChannelPromise> entry = itr.next();
        ChannelPromise promise = entry.getValue();
        if (!promise.awaitUninterruptibly(timeout, unit)) {
            throw new IllegalStateException("Timed out waiting for response on stream id " + entry.getKey());
        }
        if (!promise.isSuccess()) {
            throw new RuntimeException(promise.cause());
        }
        System.out.println("---Stream id: " + entry.getKey() + " received---");
        itr.remove();
    }
}

From source file:jmeter.plugins.http2.sampler.HttpResponseHandler.java

License:Apache License

/**
 * Wait (sequentially) for a time duration for each anticipated response
 *
 * @param timeout Value of time to wait for each response
 * @param unit Units associated with {@code timeout}
 * @see HttpResponseHandler#put(int, ChannelPromise)
 */// ww  w .  j  a  v  a2s .  c  o  m
public SortedMap<Integer, FullHttpResponse> awaitResponses(long timeout, TimeUnit unit) {
    Iterator<Entry<Integer, ChannelPromise>> itr = streamidPromiseMap.entrySet().iterator();

    while (itr.hasNext()) {
        Entry<Integer, ChannelPromise> entry = itr.next();
        ChannelPromise promise = entry.getValue();
        if (!promise.awaitUninterruptibly(timeout, unit)) {
            throw new IllegalStateException("Timed out waiting for response on stream id " + entry.getKey());
        }
        if (!promise.isSuccess()) {
            throw new RuntimeException(promise.cause());
        }
        System.out.println("---Stream id: " + entry.getKey() + " received---");
        itr.remove();
    }

    return streamidResponseMap;
}

From source file:org.ballerinalang.test.util.http2.HTTP2ResponseHandler.java

License:Open Source License

/**
 * Provide asynchronous response to HTTP2 request.
 *
 * @param streamId StreamID/*w  w w . j ava2  s  .  c  om*/
 * @return Response string
 */
public FullHttpResponse getResponse(int streamId) {

    FullHttpResponse message = streamIdResponseMap.get(streamId);
    if (message != null) {
        return message;
    } else {
        Entry<ChannelFuture, ChannelPromise> channelFutureChannelPromiseEntry = streamIdPromiseMap
                .get(streamId);
        if (channelFutureChannelPromiseEntry != null) {
            ChannelFuture writeFuture = channelFutureChannelPromiseEntry.getKey();
            if (!writeFuture.awaitUninterruptibly(TestConstant.HTTP2_RESPONSE_TIME_OUT,
                    TestConstant.HTTP2_RESPONSE_TIME_UNIT)) {
                streamIdPromiseMap.remove(streamId);
                throw new IllegalStateException("Timed out waiting to write for stream id " + streamId);
            }
            if (!writeFuture.isSuccess()) {
                streamIdPromiseMap.remove(streamId);
                throw new RuntimeException(writeFuture.cause());
            }
            ChannelPromise promise = channelFutureChannelPromiseEntry.getValue();
            if (!promise.awaitUninterruptibly(TestConstant.HTTP2_RESPONSE_TIME_OUT,
                    TestConstant.HTTP2_RESPONSE_TIME_UNIT)) {
                streamIdPromiseMap.remove(streamId);
                throw new IllegalStateException("Timed out waiting for response on stream id " + streamId);
            }
            if (!promise.isSuccess()) {
                streamIdPromiseMap.remove(streamId);
                throw new RuntimeException(promise.cause());
            }
        }
    }
    return streamIdResponseMap.get(streamId);
}

From source file:org.infinispan.rest.http2.HttpResponseHandler.java

License:Apache License

/**
 * Wait (sequentially) for a time duration for each anticipated response
 *
 * @param timeout Value of time to wait for each response
 * @param unit Units associated with {@code timeout}
 * @see HttpResponseHandler#put(int, io.netty.channel.ChannelFuture, io.netty.channel.ChannelPromise)
 *//*www.  j  a  v a  2s.co  m*/
public void awaitResponses(long timeout, TimeUnit unit) {
    Iterator<Entry<Integer, Entry<ChannelFuture, ChannelPromise>>> itr = streamidPromiseMap.entrySet()
            .iterator();
    while (itr.hasNext()) {
        Entry<Integer, Entry<ChannelFuture, ChannelPromise>> entry = itr.next();
        ChannelFuture writeFuture = entry.getValue().getKey();
        if (!writeFuture.awaitUninterruptibly(timeout, unit)) {
            throw new IllegalStateException("Timed out waiting to write for stream id " + entry.getKey());
        }
        if (!writeFuture.isSuccess()) {
            throw new RuntimeException(writeFuture.cause());
        }
        ChannelPromise promise = entry.getValue().getValue();
        if (!promise.awaitUninterruptibly(timeout, unit)) {
            throw new IllegalStateException("Timed out waiting for response on stream id " + entry.getKey());
        }
        if (!promise.isSuccess()) {
            throw new RuntimeException(promise.cause());
        }
        itr.remove();
    }
}

From source file:org.wso2.carbon.transport.http.netty.util.client.http2.HTTP2ResponseHandler.java

License:Open Source License

/**
 * Provide asynchronous response to HTTP2 request
 *
 * @param streamId StreamID/*from  ww w  .  ja v a 2 s  .c o  m*/
 * @return Response string
 */
public String getResponse(int streamId) {

    String message = streamIdResponseMap.get(streamId);
    if (message != null) {
        return message;
    } else {
        Entry<ChannelFuture, ChannelPromise> channelFutureChannelPromiseEntry = streamIdPromiseMap
                .get(streamId);
        if (channelFutureChannelPromiseEntry != null) {
            ChannelFuture writeFuture = channelFutureChannelPromiseEntry.getKey();
            if (!writeFuture.awaitUninterruptibly(TestUtil.HTTP2_RESPONSE_TIME_OUT,
                    TestUtil.HTTP2_RESPONSE_TIME_UNIT)) {
                streamIdPromiseMap.remove(streamId);
                throw new IllegalStateException("Timed out waiting to write for stream id " + streamId);
            }
            if (!writeFuture.isSuccess()) {
                streamIdPromiseMap.remove(streamId);
                throw new RuntimeException(writeFuture.cause());
            }
            ChannelPromise promise = channelFutureChannelPromiseEntry.getValue();
            if (!promise.awaitUninterruptibly(TestUtil.HTTP2_RESPONSE_TIME_OUT,
                    TestUtil.HTTP2_RESPONSE_TIME_UNIT)) {
                streamIdPromiseMap.remove(streamId);
                throw new IllegalStateException("Timed out waiting for response on stream id " + streamId);
            }
            if (!promise.isSuccess()) {
                streamIdPromiseMap.remove(streamId);
                throw new RuntimeException(promise.cause());
            }
        }
    }
    return streamIdResponseMap.get(streamId);
}

From source file:org.wso2.esb.integration.common.utils.clients.http2client.HttpResponseHandler.java

License:Open Source License

/**
 * Wait (sequentially) for a time duration for each anticipated response
 *
 * @param timeout Value of time to wait for each response
 * @param unit Units associated with {@code timeout}
 * @see HttpResponseHandler#put(int, io.netty.channel.ChannelFuture, io.netty.channel.ChannelPromise)
 *///from  www . ja  va2  s .c o  m
public void awaitResponses(long timeout, TimeUnit unit) {
    Iterator<Entry<Integer, Entry<ChannelFuture, ChannelPromise>>> itr = streamidPromiseMap.entrySet()
            .iterator();
    while (itr.hasNext()) {
        Entry<Integer, Entry<ChannelFuture, ChannelPromise>> entry = itr.next();
        ChannelFuture writeFuture = entry.getValue().getKey();
        if (!writeFuture.awaitUninterruptibly(timeout, unit)) {
            throw new IllegalStateException("Timed out waiting to write for stream id " + entry.getKey());
        }
        if (!writeFuture.isSuccess()) {
            throw new RuntimeException(writeFuture.cause());
        }
        ChannelPromise promise = entry.getValue().getValue();
        if (!promise.awaitUninterruptibly(timeout, unit)) {
            throw new IllegalStateException("Timed out waiting for response on stream id " + entry.getKey());
        }
        if (!promise.isSuccess()) {
            throw new RuntimeException(promise.cause());
        }
        log.debug("---Stream id: " + entry.getKey() + " received---");
        itr.remove();
    }
}