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

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

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

ReactiveSeq.fromStream介绍

[英]Construct a ReactiveSeq from a Stream
[中]从流构造一个ReactiveSeq

代码示例

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

private List<Class> buildClasses(Class class1, Microserver microserver) {
  List<Class> classes = new ArrayList();
  classes.add(class1);
  if (microserver.classes() != null)
    classes.addAll(Arrays.asList(microserver.classes()));
  List<Plugin> modules = PluginLoader.INSTANCE.plugins.get();
  if(modules.size()>0)
    classes.addAll(ReactiveSeq.fromStream(modules.stream()).flatMap(module -> module.springClasses().stream()).toList());
  
  return classes;
}

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

default Map<String, Filter> getFilters(ServerData data) {
  Map<String, Filter> map = new HashMap<>();
  ReactiveSeq.fromStream(PluginLoader.INSTANCE.plugins.get()
                            .stream())
        .filter(module -> module.filters() != null)
        .map(module -> module.filters()
                  .apply(data))
        .forEach(pluginMap -> map.putAll(pluginMap));
  return MapX.fromMap(map);
}

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

default Map<String, Servlet> getServlets(ServerData data) {
  Map<String, Servlet> map = new HashMap<>();
  ReactiveSeq.fromStream(PluginLoader.INSTANCE.plugins.get()
                            .stream())
        .filter(module -> module.servlets() != null)
        .map(module -> module.servlets()
                  .apply(data))
        .forEach(pluginMap -> map.putAll(pluginMap));
  return MapX.fromMap(map);
}

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

default String getProviders() {
  String additional = ReactiveSeq.fromStream(PluginLoader.INSTANCE.plugins.get()
                                      .stream())
                  .peek(System.out::println)
                  .filter(module -> module.providers() != null)
                  .concatMap(Plugin::providers)
                  .join(",");
  if (StringUtils.isEmpty(additional))
    return "com.oath.micro.server.rest.providers";
  return "com.oath.micro.server.rest.providers," + additional;
}

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

private ServerApplication createServer(Module module) {
  List<ServerApplicationFactory> applications = ReactiveSeq.fromStream(PluginLoader.INSTANCE.plugins.get()
                                                   .stream())
                               .filter(m -> m.serverApplicationFactory() != null)
                               .map(Plugin::serverApplicationFactory)
                               .flatMap(Streams::optionalToStream)
                               .toList();
  if (applications.size() > 1) {
    logger.error("ERROR!  Multiple server application factories found : The solution is remove one these plugins from your classpath ",
           applications);
    System.err.println("ERROR!  Multiple server application factories found : The solution is remove one these plugins from your classpath "
        + applications);
    throw new IncorrectNumberOfServersConfiguredException(
                               "Multiple server application factories found : The solution is remove one these plugins from your classpath "
                                   + applications);
  } else if (applications.size() == 0) {
    logger.error("ERROR!  No server application factories found. If you using micro-spring-boot don't call MicroserverApp.start() method. A possible solution is add one of micro-grizzly or micro-tomcat to the classpath.");
    System.err.println("ERROR!  No server application factories found. If you using micro-spring-boot don't call MicroserverApp.start() method. A possible solution is add one of micro-grizzly or micro-tomcat to the classpath.");
    throw new IncorrectNumberOfServersConfiguredException(
                               "No server application factories found. If you using micro-spring-boot don't call MicroserverApp.start() method. A possible solution is add one of micro-grizzly or micro-tomcat to the classpath. ");
  }
  ServerApplication app = applications.get(0)
                    .createApp(module, springContext);        
  return app;
}

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

public SpringContextFactory(Config config, Class<?> c, Set<Class<?>> classes) {
  PersistentSet<Class> s = config.getClasses()
          .plusAll(classes);
  s= s.plus(c);
  Microserver microserver = c.getAnnotation(Microserver.class);
  final PersistentSet<Class> immutableS = s;
  s = Optional.ofNullable(microserver)
        .flatMap(ms -> Optional.ofNullable(ms.blacklistedClasses()))
        .map(bl -> {
          Set<Class> blacklistedClasses = Arrays.stream(bl)
                             .collect(Collectors.toSet());
          return (PersistentSet<Class>)immutableS.stream()
                   .filter(clazz -> !blacklistedClasses.contains(clazz)).hashSet();
        })
        .orElse(immutableS);
  this.classes = s;
  this.config = config;
  springBuilder = ReactiveSeq.fromStream(PluginLoader.INSTANCE.plugins.get()
                                    .stream())
                .filter(m -> m.springBuilder() != null)
                .map(Plugin::springBuilder)
                .findFirst()
                .orElse(new SpringApplicationConfigurator());
}

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

default String getJaxWsRsApplication() {
  List<String> jaxRsApplications = ReactiveSeq.fromStream(PluginLoader.INSTANCE.plugins.get()
                                             .stream())
                        .filter(module -> module.jaxWsRsApplication() != null)
                        .map(Plugin::jaxWsRsApplication)
                        .flatMap(Streams::optionalToStream)
                        .toList();
  if (jaxRsApplications.size() > 1) {
    throw new IncorrectJaxRsPluginsException(
                         "ERROR!  Multiple jax-rs application plugins found,  a possible solution is to remove micro-jackson or other jax-rs application provider from your classpath. "
                             + jaxRsApplications);
  } else if (jaxRsApplications.size() == 0) {
    throw new IncorrectJaxRsPluginsException(
                         "ERROR!  No jax-rs application plugins found, a possible solution is to add micro-jackson to your classpath. ");
  }
  return jaxRsApplications.get(0);
}

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

private List<SpringDBConfig> getConfig(Config config, AnnotationConfigWebApplicationContext rootContext,
    ConfigurableListableBeanFactory beanFactory) {
  List<SpringDBConfig> result = ReactiveSeq.fromStream(PluginLoader.INSTANCE.plugins.get()
                                           .stream())
                       .filter(module -> module.springDbConfigurer() != null)
                       .map(Plugin::springDbConfigurer)
                       .flatMap(Streams::optionalToStream)
                       .toList();
  result.forEach(next -> {
    next.setBeanFactory(beanFactory);
    next.setRootContext(rootContext);
    next.setConfig(config);
  });
  return result;
}

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

@Test
public void testProviders(){
  System.out.println(ConfigurableModule.builder().build().getProviders());
  //test MyPlugin working
  
  System.out.println(new ModuleImpl().getProviders());
  String additional = ReactiveSeq
      .fromStream(
          Arrays.<Plugin>asList(new TestPlugin())
              .stream()).filter(module -> module.providers()!=null)
              .concatMap(Plugin::providers)
              .join(",");
  
  assertThat(additional, equalTo(""));
}
static class ModuleImpl  implements Module{

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

@Test
public void testProviders(){
  //test MyPlugin working
  assertThat("com.oath.micro.server.rest.providers,com.my.new.provider,com.my.new.provider2",
      equalTo(ConfigurableModule.builder().build().getProviders()));
  System.out.println(new ModuleImpl().getProviders());
  String additional = ReactiveSeq
      .fromStream(
          Arrays.asList(new MyPlugin())
              .stream()).filter(module -> module.providers()!=null)
              .concatMap(Plugin::providers)
              .join(",");
  
  assertThat(additional, equalTo("com.my.new.provider,com.my.new.provider2"));
}

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

public void addServlet(ServerData serverData, ServletContext webappContext) {
  List<RestConfiguration> restConfigList = ReactiveSeq.fromStream(PluginLoader.INSTANCE.plugins.get()
                                                 .stream())
                            .filter(module -> module.restServletConfiguration() != null)

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

/**
 * @return This type as a reversed Stream
 */
default ReactiveSeq<T> reveresedStream() {
  return ReactiveSeq.fromStream(reveresedStream());
}

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

@Override
public ReactiveSeq<T> stream(final Continueable s) {
  this.sub = s;
  listeningStreams.incrementAndGet(); //assumes all Streams that ever connected, remain connected
  return ReactiveSeq.fromStream(closingStream(this::get, s));
}

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

public ReactiveSeq<Collection<T>> streamBatch(final Continueable s,
    final Function<BiFunction<Long, TimeUnit, T>, Supplier<Collection<T>>> batcher) {
  this.sub = s;
  listeningStreams.incrementAndGet(); //assumes all Streams that ever connected, remain connected
  return ReactiveSeq.fromStream(closingStreamBatch(batcher.apply((timeout, timeUnit) -> ensureOpen(timeout, timeUnit)), s));
}
public ReactiveSeq<Seq<T>> streamGroupedByTime(long time, TimeUnit t){

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

public ReactiveSeq<CompletableFuture<T>> streamControlFutures(final Continueable s, final Function<Supplier<T>, CompletableFuture<T>> batcher) {
  this.sub = s;
  listeningStreams.incrementAndGet(); //assumes all Streams that ever connected, remain connected
  return ReactiveSeq.fromStream(closingStreamFutures(() -> batcher.apply(() -> ensureOpen(this.timeout, this.timeUnit)), s));
}

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

public ReactiveSeq<Collection<T>> streamBatchNoTimeout(final Continueable s, final Function<Supplier<T>, Supplier<Collection<T>>> batcher) {
  this.sub = s;
  listeningStreams.incrementAndGet(); //assumes all Streams that ever connected, remain connected
  return ReactiveSeq.fromStream(closingStreamBatch(batcher.apply(() -> ensureOpen(this.timeout, this.timeUnit)), s));
}

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

public ReactiveSeq<T> streamControl(final Continueable s, final Function<Supplier<T>, Supplier<T>> batcher) {
  listeningStreams.incrementAndGet(); //assumes all Streams that ever connected, remain connected
  return ReactiveSeq.fromStream(closingStream(batcher.apply(() -> ensureOpen(this.timeout, this.timeUnit)), s));
}

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

/**
 * @return Sequential Infinite (until Queue is closed) Stream of data from
 *         this Queue
 *
 */
@Override
public ReactiveSeq<T> stream() {
  listeningStreams.incrementAndGet(); //assumes all Streams that ever connected, remain connected
  return ReactiveSeq.fromStream(closingStream(this::get, new AlwaysContinue()));
}
/**

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

public static  <L,T> Either<L,Stream<T>> sequence(Stream<? extends Either<L,T>> stream) {
 Either<L, Stream<T>> identity = Either.right(ReactiveSeq.empty());
 BiFunction<Either<L,Stream<T>>,Either<L,T>,Either<L,Stream<T>>> combineToStream = (acc,next) ->acc.zip(next,(a,b)->ReactiveSeq.fromStream(a).append(b));
 BinaryOperator<Either<L,Stream<T>>> combineStreams = (a,b)-> a.zip(b,(z1,z2)->ReactiveSeq.fromStream(z1).appendStream(z2));
 return stream.reduce(identity,combineToStream,combineStreams);
}
public static <L,T,R> Either<L,Stream<R>> traverse(Function<? super T,? extends R> fn,Stream<Either<L,T>> stream) {

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

@Test
public void cycleWhile(){
  of(1).toList();
  count =0;
  List<Integer> b= ReactiveSeq.fromStream(Stream.of(1, 2, 3)).peek(System.out::println)
      .cycleUntil(next->count++==6).toList();
  System.out.println("B " + b);
  assertEquals(asList(1, 2,3, 1, 2,3),b);
}
@Test

相关文章

微信公众号

最新文章

更多

ReactiveSeq类方法