/** * Return this server's port. * @return The port the server is bound to. */ public int getPort() { return context.address().getPort(); }
/** * Return the server's host String. That is, the hostname or in case the server was bound * to a literal IP adress, the IP string representation (rather than performing a reverse-DNS * lookup). * * @return the host string, without reverse DNS lookup * @see NettyContext#address() * @see InetSocketAddress#getHostString() */ public String getHost() { return context.address().getHostString(); }
/** * Get the address of the remote peer. * * @return the peer's address */ default InetSocketAddress remoteAddress() { return context().address(); }
public BlockingNettyContext(Mono<? extends NettyContext> contextAsync, String description, Duration lifecycleTimeout) { this.description = description; this.lifecycleTimeout = lifecycleTimeout; this.context = contextAsync .timeout(lifecycleTimeout, Mono.error(new TimeoutException(description + " couldn't be started within " + lifecycleTimeout.toMillis() + "ms"))) .doOnNext(ctx -> LOG.info("Started {} on {}", description, ctx.address())) .block(); }
protected void shutdownFromJVM() { if (context.isDisposed()) { return; } final String hookDesc = Thread.currentThread().toString(); context.dispose(); context.onClose() .doOnError(e -> LOG.error("Stopped {} on {} with an error {} from JVM hook {}", description, context.address(), e, hookDesc)) .doOnTerminate(() -> LOG.info("Stopped {} on {} from JVM hook {}", description, context.address(), hookDesc)) .timeout(lifecycleTimeout, Mono.error(new TimeoutException(description + " couldn't be stopped within " + lifecycleTimeout.toMillis() + "ms"))) .block(); } }
/** * Shut down the {@link NettyContext} and wait for its termination, up to the * {@link #setLifecycleTimeout(Duration) lifecycle timeout}. */ public void shutdown() { if (context.isDisposed()) { return; } removeShutdownHook(); //only applies if not called from the hook's thread context.dispose(); context.onClose() .doOnError(e -> LOG.error("Stopped {} on {} with an error {}", description, context.address(), e)) .doOnTerminate(() -> LOG.info("Stopped {} on {}", description, context.address())) .timeout(lifecycleTimeout, Mono.error(new TimeoutException(description + " couldn't be stopped within " + lifecycleTimeout.toMillis() + "ms"))) .block(); }