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


Java Future类代码示例

本文整理汇总了Java中io.netty.util.concurrent.Future的典型用法代码示例。如果您正苦于以下问题:Java Future类的具体用法?Java Future怎么用?Java Future使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Future类属于io.netty.util.concurrent包,在下文中一共展示了Future类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: stopInternal

import io.netty.util.concurrent.Future; //导入依赖的package包/类
@Override
@SuppressForbidden(reason = "debug")
protected void stopInternal() {
    Releasables.close(serverOpenChannels, () -> {
        final List<Tuple<String, Future<?>>> serverBootstrapCloseFutures = new ArrayList<>(serverBootstraps.size());
        for (final Map.Entry<String, ServerBootstrap> entry : serverBootstraps.entrySet()) {
            serverBootstrapCloseFutures.add(
                Tuple.tuple(entry.getKey(), entry.getValue().config().group().shutdownGracefully(0, 5, TimeUnit.SECONDS)));
        }
        for (final Tuple<String, Future<?>> future : serverBootstrapCloseFutures) {
            future.v2().awaitUninterruptibly();
            if (!future.v2().isSuccess()) {
                logger.debug(
                    (Supplier<?>) () -> new ParameterizedMessage(
                        "Error closing server bootstrap for profile [{}]", future.v1()), future.v2().cause());
            }
        }
        serverBootstraps.clear();

        if (bootstrap != null) {
            bootstrap.config().group().shutdownGracefully(0, 5, TimeUnit.SECONDS).awaitUninterruptibly();
            bootstrap = null;
        }
    });
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:26,代码来源:Netty4Transport.java

示例2: tryAcquireAsync

import io.netty.util.concurrent.Future; //导入依赖的package包/类
public RFuture<String> tryAcquireAsync() {
    final RPromise<String> result = newPromise();
    RFuture<String> res = tryAcquireAsync(1, nonExpirableTimeout);
    res.addListener(new FutureListener<String>() {
        @Override
        public void operationComplete(Future<String> future) throws Exception {
            if (!future.isSuccess()) {
                result.tryFailure(future.cause());
                return;
            }
            
            String permitId = future.getNow();
            if (permitId != null && !permitId.startsWith(":")) {
                if (!result.trySuccess(permitId)) {
                    releaseAsync(permitId);
                }
            } else {
                result.trySuccess(null);
            }
        }
    });
    return result;
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:24,代码来源:RedissonPermitExpirableSemaphore.java

示例3: releaseAsync

import io.netty.util.concurrent.Future; //导入依赖的package包/类
@Override
public RFuture<Void> releaseAsync(final String permitId) {
    final RPromise<Void> result = newPromise();
    tryReleaseAsync(permitId).addListener(new FutureListener<Boolean>() {
        @Override
        public void operationComplete(Future<Boolean> future) throws Exception {
            if (!future.isSuccess()) {
                result.tryFailure(future.cause());
                return;
            }
            
            if (future.getNow()) {
                result.trySuccess(null);
            } else {
                result.tryFailure(new IllegalArgumentException("Permit with id " + permitId + " has already been released or doesn't exist"));
            }
        }
    });
    return result;
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:21,代码来源:RedissonPermitExpirableSemaphore.java

示例4: write

import io.netty.util.concurrent.Future; //导入依赖的package包/类
private void write(final byte[] value, final RPromise<Void> result, final int chunkSize, final int i) {
    final int len = Math.min(value.length - i*chunkSize, chunkSize);
    byte[] bytes = Arrays.copyOfRange(value, i*chunkSize, i*chunkSize + len);
    writeAsync(bytes).addListener(new FutureListener<Void>() {
        @Override
        public void operationComplete(Future<Void> future) throws Exception {
            if (!future.isSuccess()) {
                result.tryFailure(future.cause());
                return;
            }
            
            int j = i + 1;
            if (j*chunkSize > value.length) {
                result.trySuccess(null);
            } else {
                write(value, result, chunkSize, j);
            }
        }
    });
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:21,代码来源:RedissonBinaryStream.java

示例5: sendPacket

import io.netty.util.concurrent.Future; //导入依赖的package包/类
public void sendPacket(Packet packetIn, GenericFutureListener <? extends Future <? super Void >> listener, GenericFutureListener <? extends Future <? super Void >> ... listeners)
{
    if (this.isChannelOpen())
    {
        this.flushOutboundQueue();
        this.dispatchPacket(packetIn, (GenericFutureListener[])ArrayUtils.add(listeners, 0, listener));
    }
    else
    {
        this.field_181680_j.writeLock().lock();

        try
        {
            this.outboundPacketsQueue.add(new NetworkManager.InboundHandlerTuplePacketListener(packetIn, (GenericFutureListener[])ArrayUtils.add(listeners, 0, listener)));
        }
        finally
        {
            this.field_181680_j.writeLock().unlock();
        }
    }
}
 
开发者ID:SkidJava,项目名称:BaseClient,代码行数:22,代码来源:NetworkManager.java

示例6: kickPlayerFromServer

import io.netty.util.concurrent.Future; //导入依赖的package包/类
/**
 * Kick a player from the server with a reason
 */
public void kickPlayerFromServer(String reason)
{
    final ChatComponentText chatcomponenttext = new ChatComponentText(reason);
    this.netManager.sendPacket(new S40PacketDisconnect(chatcomponenttext), new GenericFutureListener < Future <? super Void >> ()
    {
        public void operationComplete(Future <? super Void > p_operationComplete_1_) throws Exception
        {
            NetHandlerPlayServer.this.netManager.closeChannel(chatcomponenttext);
        }
    }, new GenericFutureListener[0]);
    this.netManager.disableAutoRead();
    Futures.getUnchecked(this.serverController.addScheduledTask(new Runnable()
    {
        public void run()
        {
            NetHandlerPlayServer.this.netManager.checkDisconnected();
        }
    }));
}
 
开发者ID:SkidJava,项目名称:BaseClient,代码行数:23,代码来源:NetHandlerPlayServer.java

示例7: acquireConnection

import io.netty.util.concurrent.Future; //导入依赖的package包/类
private RFuture<T> acquireConnection(RedisCommand<?> command, final ClientConnectionsEntry entry) {
    final RPromise<T> result = connectionManager.newPromise();

    AcquireCallback<T> callback = new AcquireCallback<T>() {
        @Override
        public void run() {
            result.removeListener(this);
            connectTo(entry, result);
        }
        
        @Override
        public void operationComplete(Future<T> future) throws Exception {
            entry.removeConnection(this);
        }
    };
    
    result.addListener(callback);
    acquireConnection(entry, callback);
    
    return result;
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:22,代码来源:ConnectionPool.java

示例8: createConnection

import io.netty.util.concurrent.Future; //导入依赖的package包/类
private void createConnection(final ClientConnectionsEntry entry, final RPromise<T> promise) {
    RFuture<T> connFuture = connect(entry);
    connFuture.addListener(new FutureListener<T>() {
        @Override
        public void operationComplete(Future<T> future) throws Exception {
            if (!future.isSuccess()) {
                promiseFailure(entry, promise, future.cause());
                return;
            }

            T conn = future.getNow();
            if (!conn.isActive()) {
                promiseFailure(entry, promise, conn);
                return;
            }

            connectedSuccessful(entry, promise, conn);
        }
    });
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:21,代码来源:ConnectionPool.java

示例9: psubscribe

import io.netty.util.concurrent.Future; //导入依赖的package包/类
private void psubscribe(final String channelName, final Collection<RedisPubSubListener<?>> listeners,
        final Codec subscribeCodec) {
    RFuture<PubSubConnectionEntry> subscribeFuture = connectionManager.psubscribe(channelName, subscribeCodec, null);
    subscribeFuture.addListener(new FutureListener<PubSubConnectionEntry>() {
        @Override
        public void operationComplete(Future<PubSubConnectionEntry> future)
                throws Exception {
            if (!future.isSuccess()) {
                psubscribe(channelName, listeners, subscribeCodec);
                return;
            }
            
            PubSubConnectionEntry newEntry = future.getNow();
            for (RedisPubSubListener<?> redisPubSubListener : listeners) {
                newEntry.addListener(channelName, redisPubSubListener);
            }
            log.debug("resubscribed listeners for '{}' channel-pattern", channelName);
        }
    });
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:21,代码来源:MasterSlaveEntry.java

示例10: run

import io.netty.util.concurrent.Future; //导入依赖的package包/类
@Override
public void run() {
    context.channelPool().acquire().addListener((Future<Channel> channelFuture) -> {
        if (channelFuture.isSuccess()) {
            try {
                channel = channelFuture.getNow();
                initializePerRequestHandlers();
                channel.attr(REQUEST_CONTEXT_KEY).set(context);
                channel.attr(RESPONSE_COMPLETE_KEY).set(false);
                makeRequest(context.nettyRequest());
            } catch (Exception e) {
                handleFailure(() -> "Failed to make request to " + endpoint(), e);
            }
        } else {
            handleFailure(() -> "Failed to create connection to " + endpoint(), channelFuture.cause());
        }
    });
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:19,代码来源:RunnableRequest.java

示例11: forceUnlockAsync

import io.netty.util.concurrent.Future; //导入依赖的package包/类
@Override
public RFuture<Boolean> forceUnlockAsync() {
    RFuture<Boolean> result = commandExecutor.evalWriteAsync(getName(), LongCodec.INSTANCE, RedisCommands.EVAL_BOOLEAN,
            "if (redis.call('hget', KEYS[1], 'mode') == 'read') then " +
                "redis.call('del', KEYS[1]); " +
                "redis.call('publish', KEYS[2], ARGV[1]); " +
                "return 1; " +
            "end; " +
            "return 0; ",
            Arrays.<Object>asList(getName(), getChannelName()), LockPubSub.unlockMessage);

      result.addListener(new FutureListener<Boolean>() {
          @Override
          public void operationComplete(Future<Boolean> future) throws Exception {
              if (future.isSuccess() && future.getNow()) {
                  cancelExpirationRenewal();
              }
          }
      });

      return result;
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:23,代码来源:RedissonReadLock.java

示例12: checkClusterState

import io.netty.util.concurrent.Future; //导入依赖的package包/类
private void checkClusterState(final ClusterServersConfig cfg, final Iterator<URI> iterator, final AtomicReference<Throwable> lastException) {
    if (!iterator.hasNext()) {
        log.error("Can't update cluster state", lastException.get());
        scheduleClusterChangeCheck(cfg, null);
        return;
    }
    if (!getShutdownLatch().acquire()) {
        return;
    }
    final URI uri = iterator.next();
    RFuture<RedisConnection> connectionFuture = connect(cfg, uri);
    connectionFuture.addListener(new FutureListener<RedisConnection>() {
        @Override
        public void operationComplete(Future<RedisConnection> future) throws Exception {
            if (!future.isSuccess()) {
                lastException.set(future.cause());
                getShutdownLatch().release();
                checkClusterState(cfg, iterator, lastException);
                return;
            }

            RedisConnection connection = future.getNow();
            updateClusterState(cfg, connection, iterator, uri);
        }
    });
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:27,代码来源:ClusterConnectionManager.java

示例13: retryReadRandomAsync

import io.netty.util.concurrent.Future; //导入依赖的package包/类
private <R, T> void retryReadRandomAsync(final RedisCommand<T> command, final RPromise<R> mainPromise,
        final List<MasterSlaveEntry> nodes, final Object... params) {
    final RPromise<R> attemptPromise = connectionManager.newPromise();
    attemptPromise.addListener(new FutureListener<R>() {
        @Override
        public void operationComplete(Future<R> future) throws Exception {
            if (future.isSuccess()) {
                if (future.getNow() == null) {
                    if (nodes.isEmpty()) {
                        mainPromise.trySuccess(null);
                    } else {
                        retryReadRandomAsync(command, mainPromise, nodes, params);
                    }
                } else {
                    mainPromise.trySuccess(future.getNow());
                }
            } else {
                mainPromise.tryFailure(future.cause());
            }
        }
    });

    MasterSlaveEntry entry = nodes.remove(0);
    async(true, new NodeSource(entry), connectionManager.getCodec(), command, params, attemptPromise, 0);
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:26,代码来源:CommandAsyncService.java

示例14: releaseConnection

import io.netty.util.concurrent.Future; //导入依赖的package包/类
protected <V, R> void releaseConnection(final NodeSource source, final RFuture<RedisConnection> connectionFuture,
        final boolean isReadOnly, RPromise<R> attemptPromise, final AsyncDetails<V, R> details) {
    attemptPromise.addListener(new FutureListener<R>() {
        @Override
        public void operationComplete(Future<R> future) throws Exception {
            if (!connectionFuture.isSuccess()) {
                return;
            }

            RedisConnection connection = connectionFuture.getNow();
            connectionManager.getShutdownLatch().release();
            if (isReadOnly) {
                connectionManager.releaseRead(source, connection);
            } else {
                connectionManager.releaseWrite(source, connection);
            }

            if (log.isDebugEnabled()) {
                log.debug("connection released for command {} and params {} from slot {} using connection {}",
                        details.getCommand(), Arrays.toString(details.getParams()), details.getSource(), connection);
            }
        }
    });
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:25,代码来源:CommandAsyncService.java

示例15: tryAcquireOnceAsync

import io.netty.util.concurrent.Future; //导入依赖的package包/类
private RFuture<Boolean> tryAcquireOnceAsync(long leaseTime, TimeUnit unit, final long threadId) {
    if (leaseTime != -1) {
        return tryLockInnerAsync(leaseTime, unit, threadId, RedisCommands.EVAL_NULL_BOOLEAN);
    }
    RFuture<Boolean> ttlRemainingFuture = tryLockInnerAsync(commandExecutor.getConnectionManager().getCfg().getLockWatchdogTimeout(), TimeUnit.MILLISECONDS, threadId, RedisCommands.EVAL_NULL_BOOLEAN);
    ttlRemainingFuture.addListener(new FutureListener<Boolean>() {
        @Override
        public void operationComplete(Future<Boolean> future) throws Exception {
            if (!future.isSuccess()) {
                return;
            }

            Boolean ttlRemaining = future.getNow();
            // lock acquired
            if (ttlRemaining) {
                scheduleExpirationRenewal(threadId);
            }
        }
    });
    return ttlRemainingFuture;
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:22,代码来源:RedissonLock.java


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