Example usage for io.netty.channel ChannelPromise await

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

Introduction

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

Prototype

@Override
    ChannelPromise await() throws InterruptedException;

Source Link

Usage

From source file:org.tinygroup.nettyremote.impl.ClientImpl.java

License:GNU General Public License

public void write(Object o) {
    if (o instanceof Event) {
        Event event = (Event) o;
        LOGGER.logMessage(LogLevel.DEBUG, "?:eventId:{},serviceId:{}", event.getEventId(),
                event.getServiceRequest().getServiceId());
    }//from w w  w  .  j ava 2s .  co m
    if (future == null || future.channel() == null) {
        throw new RuntimeException("");
    }
    ChannelFuture f = future.channel().writeAndFlush(o);
    if (f instanceof ChannelPromise) {
        ChannelPromise p = (ChannelPromise) f;
        try {
            p.await();
        } catch (InterruptedException e) {
            LOGGER.logMessage(LogLevel.WARN, "?");
        }
        if (p.isSuccess()) {
            LOGGER.logMessage(LogLevel.DEBUG, "??{}", p.isSuccess());
        } else {
            LOGGER.logMessage(LogLevel.WARN, "??false");
            throw new RuntimeException(p.cause());
        }

    }

}