Example usage for io.netty.channel ChannelProgressiveFuture cause

List of usage examples for io.netty.channel ChannelProgressiveFuture cause

Introduction

In this page you can find the example usage for io.netty.channel ChannelProgressiveFuture cause.

Prototype

Throwable cause();

Source Link

Document

Returns the cause of the failed I/O operation if the I/O operation has failed.

Usage

From source file:com.addthis.hydra.query.tracker.TrackerHandler.java

License:Apache License

@Override
public void operationComplete(ChannelProgressiveFuture future) throws Exception {
    if (future == queryPromise) {
        // only care about operation progressed events for the gathering promise
        return;// w ww  . j  av  a  2s  . c o  m
    } else if (future == opPromise) {
        // tell aggregator about potential early termination from the op promise
        if (future.isSuccess()) {
            queryPromise.trySuccess();
        } else {
            queryPromise.tryFailure(opPromise.cause());
        }
        return;
    }
    // else the entire request is over; either from an error the last http write completing

    // tell the op processor about potential early termination (which may tell the gatherer in turn)
    if (future.isSuccess()) {
        opPromise.trySuccess();
    } else {
        opPromise.tryFailure(future.cause());
    }
    QueryEntry runE = queryTracker.running.remove(query.uuid());
    if (runE == null) {
        log.warn("failed to remove running for {}", query.uuid());
    }

    Promise<QueryEntryInfo> promise = new DefaultPromise<>(ctx.executor());
    queryEntry.getDetailedQueryEntryInfo(promise);
    QueryEntryInfo entryInfo = promise.getNow();
    if (entryInfo == null) {
        log.warn("Failed to get detailed status for completed query {}; defaulting to brief", query.uuid());
        entryInfo = queryEntry.getStat();
    }

    try {
        StringMapHelper queryLine = new StringMapHelper().put("query.path", query.getPaths()[0])
                .put("query.ops", Arrays.toString(opsLog)).put("sources", query.getParameter("sources"))
                .put("time", System.currentTimeMillis()).put("time.run", entryInfo.runTime)
                .put("job.id", query.getJob()).put("job.alias", query.getParameter("track.alias"))
                .put("query.id", query.uuid()).put("lines", entryInfo.lines)
                .put("sender", query.getParameter("sender"));
        if (!future.isSuccess()) {
            Throwable queryFailure = future.cause();
            queryLine.put("type", "query.error").put("error", queryFailure.getMessage());
            queryTracker.queryErrors.inc();
        } else {
            queryLine.put("type", "query.done");
            queryTracker.recentlyCompleted.put(query.uuid(), entryInfo);
        }
        queryTracker.log(queryLine);
        queryTracker.queryMeter.update(entryInfo.runTime, TimeUnit.MILLISECONDS);
    } catch (Exception e) {
        log.error("Error while doing record keeping for a query.", e);
    }
}

From source file:com.king.platform.net.http.netty.request.HttpClientRequestHandler.java

License:Apache License

private void writeHttpBody(final ChannelHandlerContext ctx, final HttpRequestContext httpRequestContext,
        HttpBody httpBody, final RequestEventBus requestEventBus) {
    try {//w w  w .jav a  2  s  .co m
        httpRequestContext.getTimeRecorder().startWriteBody();

        ChannelFuture channelFuture = httpBody.writeContent(ctx);

        channelFuture.addListener(new ChannelProgressiveFutureListener() {
            @Override
            public void operationProgressed(ChannelProgressiveFuture future, long progress, long total)
                    throws Exception {
                requestEventBus.triggerEvent(Event.TOUCH);
                requestEventBus.triggerEvent(Event.onWroteContentProgressed, progress, total);

            }

            @Override
            public void operationComplete(ChannelProgressiveFuture future) throws Exception {
                logger.trace("Wrote content operation completed, future: {}", future);

                if (future.isSuccess()) {
                    httpRequestContext.getTimeRecorder().completedWriteBody();
                    writeLastHttpContent(ctx, httpRequestContext, requestEventBus);
                    requestEventBus.triggerEvent(Event.TOUCH);

                } else {
                    logger.error("Failed to write http body, future: " + future);
                    requestEventBus.triggerEvent(Event.ERROR, httpRequestContext, future.cause());
                }
            }
        });

    } catch (IOException e) {
        requestEventBus.triggerEvent(Event.ERROR, httpRequestContext,
                new IOException("Failed to write body to server", e));
    }

}

From source file:org.asynchttpclient.netty.request.ProgressListener.java

License:Open Source License

@Override
public void operationComplete(ChannelProgressiveFuture cf) {
    // The write operation failed. If the channel was cached, it means it got asynchronously closed.
    // Let's retry a second time.
    if (!abortOnThrowable(cf.cause(), cf.channel())) {

        future.touch();/*from   w ww .  j  a v a2 s  .c o  m*/

        /**
         * We need to make sure we aren't in the middle of an authorization
         * process before publishing events as we will re-publish again the
         * same event after the authorization, causing unpredictable
         * behavior.
         */
        Realm realm = future.getRequest().getRealm() != null ? future.getRequest().getRealm()
                : config.getRealm();
        boolean startPublishing = future.isInAuth() || realm == null || realm.getUsePreemptiveAuth();

        if (startPublishing && asyncHandler instanceof ProgressAsyncHandler) {
            ProgressAsyncHandler<?> progressAsyncHandler = (ProgressAsyncHandler<?>) asyncHandler;
            if (notifyHeaders) {
                progressAsyncHandler.onHeadersWritten();
            } else {
                progressAsyncHandler.onContentWritten();
            }
        }
    }
}

From source file:org.asynchttpclient.netty.request.WriteProgressListener.java

License:Open Source License

@Override
public void operationComplete(ChannelProgressiveFuture cf) {
    operationComplete(cf.channel(), cf.cause());
}

From source file:org.asynchttpclient.providers.netty.request.ProgressListener.java

License:Apache License

@Override
public void operationComplete(ChannelProgressiveFuture cf) {
    // The write operation failed. If the channel was cached, it means it got asynchronously closed.
    // Let's retry a second time.

    if (!abortOnThrowable(cf.cause(), cf.channel())) {

        future.touch();/*from   w  ww. j  av  a  2 s .  c  o m*/

        /**
         * We need to make sure we aren't in the middle of an authorization process before publishing events as we
         * will re-publish again the same event after the authorization,
         * causing unpredictable behavior.
         */
        Realm realm = future.getRequest().getRealm() != null ? future.getRequest().getRealm()
                : config.getRealm();
        boolean startPublishing = future.isInAuth() || realm == null || realm.getUsePreemptiveAuth();

        if (startPublishing && asyncHandler instanceof ProgressAsyncHandler) {
            ProgressAsyncHandler<?> progressAsyncHandler = (ProgressAsyncHandler<?>) asyncHandler;
            if (notifyHeaders) {
                progressAsyncHandler.onHeaderWriteCompleted();
            } else {
                progressAsyncHandler.onContentWriteCompleted();
            }
        }
    }
}

From source file:org.asynchttpclient.providers.netty4.request.ProgressListener.java

License:Open Source License

@Override
public void operationComplete(ChannelProgressiveFuture cf) {
    // The write operation failed. If the channel was cached, it means it got asynchronously closed.
    // Let's retry a second time.
    if (!abortOnThrowable(cf.cause(), cf.channel())) {

        future.touch();/*from   w  ww  .j  a  v a  2 s . co  m*/

        /**
         * We need to make sure we aren't in the middle of an authorization
         * process before publishing events as we will re-publish again the
         * same event after the authorization, causing unpredictable
         * behavior.
         */
        Realm realm = future.getRequest().getRealm() != null ? future.getRequest().getRealm()
                : config.getRealm();
        boolean startPublishing = future.isInAuth() || realm == null || realm.getUsePreemptiveAuth();

        if (startPublishing && asyncHandler instanceof ProgressAsyncHandler) {
            ProgressAsyncHandler<?> progressAsyncHandler = (ProgressAsyncHandler<?>) asyncHandler;
            if (notifyHeaders) {
                progressAsyncHandler.onHeaderWriteCompleted();
            } else {
                progressAsyncHandler.onContentWriteCompleted();
            }
        }
    }
}