cyclops.reactive.ReactiveSeq.of()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(6.9k)|赞(0)|评价(0)|浏览(163)

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

ReactiveSeq.of介绍

[英]Efficiently construct a ReactiveSeq from a single value
[中]从单个值高效地构造一个ReactiveSeq

代码示例

代码示例来源:origin: aol/micro-server

public MicroserverPlugins(Module mod, Class... classes){
  this.classes = ReactiveSeq.of(classes)
               .appendStream(ReactiveSeq.of(new MicroserverApp(extractClass(),mod).classes))
               .toArray(i->new Class[i]);
}
public Class[] classes(){

代码示例来源:origin: aol/micro-server

private Map<String, String> manifest() {
  try {
    return ReactiveSeq.of("META-INF/MANIFEST.MF")
      .map(url -> this.getClass()
        .getClassLoader()
        .getResourceAsStream(url))
      .map(this::getManifest)
      .single()
      .orElse(null);
  } catch (Exception e) {
    logger.warn("Warning : can't load manifest due to exception {}", e.getMessage());
  }
  return null;
}

代码示例来源:origin: aol/micro-server

@GET
@Produces("application/json")
@Path("/jobs")
public void activeJobs(@Suspended AsyncResponse asyncResponse) {
  try {
    ReactiveSeq.of(this.activeJobs)
          .map(JobsBeingExecuted::toString)
          .foldFuture(WorkerThreads.ioExecutor.get(),
            s -> s.forEach(Long.MAX_VALUE, str -> asyncResponse.resume(str)));
  } catch (Exception e) {
    e.printStackTrace();
  }
}

代码示例来源:origin: aol/micro-server

@GET
@Produces("application/json")
@Path("/all-requests")
public void allActiveRequests(@Suspended AsyncResponse asyncResponse) {
  ReactiveSeq.of(activeQueries.toString())
        .foldFuture(WorkerThreads.ioExecutor.get(),
        s->s.forEach(Long.MAX_VALUE,result -> asyncResponse.resume(result)));
}

代码示例来源:origin: aol/micro-server

public MicroserverPlugins(Class... classes){
  ReactiveSeq<Class> rs=  classes!=null ? ReactiveSeq.of(classes) : ReactiveSeq.empty();
  this.classes = rs
    .appendStream(ReactiveSeq.of(new MicroserverApp(true,extractClass(),()->"").classes))
    .toArray(i->new Class[i]);
}
public MicroserverPlugins(Module mod, Class... classes){

代码示例来源:origin: aol/micro-server

@GET
@Produces("application/json")
public void mainfest(@Suspended AsyncResponse asyncResponse, @Context ServletContext context) {
  
  ReactiveSeq.of("/META-INF/MANIFEST.MF")
        .map(url->context.getResourceAsStream(url))
        .map(this::getManifest)
      .foldFuture(WorkerThreads.ioExecutor.get(),
        s->s.forEach(Long.MAX_VALUE,result->asyncResponse.resume(result)));
        
  
}

代码示例来源:origin: aol/micro-server

@GET
@Produces("application/json")
@Path("/requests")
public void activeRequests(@Suspended AsyncResponse asyncResponse, @QueryParam("type") final String type) {
  ReactiveSeq.of((type == null ? "default" : type))
        .map(typeToUse -> activeQueries.getMap()
                       .get(typeToUse)
                       .toString())
        .foldFuture(WorkerThreads.ioExecutor.get(),
        s->s.forEach(Long.MAX_VALUE,result -> asyncResponse.resume(result)));
}

代码示例来源:origin: aol/micro-server

@GET
@Path("/list")
@Produces("application/json")
public void list(@Context UriInfo uriInfo, @Suspended AsyncResponse response) {
  ReactiveSeq.of(this).foldFuture(WorkerThreads.ioExecutor.get(),
    s -> s.forEach(Long.MAX_VALUE, next -> {
      try {
        cleaner.clean();
        response.resume(finder.find(UriInfoParser.toRegisterEntry(uriInfo)));
      } catch (Exception e) {
        logger.error(e.getMessage(), e);
        response.resume(Arrays.asList("Bad Request: " + e.getMessage()));
      }
    }));
}

代码示例来源:origin: aol/micro-server

@POST
@Path("/schedule")
@Consumes("application/json")
@Produces("application/json")
public void schedule(@Suspended AsyncResponse response) {
  ReactiveSeq.of(this).foldFuture(WorkerThreads.ioExecutor.get(), s ->
    s.forEach(Long.MAX_VALUE, next -> {
      try {
        job.schedule();
        response.resume(HashMapBuilder.of("status", "success"));
      } catch (Exception e) {
        logger.error(e.getMessage(), e);
        response.resume(HashMapBuilder.of("status", "failure"));
      }
    }));
}

代码示例来源:origin: aol/micro-server

@POST
@Path("/register")
@Consumes("application/json")
@Produces("application/json")
public void register(@Suspended AsyncResponse response, RegisterEntry entry) {
  ReactiveSeq.of(this).foldFuture(WorkerThreads.ioExecutor.get(),
    s -> s.forEach(Long.MAX_VALUE, next -> {
      try {
        register.register(entry);
        response.resume(HashMapBuilder.of("status", "complete"));
      } catch (Exception e) {
        logger.error(e.getMessage(), e);
        response.resume(HashMapBuilder.of("status", "failure"));
      }
    }));
}

代码示例来源:origin: aol/micro-server

private Map<String, String> buildProperties(Microserver microserver) {
  Map<String, String> properties = ReactiveSeq.of(microserver.properties())
                        .grouped(2)
                        .toMap(prop -> prop.getOrElse(0,null), prop -> prop.getOrElse(1,null));
  return properties;
}

代码示例来源:origin: aol/micro-server

@Test
  public void test(){
    assertTrue(ReactiveSeq.of(new MicroserverPlugins().classes())
      .contains(Bean1.class));
  }
}

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

@Test
public void batchBySize(){
  System.out.println(of(1,2,3,4,5,6).grouped(3).collect(Collectors.toList()));
  assertThat(of(1,2,3,4,5,6).grouped(3).collect(Collectors.toList()).size(),is(2));
}

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

@Test
public void skipArray() throws InterruptedException{
  List<Integer> list= new ArrayList<>();
  for(int i=0;i<1000;i++)
    list.add(i);
  assertThat(ReactiveSeq.of(list.toArray())
       .skip(100)
       .count(),equalTo(900L));
}
@Test

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

@Test
public void testLimitLastEmpty(){
  assertThat(ReactiveSeq.of()
            .takeRight(2)
            .collect(Collectors.toList()),equalTo(Arrays.asList()));
}
@Test

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

@Test
public void testLazy(){
  Collection<Integer> col = ReactiveSeq.of(1,2,3,4,5)
                    .peek(System.out::println).to()
                    .lazyCollection();
  System.out.println("takeOne!");
  col.forEach(System.out::println);
  assertThat(col.size(),equalTo(5));
}

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

@Test
public void windowStatefullyWhile(){
  System.out.println(ReactiveSeq.of(1,2,3,4,5,6)
      .groupedWhile((s, i)->s.containsValue(4) ? true : false)
      .toList());
  assertThat(ReactiveSeq.of(1,2,3,4,5,6)
      .groupedWhile((s, i)->s.containsValue(4) ? true : false)
      .toList().size(),equalTo(4));
}
@Test

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

@Test
public void timeStamp(){
  assertTrue(ReactiveSeq.of(1,2,3,4,5)
            .timestamp()
            .allMatch(t-> t._2() <= System.currentTimeMillis()));
}
@Test

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

@Test
public void testUnzip3() {
  Supplier<ReactiveSeq<Tuple3<Integer, String, Long>>> s = () -> of(new Tuple3(1, "a", 2l), new Tuple3(2, "b", 3l), new Tuple3(3, "c", 4l));
  Tuple3<ReactiveSeq<Integer>, ReactiveSeq<String>, ReactiveSeq<Long>> u1 = ReactiveSeq.unzip3(s.get());
  assertTrue(u1._1().toList().containsAll(Arrays.asList(1, 2, 3)));
  assertTrue(u1._2().toList().containsAll(asList("a", "b", "c")));
  assertTrue(u1._3().toList().containsAll(asList(2l, 3l, 4l)));
}

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

@Test
public void slidingOverlap() {
  List<Seq<Integer>> sliding = ReactiveSeq.of(1, 2, 3, 4, 5).sliding(3,2).toList();
  assertThat(sliding, contains(Seq.of(1, 2, 3), Seq.of(3, 4, 5)));
}

相关文章

微信公众号

最新文章

更多

ReactiveSeq类方法