com.twitter.util.Future.apply()方法的使用及代码示例

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

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

Future.apply介绍

暂无

代码示例

代码示例来源:origin: com.senseidb.zu/zu-finagle

public void shutdown(Duration timeout){
 if (server != null) {
  Future<?> future = server.close();
  if (timeout != null) {
   future.apply(timeout);
  }
  else {
   future.apply();
  }
 }
}

代码示例来源:origin: com.senseidb.zu/zu-finagle

@Override
public Res handleRequest(Req req) {
 return svc.apply(req).apply();
}

代码示例来源:origin: com.senseidb.zu/zu-finagle

@Override
public void cleanup(Set<Service<Req, Res>> toBeClosed) {
 for (Service<Req,Res> svc : toBeClosed) {
  Future<BoxedUnit> closeFuture = svc.close();
  if (closeFuture != null) {
   closeFuture.apply();
  }
 }
}

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

/**
 * Calls {@link Client#delete(String)} on the underlying {@link Client}
 * instance. This deletes the underlying journal instance in the kestrel
 * queue
 *
 * @param queueName
 */
public void delete(String queueName) {
  client.delete(queueName).apply();
}

代码示例来源:origin: org.openimaj.storm/core-storm

/**
 * Calls {@link Client#delete(String)} on the underlying {@link Client}
 * instance. This deletes the underlying journal instance in the kestrel
 * queue
 *
 * @param queueName
 */
public void delete(String queueName) {
  client.delete(queueName).apply();
}

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

/**
 * Get the next value from the queue
 *
 * @param queueName
 * @param waitDuration
 *            an amount of time to wait before returning null
 * @return the next value
 */
public byte[] getByte(String queueName, Duration waitDuration) {
  try {
    final ChannelBuffer value = client.get(queueName, waitDuration).apply();
    return value == null ? null : value.array();
  } catch (final Exception e) {
    if (THROUGH_EXCEPTIONS.contains(e.getClass())) {
      return null;
    }
    LOG.error(e.getMessage(), e);
    throw new IllegalStateException(e);
  }
}

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

/**
 * Get the next value from the queue
 *
 * @param queueName
 * @param waitDuration
 * @return the next value
 */
public String get(String queueName, Duration waitDuration) {
  try {
    final ChannelBuffer value = client.get(queueName, waitDuration).apply();
    return value == null ? null : value.toString(CharsetUtil.UTF_8);
  } catch (final Exception e) {
    if (THROUGH_EXCEPTIONS.contains(e.getClass())) {
      return null;
    }
    LOG.error(e.getMessage(), e);
    throw new IllegalStateException(e);
  }
}

代码示例来源:origin: org.openimaj.storm/core-storm

/**
 * Get the next value from the queue
 *
 * @param queueName
 * @param waitDuration
 * @return the next value
 */
public String get(String queueName, Duration waitDuration) {
  try {
    final ChannelBuffer value = client.get(queueName, waitDuration).apply();
    return value == null ? null : value.toString(CharsetUtil.UTF_8);
  } catch (final Exception e) {
    if (THROUGH_EXCEPTIONS.contains(e.getClass())) {
      return null;
    }
    LOG.error(e.getMessage(), e);
    throw new IllegalStateException(e);
  }
}

代码示例来源:origin: org.openimaj.storm/core-storm

/**
 * Get the next value from the queue
 *
 * @param queueName
 * @param waitDuration
 *            an amount of time to wait before returning null
 * @return the next value
 */
public byte[] getByte(String queueName, Duration waitDuration) {
  try {
    final ChannelBuffer value = client.get(queueName, waitDuration).apply();
    return value == null ? null : value.array();
  } catch (final Exception e) {
    if (THROUGH_EXCEPTIONS.contains(e.getClass())) {
      return null;
    }
    LOG.error(e.getMessage(), e);
    throw new IllegalStateException(e);
  }
}

代码示例来源:origin: com.senseidb/sensei-core

protected List<RESULT> executeRequestsInParallel(
  final Map<Service<REQUEST, RESULT>, REQUEST> serviceToRequest, long timeout) {
 long start = System.currentTimeMillis();
 final List<Future<RESULT>> futures = new ArrayList<Future<RESULT>>();
 for (Entry<Service<REQUEST, RESULT>, REQUEST> entry : serviceToRequest.entrySet()) {
  futures.add(entry.getKey().apply(entry.getValue())
    .addEventListener(new FutureEventListener<RESULT>() {
     @Override
     public void onFailure(Throwable t) {
      logger.error("Failed to get response", t);
     }
     @Override
     public void onSuccess(RESULT result) {
      // do nothing as we wait for all results below
     }
    }));
 }
 Future<List<RESULT>> collected = Future.collect(futures);
 List<RESULT> results = collected.apply(Duration.apply(timeout, TimeUnit.MILLISECONDS));
 logger.info(String.format("Getting responses from %d nodes took %dms.", results.size(),
  (System.currentTimeMillis() - start)));
 return results;
}

代码示例来源:origin: com.senseidb.zu/zu-finagle

@Override
 public Future<Res> apply(Req req) {
  Map<Integer, Future<Res>> futureList = new HashMap<Integer,Future<Res>>();
  for (Integer shard : shards) {
   Service<Req, Res> node = routingAlgorithm.route(routingKey, shard);
   if (node != null) {
    Req rewrittenReq = scatterGather.rewrite(req, shard);
    futureList.put(shard, node.apply(rewrittenReq));
   }
  }
  
  Map<Integer, Res> resList = new HashMap<Integer,Res>();
  
  for (Entry<Integer, Future<Res>> entry : futureList.entrySet()) {
   Res result = entry.getValue().apply(partialResultTimeout);
   resList.put(entry.getKey(), result);
  }
  
  return  Future.value(scatterGather.merge(resList));
 }
};

相关文章