本文整理了Java中io.netty.util.concurrent.Promise.setFailure()
方法的一些代码示例,展示了Promise.setFailure()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Promise.setFailure()
方法的具体详情如下:
包路径:io.netty.util.concurrent.Promise
类名称:Promise
方法名:setFailure
[英]Marks this future as a failure and notifies all listeners. If it is success or failed already it will throw an IllegalStateException.
[中]将此未来标记为失败,并通知所有侦听器。如果它已经成功或失败,它将抛出一个非法的例外。
代码示例来源:origin: netty/netty
@Override
public void onTimeout(AcquireTask task) {
// Fail the promise as we timed out.
task.promise.setFailure(TIMEOUT_EXCEPTION);
}
};
代码示例来源:origin: redisson/redisson
@Override
public void onTimeout(AcquireTask task) {
// Fail the promise as we timed out.
task.promise.setFailure(TIMEOUT_EXCEPTION);
}
};
代码示例来源:origin: netty/netty
/**
* Fails the underlying {@link Promise} with the given cause and recycle this instance.
*/
public boolean failAndRecycle(Throwable cause) {
ReferenceCountUtil.release(msg);
if (promise != null) {
promise.setFailure(cause);
}
return recycle();
}
代码示例来源:origin: netty/netty
@Override
public void operationComplete(Future<InetAddress> future) throws Exception {
if (future.isSuccess()) {
promise.setSuccess(new InetSocketAddress(future.getNow(), unresolvedAddress.getPort()));
} else {
promise.setFailure(future.cause());
}
}
});
代码示例来源:origin: netty/netty
@Override
public void operationComplete(Future<List<InetAddress>> future) throws Exception {
if (future.isSuccess()) {
List<InetAddress> inetAddresses = future.getNow();
int numAddresses = inetAddresses.size();
if (numAddresses > 0) {
// if there are multiple addresses: we shall pick one by one
// to support the round robin distribution
promise.setSuccess(inetAddresses.get(randomIndex(numAddresses)));
} else {
promise.setFailure(new UnknownHostException(inetHost));
}
} else {
promise.setFailure(future.cause());
}
}
});
代码示例来源:origin: redisson/redisson
/**
* Fails the underlying {@link Promise} with the given cause and recycle this instance.
*/
public boolean failAndRecycle(Throwable cause) {
ReferenceCountUtil.release(msg);
if (promise != null) {
promise.setFailure(cause);
}
return recycle();
}
代码示例来源:origin: netty/netty
@Override
public void operationComplete(Future<List<InetAddress>> future) throws Exception {
if (future.isSuccess()) {
List<InetAddress> inetAddresses = future.getNow();
List<InetSocketAddress> socketAddresses =
new ArrayList<InetSocketAddress>(inetAddresses.size());
for (InetAddress inetAddress : inetAddresses) {
socketAddresses.add(new InetSocketAddress(inetAddress, unresolvedAddress.getPort()));
}
promise.setSuccess(socketAddresses);
} else {
promise.setFailure(future.cause());
}
}
});
代码示例来源:origin: netty/netty
@Override
protected void doResolveAll(String inetHost, Promise<List<InetAddress>> promise) throws Exception {
try {
promise.setSuccess(Arrays.asList(SocketUtils.allAddressesByName(inetHost)));
} catch (UnknownHostException e) {
promise.setFailure(e);
}
}
}
代码示例来源:origin: redisson/redisson
@Override
public void operationComplete(Future<InetAddress> future) throws Exception {
if (future.isSuccess()) {
promise.setSuccess(new InetSocketAddress(future.getNow(), unresolvedAddress.getPort()));
} else {
promise.setFailure(future.cause());
}
}
});
代码示例来源:origin: netty/netty
@Override
public Future<T> resolve(String inetHost, Promise<T> promise) {
checkNotNull(promise, "promise");
try {
doResolve(inetHost, promise);
return promise;
} catch (Exception e) {
return promise.setFailure(e);
}
}
代码示例来源:origin: netty/netty
@Override
public Future<List<T>> resolveAll(String inetHost, Promise<List<T>> promise) {
checkNotNull(promise, "promise");
try {
doResolveAll(inetHost, promise);
return promise;
} catch (Exception e) {
return promise.setFailure(e);
}
}
代码示例来源:origin: netty/netty
@Override
protected void doResolve(String inetHost, Promise<InetAddress> promise) throws Exception {
try {
promise.setSuccess(SocketUtils.addressByName(inetHost));
} catch (UnknownHostException e) {
promise.setFailure(e);
}
}
代码示例来源:origin: redisson/redisson
@Override
protected void doResolveAll(String inetHost, Promise<List<InetAddress>> promise) throws Exception {
try {
promise.setSuccess(Arrays.asList(SocketUtils.allAddressesByName(inetHost)));
} catch (UnknownHostException e) {
promise.setFailure(e);
}
}
}
代码示例来源:origin: netty/netty
@Override
public void operationComplete(Future<List<InetAddress>> future) throws Exception {
if (future.isSuccess()) {
List<InetAddress> inetAddresses = future.getNow();
if (!inetAddresses.isEmpty()) {
// create a copy to make sure that it's modifiable random access collection
List<InetAddress> result = new ArrayList<InetAddress>(inetAddresses);
// rotate by different distance each time to force round robin distribution
Collections.rotate(result, randomIndex(inetAddresses.size()));
promise.setSuccess(result);
} else {
promise.setSuccess(inetAddresses);
}
} else {
promise.setFailure(future.cause());
}
}
});
代码示例来源:origin: redisson/redisson
@Override
public Future<T> resolve(String inetHost, Promise<T> promise) {
checkNotNull(promise, "promise");
try {
doResolve(inetHost, promise);
return promise;
} catch (Exception e) {
return promise.setFailure(e);
}
}
代码示例来源:origin: redisson/redisson
@Override
public Future<SslContext> map(String input, Promise<SslContext> promise) {
final SslContext context;
try {
context = mapping.map(input);
} catch (Throwable cause) {
return promise.setFailure(cause);
}
return promise.setSuccess(context);
}
}
代码示例来源:origin: redisson/redisson
@Override
protected void doResolve(String inetHost, Promise<InetAddress> promise) throws Exception {
try {
promise.setSuccess(SocketUtils.addressByName(inetHost));
} catch (UnknownHostException e) {
promise.setFailure(e);
}
}
代码示例来源:origin: redisson/redisson
@Override
public Future<List<T>> resolveAll(String inetHost, Promise<List<T>> promise) {
checkNotNull(promise, "promise");
try {
doResolveAll(inetHost, promise);
return promise;
} catch (Exception e) {
return promise.setFailure(e);
}
}
代码示例来源:origin: netty/netty
private void doResolveRec(final String inetHost,
final Promise<T> promise,
final int resolverIndex,
Throwable lastFailure) throws Exception {
if (resolverIndex >= resolvers.length) {
promise.setFailure(lastFailure);
} else {
NameResolver<T> resolver = resolvers[resolverIndex];
resolver.resolve(inetHost).addListener(new FutureListener<T>() {
@Override
public void operationComplete(Future<T> future) throws Exception {
if (future.isSuccess()) {
promise.setSuccess(future.getNow());
} else {
doResolveRec(inetHost, promise, resolverIndex + 1, future.cause());
}
}
});
}
}
代码示例来源:origin: netty/netty
@Override
public Future<Channel> acquire(final Promise<Channel> promise) {
try {
if (executor.inEventLoop()) {
acquire0(promise);
} else {
executor.execute(new Runnable() {
@Override
public void run() {
acquire0(promise);
}
});
}
} catch (Throwable cause) {
promise.setFailure(cause);
}
return promise;
}
内容来源于网络,如有侵权,请联系作者删除!