当前位置: 首页>>代码示例>>Java>>正文


Java Future.isSuccess方法代码示例

本文整理汇总了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;
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:25,代码来源:LoadBalancerManager.java

示例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);
    }
}
 
开发者ID:rodbate,项目名称:fastdfs-spring-boot,代码行数:29,代码来源:FastdfsExecutor.java

示例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);
                }
            }
        });
    }
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:16,代码来源:MapWriteBehindListener.java

示例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());
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:10,代码来源:TransferListener.java

示例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);
    }
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:11,代码来源:CountListener.java

示例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);
    }
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:12,代码来源:FutureConnectionListener.java

示例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;
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:40,代码来源:CommandAsyncService.java

示例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;
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:33,代码来源:CommandAsyncService.java

示例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;
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:34,代码来源:CommandAsyncService.java

示例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());
        }
    }
}
 
开发者ID:recklessMo,项目名称:nettyRpc,代码行数:30,代码来源:ClientInvocationHandler.java

示例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());
    }
}
 
开发者ID:bitkylin,项目名称:ClusterDeviceControlPlatform,代码行数:9,代码来源:NettyServer.java

示例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());
}
 
开发者ID:bitkylin,项目名称:ClusterDeviceControlPlatform,代码行数:10,代码来源:NettyClient.java

示例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());
  }
}
 
开发者ID:HubSpot,项目名称:NioImapClient,代码行数:12,代码来源:NettyCompletableFuture.java

示例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);
    }
}
 
开发者ID:warlock-china,项目名称:azeroth,代码行数:30,代码来源:FastdfsExecutor.java

示例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();
  }
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:8,代码来源:BasicClient.java


注:本文中的io.netty.util.concurrent.Future.isSuccess方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。