本文整理汇总了Java中io.netty.util.concurrent.Future.isSuccess方法的典型用法代码示例。如果您正苦于以下问题:Java Future.isSuccess方法的具体用法?Java Future.isSuccess怎么用?Java Future.isSuccess使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.netty.util.concurrent.Future
的用法示例。
在下文中一共展示了Future.isSuccess方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: add
import io.netty.util.concurrent.Future; //导入方法依赖的package包/类
public RFuture<Void> add(final ClientConnectionsEntry entry) {
final RPromise<Void> result = connectionManager.newPromise();
FutureListener<Void> listener = new FutureListener<Void>() {
AtomicInteger counter = new AtomicInteger(2);
@Override
public void operationComplete(Future<Void> future) throws Exception {
if (!future.isSuccess()) {
result.tryFailure(future.cause());
return;
}
if (counter.decrementAndGet() == 0) {
String addr = entry.getClient().getIpAddr();
ip2Entry.put(addr, entry);
result.trySuccess(null);
}
}
};
RFuture<Void> slaveFuture = slaveConnectionPool.add(entry);
slaveFuture.addListener(listener);
RFuture<Void> pubSubFuture = pubSubConnectionPool.add(entry);
pubSubFuture.addListener(listener);
return result;
}
示例2: operationComplete
import io.netty.util.concurrent.Future; //导入方法依赖的package包/类
@Override
public void operationComplete(Future<Channel> cf) throws Exception {
if (cf.isCancelled()) {
promise.cancel(true);
return;
}
if (!cf.isSuccess()) {
promise.completeExceptionally(cf.cause());
return;
}
Channel channel = cf.getNow();
promise.whenComplete((result, error) -> pool.release(channel));
try {
FastdfsOperation<T> fastdfsOperation = new FastdfsOperation<>(channel, requester, replier, promise);
if (LOG.isDebugEnabled()) {
LOG.debug("execute {}", fastdfsOperation);
}
fastdfsOperation.execute();
} catch (Exception e) {
promise.completeExceptionally(e);
}
}
示例3: operationComplete
import io.netty.util.concurrent.Future; //导入方法依赖的package包/类
@Override
public void operationComplete(Future<R> future) throws Exception {
if (future.isSuccess() && task.condition(future)) {
enqueueRunnable(new Runnable() {
@Override
public void run() {
try {
task.execute();
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
});
}
}
示例4: operationComplete
import io.netty.util.concurrent.Future; //导入方法依赖的package包/类
@Override
public void operationComplete(Future<T> future) throws Exception {
if (!future.isSuccess()) {
promise.tryFailure(future.cause());
return;
}
promise.trySuccess(future.getNow());
}
示例5: operationComplete
import io.netty.util.concurrent.Future; //导入方法依赖的package包/类
@Override
public void operationComplete(Future<Void> future) throws Exception {
if (!future.isSuccess()) {
res.tryFailure(future.cause());
return;
}
if (counter.decrementAndGet() == 0) {
res.trySuccess(null);
}
}
示例6: operationComplete
import io.netty.util.concurrent.Future; //导入方法依赖的package包/类
@Override
public void operationComplete(Future<Object> future) throws Exception {
if (!future.isSuccess()) {
connection.closeAsync();
connectionPromise.tryFailure(future.cause());
return;
}
if (commandsCounter.decrementAndGet() == 0) {
connectionPromise.trySuccess(connection);
}
}
示例7: readAllAsync
import io.netty.util.concurrent.Future; //导入方法依赖的package包/类
@Override
public <T, R> RFuture<Collection<R>> readAllAsync(RedisCommand<T> command, Object... params) {
final RPromise<Collection<R>> mainPromise = connectionManager.newPromise();
final Collection<MasterSlaveEntry> nodes = connectionManager.getEntrySet();
final List<R> results = new ArrayList<R>();
final AtomicInteger counter = new AtomicInteger(nodes.size());
FutureListener<R> listener = new FutureListener<R>() {
@Override
public void operationComplete(Future<R> future) throws Exception {
if (!future.isSuccess()) {
mainPromise.tryFailure(future.cause());
return;
}
R result = future.getNow();
if (result instanceof Collection) {
synchronized (results) {
results.addAll((Collection) result);
}
} else {
synchronized (results) {
results.add(result);
}
}
if (counter.decrementAndGet() == 0
&& !mainPromise.isDone()) {
mainPromise.trySuccess(results);
}
}
};
for (MasterSlaveEntry entry : nodes) {
RPromise<R> promise = connectionManager.newPromise();
promise.addListener(listener);
async(true, new NodeSource(entry), connectionManager.getCodec(), command, params, promise, 0);
}
return mainPromise;
}
示例8: allAsync
import io.netty.util.concurrent.Future; //导入方法依赖的package包/类
private <T, R> RFuture<R> allAsync(boolean readOnlyMode, RedisCommand<T> command, final SlotCallback<T, R> callback, Object... params) {
final RPromise<R> mainPromise = connectionManager.newPromise();
final Collection<MasterSlaveEntry> nodes = connectionManager.getEntrySet();
final AtomicInteger counter = new AtomicInteger(nodes.size());
FutureListener<T> listener = new FutureListener<T>() {
@Override
public void operationComplete(Future<T> future) throws Exception {
if (!future.isSuccess()) {
mainPromise.tryFailure(future.cause());
return;
}
if (callback != null) {
callback.onSlotResult(future.getNow());
}
if (counter.decrementAndGet() == 0) {
if (callback != null) {
mainPromise.trySuccess(callback.onFinish());
} else {
mainPromise.trySuccess(null);
}
}
}
};
for (MasterSlaveEntry entry : nodes) {
RPromise<T> promise = connectionManager.newPromise();
promise.addListener(listener);
async(readOnlyMode, new NodeSource(entry), connectionManager.getCodec(), command, params, promise, 0);
}
return mainPromise;
}
示例9: evalAllAsync
import io.netty.util.concurrent.Future; //导入方法依赖的package包/类
public <T, R> RFuture<R> evalAllAsync(boolean readOnlyMode, RedisCommand<T> command, final SlotCallback<T, R> callback, String script, List<Object> keys, Object... params) {
final RPromise<R> mainPromise = connectionManager.newPromise();
final Collection<MasterSlaveEntry> entries = connectionManager.getEntrySet();
final AtomicInteger counter = new AtomicInteger(entries.size());
FutureListener<T> listener = new FutureListener<T>() {
@Override
public void operationComplete(Future<T> future) throws Exception {
if (!future.isSuccess()) {
mainPromise.tryFailure(future.cause());
return;
}
callback.onSlotResult(future.getNow());
if (counter.decrementAndGet() == 0
&& !mainPromise.isDone()) {
mainPromise.trySuccess(callback.onFinish());
}
}
};
List<Object> args = new ArrayList<Object>(2 + keys.size() + params.length);
args.add(script);
args.add(keys.size());
args.addAll(keys);
args.addAll(Arrays.asList(params));
for (MasterSlaveEntry entry : entries) {
RPromise<T> promise = connectionManager.newPromise();
promise.addListener(listener);
async(readOnlyMode, new NodeSource(entry), connectionManager.getCodec(), command, args.toArray(), promise, 0);
}
return mainPromise;
}
示例10: invoke
import io.netty.util.concurrent.Future; //导入方法依赖的package包/类
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
Future<Channel> channelFuture = null;
try {
RequestWrapper requestWrapper = new RequestWrapper();
requestWrapper.setServiceName(name);
requestWrapper.setMethodName(method.getName());
requestWrapper.setParameters(args);
requestWrapper.setParamTypes(method.getParameterTypes());
requestWrapper.setRequestId(UUIDUtils.getRandomId());
System.out.println("send request: " + requestWrapper);
//获取一个可用的channel
channelFuture = connectionPool.acquire().sync();
if (!channelFuture.isSuccess()) {
throw new Exception("获取链接失败!");
}
Promise<ResponseWrapper> promise = eventExecutor.newPromise();
requestWrapper.setPromise(promise);
RpcClient.getRequestWrapperMap().put(requestWrapper.getRequestId(), promise);
//注意channel.write和context.write的区别
channelFuture.getNow().writeAndFlush(requestWrapper);
//如果是同步模式,return结果
return promise.get(5000L, TimeUnit.MILLISECONDS).getResult();
} finally {
if (channelFuture != null && channelFuture.isSuccess()) {
connectionPool.release(channelFuture.getNow());
}
}
}
示例11: startListenerHandle
import io.netty.util.concurrent.Future; //导入方法依赖的package包/类
private void startListenerHandle(Future future, SuccessfulListener listener) {
if (!future.isSuccess()) {
future.cause().printStackTrace();
}
if (listener != null) {
listener.onSuccess(future.isSuccess());
}
}
示例12: startListenerHandle
import io.netty.util.concurrent.Future; //导入方法依赖的package包/类
private void startListenerHandle(Future future, SuccessfulListener listener) {
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
if (!future.isSuccess()) future.cause().printStackTrace();
if (listener != null) listener.onSuccess(future.isSuccess());
}
示例13: operationComplete
import io.netty.util.concurrent.Future; //导入方法依赖的package包/类
@Override
public void operationComplete(Future<T> tFuture) throws Exception {
LOGGER.trace("Completing future from thread: {}", Thread.currentThread().getName());
if (tFuture.isSuccess()) {
complete(tFuture.getNow());
} else if (tFuture.isCancelled()) {
cancel(true);
} else {
completeExceptionally(tFuture.cause());
}
}
示例14: operationComplete
import io.netty.util.concurrent.Future; //导入方法依赖的package包/类
@Override
public void operationComplete(Future<Channel> cf) throws Exception {
if (cf.isCancelled()) {
promise.cancel(true);
return;
}
if (!cf.isSuccess()) {
promise.completeExceptionally(cf.cause());
return;
}
Channel channel = cf.getNow();
promise.whenComplete((result, error) -> pool.release(channel));
try {
FastdfsOperation<T> fastdfsOperation = new FastdfsOperation<>(channel, requestor,
replier, promise);
if (LOG.isDebugEnabled()) {
LOG.debug("execute {}", fastdfsOperation);
}
fastdfsOperation.execute();
} catch (Exception e) {
promise.completeExceptionally(e);
}
}
示例15: operationComplete
import io.netty.util.concurrent.Future; //导入方法依赖的package包/类
@Override
public void operationComplete(Future<? super Void> future) throws Exception {
if (!future.isSuccess()) {
logger.error("Unable to maintain connection {}. Closing connection.", connection.getName());
connection.close();
}
}