Java Code Examples for com.twitter.util.Promise#updateIfEmpty()

The following examples show how to use com.twitter.util.Promise#updateIfEmpty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FutureUtils.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
/**
 * Satisfy the <i>promise</i> with provided <i>cause</i>.
 *
 * @param promise promise to satisfy
 * @param cause cause to satisfy
 * @return true if successfully satisfy the future. false if the promise has been satisfied.
 */
public static <T> boolean setException(Promise<T> promise, Throwable cause) {
    boolean success = promise.updateIfEmpty(new Throw<T>(cause));
    if (!success) {
        logger.info("Result set multiple times. Value = '{}', New = 'Throw({})'",
                promise.poll(), cause);
    }
    return success;
}
 
Example 2
Source File: FutureUtils.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
/**
 * Satisfy the <i>promise</i> with provide value.
 * <p>If the promise was already satisfied, nothing will be changed.
 *
 * @param promise promise to satisfy
 * @param value value to satisfy
 * @return true if successfully satisfy the future. false if the promise has been satisfied.
 */
public static <T> boolean setValue(Promise<T> promise, T value) {
    boolean success = promise.updateIfEmpty(new Return<T>(value));
    if (!success) {
        logger.info("Result set multiple times. Value = '{}', New = 'Return({})'",
                promise.poll(), value);
    }
    return success;
}
 
Example 3
Source File: FutureUtils.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
/**
 * Satisfy the <i>promise</i> with provided <i>cause</i>.
 *
 * @param promise promise to satisfy
 * @param cause cause to satisfy
 * @return true if successfully satisfy the future. false if the promise has been satisfied.
 */
public static <T> boolean setException(Promise<T> promise, Throwable cause) {
    boolean success = promise.updateIfEmpty(new Throw<T>(cause));
    if (!success) {
        logger.info("Result set multiple times. Value = '{}', New = 'Throw({})'",
                promise.poll(), cause);
    }
    return success;
}
 
Example 4
Source File: TwitterFutureUtils.java    From distributedlog with Apache License 2.0 4 votes vote down vote up
public static <T> void setValue(Promise<T> promise, T value) {
    promise.updateIfEmpty(new Return<T>(value));
}
 
Example 5
Source File: FutureUtils.java    From distributedlog with Apache License 2.0 3 votes vote down vote up
/**
 * Satisfy the <i>promise</i> with provide value.
 *
 * <p>If the promise was already satisfied, nothing will be changed.
 *
 * @param promise promise to satisfy
 * @param value value to satisfy
 * @return true if successfully satisfy the future. false if the promise has been satisfied.
 */
public static <T> boolean setValue(Promise<T> promise, T value) {
    boolean success = promise.updateIfEmpty(new Return<T>(value));
    if (!success) {
        logger.info("Result set multiple times. Value = '{}', New = 'Return({})'",
                promise.poll(), value);
    }
    return success;
}