com.oath.cyclops.async.adapters.Queue.streamBatch()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(1.7k)|赞(0)|评价(0)|浏览(97)

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

Queue.streamBatch介绍

暂无

代码示例

代码示例来源:origin: aol/cyclops

public ReactiveSeq<Seq<T>> streamGroupedBySizeAndTime(int size, long time, TimeUnit t){
  long toRun = t.toNanos(time);
  return streamBatch(new Subscription(), source->{
    return ()->{
      List<T> result = new ArrayList<>();
      long start = System.nanoTime();
     try {
       while (result.size() < size && checkTime(System.nanoTime(), start, toRun)) {
         try {
           T next = source.apply(100l, TimeUnit.MICROSECONDS);
           if (next != null) {
             result.add(next);
           }
         } catch (Queue.QueueTimeoutException e) {
         }
       }
     }catch(Queue.ClosedQueueException e){
       if(result.size()>0) {
         List list = new ArrayList<>();
         list.add(result);
         throw new ClosedQueueException(list);
       }
     }
      return result;
    };
  }).filter(l->l.size()>0)
      .map(Seq::fromIterable);
}

代码示例来源:origin: com.oath.cyclops/cyclops

public ReactiveSeq<Seq<T>> streamGroupedBySizeAndTime(int size, long time, TimeUnit t){
  long toRun = t.toNanos(time);
  return streamBatch(new Subscription(), source->{
    return ()->{
      List<T> result = new ArrayList<>();
      long start = System.nanoTime();
     try {
       while (result.size() < size && checkTime(System.nanoTime(), start, toRun)) {
         try {
           T next = source.apply(100l, TimeUnit.MICROSECONDS);
           if (next != null) {
             result.add(next);
           }
         } catch (Queue.QueueTimeoutException e) {
         }
       }
     }catch(Queue.ClosedQueueException e){
       if(result.size()>0) {
         List list = new ArrayList<>();
         list.add(result);
         throw new ClosedQueueException(list);
       }
     }
      return result;
    };
  }).filter(l->l.size()>0)
      .map(Seq::fromIterable);
}

相关文章