本文整理匯總了Java中io.netty.util.concurrent.Promise.tryFailure方法的典型用法代碼示例。如果您正苦於以下問題:Java Promise.tryFailure方法的具體用法?Java Promise.tryFailure怎麽用?Java Promise.tryFailure使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類io.netty.util.concurrent.Promise
的用法示例。
在下文中一共展示了Promise.tryFailure方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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);
}
示例2: toBytes
import io.netty.util.concurrent.Promise; //導入方法依賴的package包/類
public static PromiseConverter<byte[]> toBytes(EventExecutor executor) {
return new PromiseConverter<byte[]>(executor) {
@Override
public FutureListener<Object> newListener(final Promise<byte[]> promise) {
return new FutureListener<Object>() {
@Override
public void operationComplete(Future<Object> future) throws Exception {
if (future.isSuccess()) {
Object resp = future.getNow();
if (resp instanceof RedisResponseException) {
promise.tryFailure((RedisResponseException) resp);
} else if (resp == RedisResponseDecoder.NULL_REPLY) {
promise.trySuccess(null);
} else {
promise.trySuccess((byte[]) resp);
}
} else {
promise.tryFailure(future.cause());
}
}
};
}
};
}
示例3: toDouble
import io.netty.util.concurrent.Promise; //導入方法依賴的package包/類
public static PromiseConverter<Double> toDouble(EventExecutor executor) {
return new PromiseConverter<Double>(executor) {
@Override
public FutureListener<Object> newListener(final Promise<Double> promise) {
return new FutureListener<Object>() {
@Override
public void operationComplete(Future<Object> future) throws Exception {
if (future.isSuccess()) {
Object resp = future.getNow();
if (resp instanceof RedisResponseException) {
promise.tryFailure((RedisResponseException) resp);
} else if (resp == RedisResponseDecoder.NULL_REPLY) {
promise.trySuccess(null);
} else {
promise.trySuccess(bytesToDouble((byte[]) resp));
}
} else {
promise.tryFailure(future.cause());
}
}
};
}
};
}
示例4: toLong
import io.netty.util.concurrent.Promise; //導入方法依賴的package包/類
public static PromiseConverter<Long> toLong(EventExecutor executor) {
return new PromiseConverter<Long>(executor) {
@Override
public FutureListener<Object> newListener(final Promise<Long> promise) {
return new FutureListener<Object>() {
@Override
public void operationComplete(Future<Object> future) throws Exception {
if (future.isSuccess()) {
Object resp = future.getNow();
if (resp instanceof RedisResponseException) {
promise.tryFailure((RedisResponseException) resp);
} else if (resp == RedisResponseDecoder.NULL_REPLY) {
promise.trySuccess(null);
} else {
promise.trySuccess((Long) resp);
}
} else {
promise.tryFailure(future.cause());
}
}
};
}
};
}
示例5: toObject
import io.netty.util.concurrent.Promise; //導入方法依賴的package包/類
public static PromiseConverter<Object> toObject(EventExecutor executor) {
return new PromiseConverter<Object>(executor) {
@Override
public FutureListener<Object> newListener(final Promise<Object> promise) {
return new FutureListener<Object>() {
@Override
public void operationComplete(Future<Object> future) throws Exception {
if (future.isSuccess()) {
Object resp = future.getNow();
if (resp instanceof RedisResponseException) {
promise.tryFailure((RedisResponseException) resp);
} else if (resp == RedisResponseDecoder.NULL_REPLY) {
promise.trySuccess(null);
} else {
promise.trySuccess(resp);
}
} else {
promise.tryFailure(future.cause());
}
}
};
}
};
}
示例6: toString
import io.netty.util.concurrent.Promise; //導入方法依賴的package包/類
public static PromiseConverter<String> toString(EventExecutor executor) {
return new PromiseConverter<String>(executor) {
@Override
public FutureListener<Object> newListener(final Promise<String> promise) {
return new FutureListener<Object>() {
@Override
public void operationComplete(Future<Object> future) throws Exception {
if (future.isSuccess()) {
Object resp = future.getNow();
if (resp instanceof RedisResponseException) {
promise.tryFailure((RedisResponseException) resp);
} else if (resp == RedisResponseDecoder.NULL_REPLY) {
promise.trySuccess(null);
} else {
promise.trySuccess(resp.toString());
}
} else {
promise.tryFailure(future.cause());
}
}
};
}
};
}
示例7: toVoid
import io.netty.util.concurrent.Promise; //導入方法依賴的package包/類
public static PromiseConverter<Void> toVoid(EventExecutor executor) {
return new PromiseConverter<Void>(executor) {
@Override
public FutureListener<Object> newListener(final Promise<Void> promise) {
return new FutureListener<Object>() {
@Override
public void operationComplete(Future<Object> future) throws Exception {
if (future.isSuccess()) {
Object resp = future.getNow();
if (resp instanceof RedisResponseException) {
promise.tryFailure((RedisResponseException) resp);
} else {
promise.trySuccess(null);
}
} else {
promise.tryFailure(future.cause());
}
}
};
}
};
}
示例8: notifyConnect
import io.netty.util.concurrent.Promise; //導入方法依賴的package包/類
private static void notifyConnect(ChannelFuture future, Promise<Channel> promise)
{
if (future.isSuccess()) {
Channel channel = future.channel();
if (!promise.trySuccess(channel)) {
// Promise was completed in the meantime (likely cancelled), just release the channel again
channel.close();
}
}
else {
promise.tryFailure(future.cause());
}
}
示例9: send
import io.netty.util.concurrent.Promise; //導入方法依賴的package包/類
private synchronized void send(ImapCommand imapCommand, Promise promise) {
if (connectionShutdown.get()) {
promise.tryFailure(new ConnectionClosedException("Cannot write to closed connection."));
return;
}
if ((currentCommandPromise != null && !currentCommandPromise.isDone()) || !isConnected()) {
PendingCommand pendingCommand = PendingCommand.newInstance(imapCommand, promise);
pendingWriteQueue.add(pendingCommand);
} else {
actuallySend(imapCommand, promise);
}
}
示例10: setPromiseResult
import io.netty.util.concurrent.Promise; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
private boolean setPromiseResult(Promise promise, Message.AddressedMessage message) {
final MessagePayload payload = message.getPayloadChecked(MessagePayload.class);
if (payload instanceof ErrorPayload) {
return promise.tryFailure((ErrorPayload) payload);
} else {
return promise.trySuccess(payload);
}
}
示例11: toList
import io.netty.util.concurrent.Promise; //導入方法依賴的package包/類
public static PromiseConverter<List<byte[]>> toList(EventExecutor executor) {
return new PromiseConverter<List<byte[]>>(executor) {
@Override
public FutureListener<Object> newListener(final Promise<List<byte[]>> promise) {
return new FutureListener<Object>() {
@SuppressWarnings("unchecked")
@Override
public void operationComplete(Future<Object> future) throws Exception {
if (future.isSuccess()) {
Object resp = future.getNow();
if (resp instanceof RedisResponseException) {
promise.tryFailure((RedisResponseException) resp);
} else if (resp == RedisResponseDecoder.NULL_REPLY) {
promise.trySuccess(null);
} else {
promise.trySuccess((List<byte[]>) resp);
}
} else {
promise.tryFailure(future.cause());
}
}
};
}
};
}
示例12: toBoolean
import io.netty.util.concurrent.Promise; //導入方法依賴的package包/類
public static PromiseConverter<Boolean> toBoolean(EventExecutor executor) {
return new PromiseConverter<Boolean>(executor) {
@Override
public FutureListener<Object> newListener(final Promise<Boolean> promise) {
return new FutureListener<Object>() {
@Override
public void operationComplete(Future<Object> future) throws Exception {
if (future.isSuccess()) {
Object resp = future.getNow();
if (resp instanceof RedisResponseException) {
promise.tryFailure((RedisResponseException) resp);
} else if (resp == RedisResponseDecoder.NULL_REPLY) {
promise.trySuccess(false);
} else if (resp instanceof String) {
promise.trySuccess(true);
} else {
promise.trySuccess(((Long) resp).intValue() != 0);
}
} else {
promise.tryFailure(future.cause());
}
}
};
}
};
}
示例13: toArrayScanResult
import io.netty.util.concurrent.Promise; //導入方法依賴的package包/類
public static PromiseConverter<ScanResult<byte[]>> toArrayScanResult(EventExecutor executor) {
return new PromiseConverter<ScanResult<byte[]>>(executor) {
@Override
public FutureListener<Object> newListener(final Promise<ScanResult<byte[]>> promise) {
return new FutureListener<Object>() {
@SuppressWarnings("unchecked")
@Override
public void operationComplete(Future<Object> future) throws Exception {
if (future.isSuccess()) {
Object resp = future.getNow();
if (resp instanceof RedisResponseException) {
promise.tryFailure((RedisResponseException) resp);
} else {
List<Object> list = (List<Object>) resp;
promise.trySuccess(new ScanResult<byte[]>((byte[]) list.get(0),
(List<byte[]>) list.get(1)));
}
} else {
promise.tryFailure(future.cause());
}
}
};
}
};
}
示例14: toHashScanResult
import io.netty.util.concurrent.Promise; //導入方法依賴的package包/類
public static PromiseConverter<ScanResult<HashEntry>> toHashScanResult(EventExecutor executor) {
return new PromiseConverter<ScanResult<HashEntry>>(executor) {
@Override
public FutureListener<Object> newListener(final Promise<ScanResult<HashEntry>> promise) {
return new FutureListener<Object>() {
@SuppressWarnings("unchecked")
@Override
public void operationComplete(Future<Object> future) throws Exception {
if (future.isSuccess()) {
Object resp = future.getNow();
if (resp instanceof RedisResponseException) {
promise.tryFailure((RedisResponseException) resp);
} else {
List<Object> list = (List<Object>) resp;
byte[] cursor = (byte[]) list.get(0);
List<byte[]> rawValueList = (List<byte[]>) list.get(1);
List<HashEntry> values = new ArrayList<>(rawValueList.size() / 2);
for (Iterator<byte[]> iter = rawValueList.iterator(); iter
.hasNext();) {
values.add(new HashEntry(iter.next(), iter.next()));
}
promise.trySuccess(new ScanResult<HashEntry>(cursor, values));
}
} else {
promise.tryFailure(future.cause());
}
}
};
}
};
}
示例15: toSortedSetScanResult
import io.netty.util.concurrent.Promise; //導入方法依賴的package包/類
public static PromiseConverter<ScanResult<SortedSetEntry>> toSortedSetScanResult(
EventExecutor executor) {
return new PromiseConverter<ScanResult<SortedSetEntry>>(executor) {
@Override
public FutureListener<Object> newListener(
final Promise<ScanResult<SortedSetEntry>> promise) {
return new FutureListener<Object>() {
@SuppressWarnings("unchecked")
@Override
public void operationComplete(Future<Object> future) throws Exception {
if (future.isSuccess()) {
Object resp = future.getNow();
if (resp instanceof RedisResponseException) {
promise.tryFailure((RedisResponseException) resp);
} else {
List<Object> list = (List<Object>) resp;
byte[] cursor = (byte[]) list.get(0);
List<byte[]> rawValueList = (List<byte[]>) list.get(1);
List<SortedSetEntry> values = new ArrayList<>(
rawValueList.size() / 2);
for (Iterator<byte[]> iter = rawValueList.iterator(); iter
.hasNext();) {
values.add(new SortedSetEntry(iter.next(), bytesToDouble(iter
.next())));
}
promise.trySuccess(new ScanResult<SortedSetEntry>(cursor, values));
}
} else {
promise.tryFailure(future.cause());
}
}
};
}
};
}