當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。