public List<Thread> start() { List<ServerApplication> apps = modules.map(module -> createServer(module)); ServerRunner runner; try { runner = new ServerRunner( springContext.getBean(ApplicationRegister.class), apps, end); } catch (BeansException e) { runner = new ServerRunner( apps, end); } return runner.run(); }
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; }
@Test public void testRun() { serverRunner.run(); assertThat(server1Count,is(1)); assertThat(server2Count,is(1)); } }
@Before public void setUp() { server1Count =0; server2Count =0; ServerData data1 = new ServerData(8080,Arrays.asList(), Mockito.mock(ApplicationContext.class), "url1", () -> "app-context"); ServerData data2 = new ServerData(8081, Arrays.asList(), Mockito.mock(ApplicationContext.class), "url2", () -> "test-context"); serverApplication1 = new GrizzlyApplication(AllData.builder().serverData(data1).build()){ @Override public void run(CompletableFuture start,JaxRsServletConfigurer jaxRsConfigurer, CompletableFuture end) { server1Count++; start.complete(true); } }; serverApplication2 = new GrizzlyApplication(AllData.builder().serverData(data2).build()){ @Override public void run(CompletableFuture start,JaxRsServletConfigurer jaxRsConfigurer,CompletableFuture end) { server2Count++; start.complete(true); } }; serverRunner = new ServerRunner( (array) -> {registered = array; } , Arrays.asList(serverApplication1, serverApplication2), new CompletableFuture()); }
public List<Thread> start() { List<ServerApplication> apps = modules.map(module -> createServer(module)); ServerRunner runner; try { runner = new ServerRunner( springContext.getBean(ApplicationRegister.class), apps, end); } catch (BeansException e) { runner = new ServerRunner( apps, end); } return runner.run(); }
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; }