當前位置: 首頁>>代碼示例>>Java>>正文


Java Promise.cause方法代碼示例

本文整理匯總了Java中io.netty.util.concurrent.Promise.cause方法的典型用法代碼示例。如果您正苦於以下問題:Java Promise.cause方法的具體用法?Java Promise.cause怎麽用?Java Promise.cause使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在io.netty.util.concurrent.Promise的用法示例。


在下文中一共展示了Promise.cause方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: rejectPromise

import io.netty.util.concurrent.Promise; //導入方法依賴的package包/類
/**
 * Rejects the specified {@code promise} with the specified {@code cause}. If {@code promise} is done
 * already, this method logs a warning about the failure. Note that a {@link Promise} can be done already
 * even if you did not call this method in the following cases:
 * <ul>
 *   <li>Invocation timeout - The invocation associated with the {@link Promise} has been timed out.</li>
 *   <li>User error - A service implementation called any of the following methods more than once:
 *     <ul>
 *       <li>{@link #resolvePromise(Promise, Object)}</li>
 *       <li>{@link #rejectPromise(Promise, Throwable)}</li>
 *       <li>{@link Promise#setSuccess(Object)}</li>
 *       <li>{@link Promise#setFailure(Throwable)}</li>
 *       <li>{@link Promise#cancel(boolean)}</li>
 *     </ul>
 *   </li>
 * </ul>
 *
 * @deprecated Use {@link CompletableFuture} instead.
 */
@Deprecated
default void rejectPromise(Promise<?> promise, Throwable cause) {
    if (promise.tryFailure(cause)) {
        // Fulfilled successfully.
        return;
    }

    final Throwable firstCause = promise.cause();
    if (firstCause instanceof TimeoutException) {
        // Timed out already.
        return;
    }

    if (Exceptions.isExpected(cause)) {
        // The exception that was thrown after firstCause (often a transport-layer exception)
        // was a usual expected exception, not an error.
        return;
    }

    LoggerFactory.getLogger(RequestContext.class).warn(
            "Failed to reject a completed promise ({}) with {}", promise, cause, cause);
}
 
開發者ID:line,項目名稱:armeria,代碼行數:42,代碼來源:RequestContext.java

示例2: resolvePromise

import io.netty.util.concurrent.Promise; //導入方法依賴的package包/類
/**
 * Resolves the specified {@code promise} with the specified {@code result} so that the {@code promise} is
 * marked as 'done'. If {@code promise} is done already, this method does the following:
 * <ul>
 *   <li>Log a warning about the failure, and</li>
 *   <li>Release {@code result} if it is {@linkplain ReferenceCounted a reference-counted object},
 *       such as {@link ByteBuf} and {@link FullHttpResponse}.</li>
 * </ul>
 * Note that a {@link Promise} can be done already even if you did not call this method in the following
 * cases:
 * <ul>
 *   <li>Invocation timeout - The invocation associated with the {@link Promise} has been timed out.</li>
 *   <li>User error - A service implementation called any of the following methods more than once:
 *     <ul>
 *       <li>{@link #resolvePromise(Promise, Object)}</li>
 *       <li>{@link #rejectPromise(Promise, Throwable)}</li>
 *       <li>{@link Promise#setSuccess(Object)}</li>
 *       <li>{@link Promise#setFailure(Throwable)}</li>
 *       <li>{@link Promise#cancel(boolean)}</li>
 *     </ul>
 *   </li>
 * </ul>
 *
 * @deprecated Use {@link CompletableFuture} instead.
 */
@Deprecated
default void resolvePromise(Promise<?> promise, Object result) {
    @SuppressWarnings("unchecked")
    final Promise<Object> castPromise = (Promise<Object>) promise;

    if (castPromise.trySuccess(result)) {
        // Resolved successfully.
        return;
    }

    try {
        if (!(promise.cause() instanceof TimeoutException)) {
            // Log resolve failure unless it is due to a timeout.
            LoggerFactory.getLogger(RequestContext.class).warn(
                    "Failed to resolve a completed promise ({}) with {}", promise, result);
        }
    } finally {
        ReferenceCountUtil.safeRelease(result);
    }
}
 
開發者ID:line,項目名稱:armeria,代碼行數:46,代碼來源:RequestContext.java


注:本文中的io.netty.util.concurrent.Promise.cause方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。