private static boolean isStopped(@Nullable Server server) { return server == null || server.activePorts().isEmpty(); }
/** * Stops the {@link Server} asynchronously. * * @return the {@link CompletableFuture} that will complete when the {@link Server} is stopped. */ public CompletableFuture<Void> stop() { final Server server = this.server.getAndSet(null); if (server == null || server.activePorts().isEmpty()) { return CompletableFuture.completedFuture(null); } return server.stop(); }
@Override public String toString() { return MoreObjects.toStringHelper(this) .add("config", config()) .add("activePorts", activePorts()) .add("state", startStop) .toString(); }
private boolean hasSessionProtocol(SessionProtocol protocol) { final Server server = this.server.get(); return server != null && server.activePorts().values().stream() .anyMatch(port -> port.hasProtocol(protocol)); }
/** * Returns the port number of the {@link Server} for the specified {@link SessionProtocol}. * * @throws IllegalStateException if the {@link Server} is not started or it did not open a port of the * specified protocol. */ public int port(SessionProtocol protocol) { return server().activePorts().values().stream() .filter(p1 -> p1.hasProtocol(protocol)).findAny() .flatMap(p -> Optional.of(p.localAddress().getPort())) .orElseThrow(() -> new IllegalStateException(protocol + " port not open")); }
@Override public synchronized void start() { try { if (!isRunning) { server.start().get(); if (port == 0) { // Replace the specified port number with the primary port number. // Server#activePort doesn't return the first added port, so we need to find that. final Optional<ServerPort> port = server.activePorts().values().stream() .filter(p -> p.protocols().contains(protocol)) .filter(p -> address == null || Arrays.equals(address.getAddress(), p.localAddress().getAddress().getAddress())) .findFirst(); assert port.isPresent() : "the primary port doest not exist."; this.port = port.get().localAddress().getPort(); } isRunning = true; } } catch (Exception cause) { throw new WebServerException("Failed to start " + ArmeriaWebServer.class.getSimpleName(), Exceptions.peel(cause)); } }
@Test public void testPortConfiguration() throws Exception { final Collection<ServerPort> ports = server.activePorts().values(); assertThat(ports.stream().filter(ServerPort::hasHttp)).hasSize(3); assertThat(ports.stream().filter(p -> p.localAddress().getAddress().isAnyLocalAddress())).hasSize(2); assertThat(ports.stream().filter(p -> p.localAddress().getAddress().isLoopbackAddress())).hasSize(1); }
@BeforeClass public static void init() throws Exception { server.start().get(); httpPort = server.activePorts().values().stream() .filter(ServerPort::hasHttp).findAny().get() .localAddress().getPort(); httpsPort = server.activePorts().values().stream() .filter(ServerPort::hasHttps).findAny().get() .localAddress().getPort(); }
@Before public void init() throws Exception { httpPort = server.activePorts() .values() .stream() .filter(ServerPort::hasHttp) .findAny() .get() .localAddress() .getPort(); }
logger.info("Armeria server started at ports: {}", s.activePorts()); return s;
server.start().get(); httpPort = server.activePorts().values().stream() .filter(ServerPort::hasHttp).findAny().get().localAddress() .getPort(); httpsPort = server.activePorts().values().stream() .filter(ServerPort::hasHttps).findAny().get().localAddress() .getPort();
/** * Returns the ports of the server. * * @return the {@link Map} which contains the pairs of local {@link InetSocketAddress} and * {@link ServerPort} is the server is started. {@link Optional#empty()} otherwise. */ public Map<InetSocketAddress, ServerPort> activePorts() { final Server server = this.server; if (server != null) { return server.activePorts(); } else { return Collections.emptyMap(); } }
/** * Returns the ports of the server. * * @return the {@link Map} which contains the pairs of local {@link InetSocketAddress} and * {@link ServerPort} is the server is started. {@link Optional#empty()} otherwise. */ public Map<InetSocketAddress, ServerPort> activePorts() { final Server server = this.server; if (server != null) { return server.activePorts(); } else { return Collections.emptyMap(); } }
/** * Returns the ports of the server. * * @return the {@link Map} which contains the pairs of local {@link InetSocketAddress} and * {@link ServerPort} is the server is started. {@link Optional#empty()} otherwise. */ public Map<InetSocketAddress, ServerPort> activePorts() { final Server server = this.server; if (server != null) { return server.activePorts(); } else { return Collections.emptyMap(); } }
logger.info("Started the RPC server at: {}", server.activePorts()); logger.info("Started the Central Dogma successfully."); success = true;
logger.info("Started the RPC server at: {}", server.activePorts()); logger.info("Started the Central Dogma successfully."); success = true;
logger.info("Started the RPC server at: {}", server.activePorts()); logger.info("Started the Central Dogma successfully"); success = true;
logger.info("Armeria server started at ports: {}", s.activePorts()); return s;
logger.info("Armeria server started at ports: {}", s.activePorts()); return s;
logger.info("Armeria server started at ports: {}", s.activePorts()); return s;