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

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

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

ReactiveSeq.map介绍

暂无

代码示例

代码示例来源: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")
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

public ReactiveSeq<Tuple2<String,String>> extractResources() {
  return resources.stream().peek(resource -> logMissingPath(resource))
              .filter(resource-> resource.getClass().getAnnotation(Path.class)!=null)
              .map(resource -> Tuple.tuple(resource.getClass().getName(),
                  resource.getClass().getAnnotation(Path.class).value()));
}

代码示例来源: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

public List<Thread> run() {
  register.ifPresent( reg -> 
    reg.register(
      apps.stream().map(app -> app.getServerData())
        .collect(Collectors.toList())
        .toArray(new ServerData[0])));
  Map<ServerApplication,CompletableFuture> mapFutures = new HashMap<>();
  apps.stream().forEach(app -> mapFutures.put(app,new CompletableFuture()));
  
  List<Thread> threads = apps.stream().map(app -> start(app, app.getServerData().getModule(),mapFutures.get(app))).collect(Collectors.toList());
  mapFutures.values().forEach(future -> get(future));
  
  logger.info("Started {} Rest applications ", apps.size());
  return threads;
}

代码示例来源: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

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 List<ServletRequestListener> getRequestListeners(ServerData data) {
  return PluginLoader.INSTANCE.plugins.get()
                    .stream()
                    .filter(module -> module.servletRequestListeners() != null)
                    .concatMap(Plugin::servletRequestListeners)
                    .map(fn -> fn.apply(data))
                     .to(ListX::fromIterable);
}

代码示例来源: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

private ReactiveSeq<SystemData<String, String>> create(DataLoader dl) {
    return ReactiveSeq.generate(() -> 1)
      .filter(in -> condition.shouldLoad())
      .map(in -> dl.scheduleAndLog())
      .peek(sd -> bus.post(sd));
  }
}

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

default List<ServletContextListener> getListeners(ServerData data) {
  List<ServletContextListener> list = new ArrayList<>();
  if (data.getRootContext() instanceof WebApplicationContext) {
    list.add(new ContextLoaderListener(
                      (WebApplicationContext) data.getRootContext()));
  }
  ListX<Plugin> modules = PluginLoader.INSTANCE.plugins.get();
  ListX<ServletContextListener> listeners = modules.stream()
                            .filter(module -> module.servletContextListeners() != null)
                            .concatMap(Plugin::servletContextListeners)
                            .map(fn -> fn.apply(data))
                            .to(ListX::fromIterable);
  return listeners.plusAll(list);
}

代码示例来源: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 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

public void schedule() {
    cleaner.forEach(cl -> {
      ReactiveSeq.generate(() -> 1)
            .filter(in -> condition.shouldClean())
            .map(i -> cl.scheduleAndLog())
            .peek(sd -> bus.post(sd))
            .schedule(cl.getCron(), executor);
    });
  }
}

代码示例来源: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

@Override
public ConfigurableApplicationContext createSpringApp(Config config, Class... classes) {
  logger.debug("Configuring Spring");
  AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
  rootContext.setAllowCircularReferences(config.isAllowCircularReferences());
  rootContext.register(classes);
  rootContext.scan(config.getBasePackages());
  rootContext.refresh();
  logger.debug("Configuring Additional Spring Beans");
  ConfigurableListableBeanFactory beanFactory = ((ConfigurableApplicationContext) rootContext).getBeanFactory();
  config.getDataSources()
     .stream()
      .map(Tuple2::_1)
     .filter(it -> !new ConfigAccessor().get()
                       .getDefaultDataSourceName()
                       .equals(it))
     .forEach(name -> {
       List<SpringDBConfig> dbConfig = getConfig(config, rootContext, beanFactory);
       dbConfig.forEach(spring -> spring.createSpringApp(name));
     });
  logger.debug("Finished Configuring Spring");
  return rootContext;
}

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

@Test
public void properties() {
  assertThat(configurer.buildConfig(MicroserverConfigurerTest.class).getProperties().stream().map(Tuple2::_1).toSet(), hasItem("hello"));
  assertThat(configurer.buildConfig(MicroserverConfigurerTest.class).getProperties().stream().map(Tuple2::_2).toSet(), hasItem("world"));
}

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

.stream())
.filter(module -> module.restServletConfiguration() != null)
.map(Plugin::restServletConfiguration)
.flatMap(Streams::optionalToStream)
.toList();

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

@Override
public ReactiveSeq<T> cycle() {
  ReactiveSeq<T> cycling = collectAll(Collectors.toList())
      .map(s -> Spouts.fromIterable(s).cycle(Long.MAX_VALUE))
      .flatMap(i -> i);
  return createSeq(new IterableSourceOperator<T>(cycling), SYNC);
}

相关文章

微信公众号

最新文章

更多

ReactiveSeq类方法