io.netty.util.concurrent.Future.get()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(7.5k)|赞(0)|评价(0)|浏览(115)

本文整理了Java中io.netty.util.concurrent.Future.get()方法的一些代码示例,展示了Future.get()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Future.get()方法的具体详情如下:
包路径:io.netty.util.concurrent.Future
类名称:Future
方法名:get

Future.get介绍

[英]Return the result without blocking. If the future is not done yet this will return null. As it is possible that a null value is used to mark the future as successful you also need to check if the future is really done with #isDone() and not relay on the returned null value.
[中]返回结果而不阻塞。如果未来尚未完成,则返回null。由于可能会使用空值将未来标记为成功,因此您还需要检查未来是否真的使用了#isDone()而不是使用返回的空值。

代码示例

代码示例来源:origin: redisson/redisson

@Override
public void operationComplete(Future<Codec> future) throws Exception {
  if (future.get() == null) {
    return;
  }
  
  Codec subscribeCodec = future.get();
  if (topicType == PubSubType.PUNSUBSCRIBE) {
    psubscribe(channelName, listeners, subscribeCodec);
  } else {
    subscribe(channelName, listeners, subscribeCodec);
  }
}

代码示例来源:origin: redisson/redisson

@Override
public void operationComplete(Future<Codec> future) throws Exception {
  if (future.get() == null) {
    return;
  }
  
  Codec subscribeCodec = future.get();
  if (topicType == PubSubType.PUNSUBSCRIBE) {
    psubscribe(channelName, listeners, subscribeCodec);
  } else {
    subscribe(channelName, listeners, subscribeCodec);
  }
}

代码示例来源:origin: redisson/redisson

@Override
  public void operationComplete(Future<List<?>> future) throws Exception {
    if (future.isSuccess()) {
      List<Long> result = (List<Long>) future.get();
      for (Long res : result) {
        if (res != null) {
          count.addAndGet(res);
        }
      }
    } else {
      failed.set(future.cause());
    }
    checkExecution(result, failed, count, executed);
  }
};

代码示例来源:origin: redisson/redisson

@Override
  public void operationComplete(Future<List<?>> future) throws Exception {
    if (future.isSuccess()) {
      List<Long> result = (List<Long>) future.get();
      for (Long res : result) {
        if (res != null) {
          count.addAndGet(res);
        }
      }
    } else {
      failed.set(future.cause());
    }
    checkExecution(result, failed, count, executed);
  }
};

代码示例来源:origin: redisson/redisson

@Override
  public void operationComplete(Future<List<?>> future) throws Exception {
    if (future.isSuccess()) {
      List<Long> result = (List<Long>) future.get();
      for (Long res : result) {
        if (res != null) {
          count.addAndGet(res);
        }
      }
    } else {
      failed.set(future.cause());
    }
    checkExecution(result, failed, count, executed);
  }
};

代码示例来源:origin: redisson/redisson

@Override
  public void operationComplete(Future<List<?>> future) throws Exception {
    if (future.isSuccess()) {
      List<Long> result = (List<Long>) future.get();
      for (Long res : result) {
        if (res != null) {
          count.addAndGet(res);
        }
      }
    } else {
      failed.set(future.cause());
    }
    checkExecution(result, failed, count, executed);
  }
};

代码示例来源:origin: redisson/redisson

@Override
  public void operationComplete(Future<Boolean> future) throws Exception {
    if (!future.isSuccess() || future.get()) {
      scheduleRetryTimeRenewal(requestId);
    }
  }
});

代码示例来源:origin: redisson/redisson

@Override
  public void operationComplete(Future<Boolean> future) throws Exception {
    if (!future.isSuccess() || future.get()) {
      scheduleRetryTimeRenewal(requestId);
    }
  }
});

代码示例来源:origin: Netflix/zuul

/** This is just for use in unit-testing. */
public void waitForEachEventLoop() throws InterruptedException, ExecutionException
{
  for (EventExecutor exec : serverGroup.clientToProxyWorkerPool)
  {
    exec.submit(() -> {
      // Do nothing.
    }).get();
  }
}

代码示例来源:origin: redisson/redisson

@Override
  public void operationComplete(Future<Collection<V>> future) throws Exception {
    if (!future.isSuccess()) {
      promise.tryFailure(future.cause());
      return;
    }
    
    result.addAll(future.get());
    promise.trySuccess(result);
  }
});

代码示例来源:origin: redisson/redisson

@Override
  public void operationComplete(Future<Collection<V>> future) throws Exception {
    if (!future.isSuccess()) {
      promise.tryFailure(future.cause());
      return;
    }
    
    result.addAll(future.get());
    promise.trySuccess(result);
  }
});

代码示例来源:origin: netty/netty

@Override
  public void operationComplete(F future) throws Exception {
    InternalLogger internalLogger = logNotifyFailure ? logger : null;
    if (future.isSuccess()) {
      V result = future.get();
      for (Promise<? super V> p: promises) {
        PromiseNotificationUtil.trySuccess(p, result, internalLogger);
      }
    } else if (future.isCancelled()) {
      for (Promise<? super V> p: promises) {
        PromiseNotificationUtil.tryCancel(p, internalLogger);
      }
    } else {
      Throwable cause = future.cause();
      for (Promise<? super V> p: promises) {
        PromiseNotificationUtil.tryFailure(p, cause, internalLogger);
      }
    }
  }
}

代码示例来源:origin: Netflix/zuul

/** This is just for use in unit-testing. */
public void waitForEachEventLoop() throws InterruptedException, ExecutionException
{
  for (EventExecutor exec : serverGroup.clientToProxyWorkerPool)
  {
    exec.submit(() -> {
      // Do nothing.
    }).get();
  }
}

代码示例来源:origin: apache/incubator-shardingsphere

private void executeSQL(final String dataSourceName, final String sql) throws InterruptedException, ExecutionException, TimeoutException {
  if (!channelMap.containsKey(dataSourceName)) {
    channelMap.put(dataSourceName, new ArrayList<Channel>());
  }
  SimpleChannelPool pool = CLIENT_MANAGER.getBackendNettyClient(logicSchema.getName()).getPoolMap().get(dataSourceName);
  Channel channel = pool.acquire().get(GLOBAL_REGISTRY.getShardingProperties().<Long>getValue(ShardingPropertiesConstant.PROXY_BACKEND_CONNECTION_TIMEOUT_SECONDS), TimeUnit.SECONDS);
  channelMap.get(dataSourceName).add(channel);
  ChannelRegistry.getInstance().putConnectionId(channel.id().asShortText(), connectionId);
  channel.writeAndFlush(new ComQueryPacket(sequenceId, sql));
}

代码示例来源:origin: apache/incubator-shardingsphere

private void executeSQL(final String dataSourceName, final String sql) throws InterruptedException, ExecutionException, TimeoutException {
  if (!channelMap.containsKey(dataSourceName)) {
    channelMap.put(dataSourceName, new ArrayList<Channel>());
  }
  SimpleChannelPool pool = CLIENT_MANAGER.getBackendNettyClient(logicSchema.getName()).getPoolMap().get(dataSourceName);
  Channel channel = pool.acquire().get(GLOBAL_REGISTRY.getShardingProperties().<Long>getValue(ShardingPropertiesConstant.PROXY_BACKEND_CONNECTION_TIMEOUT_SECONDS), TimeUnit.SECONDS);
  channelMap.get(dataSourceName).add(channel);
  ChannelRegistry.getInstance().putConnectionId(channel.id().asShortText(), connectionId);
  channel.writeAndFlush(new ComQueryPacket(sequenceId, sql));
}

代码示例来源:origin: AsyncHttpClient/async-http-client

@Test(timeOut = 60000, expectedExceptions = ExecutionException.class)
public void sendByteMessageExpectFailure() throws Exception {
 try (AsyncHttpClient c = asyncHttpClient()) {
  CountDownLatch closeLatch = new CountDownLatch(1);
  WebSocket websocket = getWebSocket(c, closeLatch);
  websocket.sendCloseFrame();
  closeLatch.await(1, TimeUnit.SECONDS);
  websocket.sendBinaryFrame("BYTES".getBytes()).get(10, TimeUnit.SECONDS);
 }
}

代码示例来源:origin: AsyncHttpClient/async-http-client

@Test(timeOut = 60000)
public void streamBytes() throws Exception {
 try (AsyncHttpClient c = asyncHttpClient()) {
  getWebSocket(c).sendBinaryFrame("STREAM".getBytes(), true, 0).get(1, TimeUnit.SECONDS);
 }
}

代码示例来源:origin: AsyncHttpClient/async-http-client

@Test(timeOut = 60000)
public void sendPingMessage() throws Exception {
 try (AsyncHttpClient c = asyncHttpClient()) {
  getWebSocket(c).sendPingFrame("PING".getBytes()).get(10, TimeUnit.SECONDS);
 }
}

代码示例来源:origin: AsyncHttpClient/async-http-client

@Test(expectedExceptions = ExecutionException.class)
public void streamTextExpectFailure() throws Exception {
 try (AsyncHttpClient c = asyncHttpClient()) {
  CountDownLatch closeLatch = new CountDownLatch(1);
  WebSocket websocket = getWebSocket(c, closeLatch);
  websocket.sendCloseFrame();
  closeLatch.await(1, TimeUnit.SECONDS);
  websocket.sendTextFrame("STREAM", true, 0).get(1, TimeUnit.SECONDS);
 }
}

代码示例来源:origin: AsyncHttpClient/async-http-client

@Test(timeOut = 60000)
public void sendTextMessage() throws Exception {
 try (AsyncHttpClient c = asyncHttpClient()) {
  getWebSocket(c).sendTextFrame("TEXT").get(10, TimeUnit.SECONDS);
 }
}

相关文章