本文整理匯總了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;
}
});
}
示例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;
}
示例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;
}
示例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);
}
}
});
}
示例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();
}
}
}
示例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();
}
}));
}
示例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;
}
示例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);
}
});
}
示例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);
}
});
}
示例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());
}
});
}
示例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;
}
示例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);
}
});
}
示例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);
}
示例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);
}
}
});
}
示例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;
}