Package com.linecorp.armeria.server
Class Server
java.lang.Object
com.linecorp.armeria.server.Server
- All Implemented Interfaces:
AsyncCloseable,ListenableAsyncCloseable,AutoCloseable
Listens to
ServerPorts and delegates client requests to Services.- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionintReturns the localServerPortthat thisServeris listening to.intactiveLocalPort(SessionProtocol protocol) Returns the localServerPortwhich serves the givenSessionProtocol.Returns the primaryServerPortthat thisServeris listening to.activePort(SessionProtocol protocol) Returns the primaryServerPortwhich serves the givenSessionProtocolthat thisServeris listening to.Returns allServerPorts that thisServeris listening to.voidaddListener(ServerListener listener) Adds the specifiedServerListenerto thisServer, so that it is notified when the state of thisServerchanges.voidWaits until the result ofCompletableFuturewhich is completed after theclose()orcloseAsync()operation is completed.static ServerBuilderbuilder()Creates a newServerBuilder.voidclose()Releases any underlying resources held by this object synchronously.Releases any underlying resources held by this object asynchronously.Registers a JVM shutdown hook that closes thisServerwhen the current JVM terminates.closeOnJvmShutdown(Runnable whenClosing) Registers a JVM shutdown hook that closes thisServerwhen the current JVM terminates.config()Returns the configuration of thisServer.Returns the hostname of the defaultVirtualHost, which is the hostname of the machine.booleanisClosed()Returns whetherAsyncCloseable.close()orAsyncCloseable.closeAsync()operation has been completed.booleanReturns whetherAsyncCloseable.close()orAsyncCloseable.closeAsync()has been called.Returns theMeterRegistrythat collects various stats.Returns aEventLoopfrom the worker group.intReturns the number of open connections on thisServer.voidreconfigure(ServerConfigurator serverConfigurator) Reconfigure Server configuration.booleanremoveListener(ServerListener listener) Removes the specifiedServerListenerfrom thisServer, so that it is not notified anymore when the state of thisServerchanges.start()stop()Stops thisServerto close all activeServerPorts.toString()Returns theCompletableFuturewhich is completed after theAsyncCloseable.close()orAsyncCloseable.closeAsync()operation is completed.
-
Method Details
-
builder
Creates a newServerBuilder. -
config
Returns the configuration of thisServer. -
serviceConfigs
-
defaultHostname
Returns the hostname of the defaultVirtualHost, which is the hostname of the machine. -
activePorts
Returns allServerPorts that thisServeris listening to.- Returns:
- a
Mapwhose key is the bind address and value isServerPort. an emptyMapif thisServerdid not start. - See Also:
-
activePort
Returns the primaryServerPortthat thisServeris listening to. If thisServerhas both a local port and a non-local port, the non-local port is returned.- Returns:
- the primary
ServerPort, ornullif thisServerdid not start.
-
activePort
Returns the primaryServerPortwhich serves the givenSessionProtocolthat thisServeris listening to. If thisServerhas both a local port and a non-local port, the non-local port is returned.- Returns:
- the primary
ServerPort, ornullif there is no active port available for the givenSessionProtocol.
-
activeLocalPort
public int activeLocalPort()Returns the localServerPortthat thisServeris listening to.- Throws:
IllegalStateException- if there is no active local port available or the server is not started yet
-
activeLocalPort
Returns the localServerPortwhich serves the givenSessionProtocol.- Throws:
IllegalStateException- if there is no active local port available for the givenSessionProtocolor the server is not started yet
-
meterRegistry
Returns theMeterRegistrythat collects various stats. -
addListener
Adds the specifiedServerListenerto thisServer, so that it is notified when the state of thisServerchanges. This method is useful when you want to initialize/destroy the resources associated with aService:> public class MyService extends SimpleService { > @Override > public void serviceAdded(Server server) { > server.addListener(new ServerListenerAdapter() { > @Override > public void serverStarting() { > ... initialize ... > } > > @Override > public void serverStopped() { > ... destroy ... > } > } > } > } -
removeListener
Removes the specifiedServerListenerfrom thisServer, so that it is not notified anymore when the state of thisServerchanges. -
start
Starts thisServerto listen to theServerPorts specified in theServerConfig. Note that the startup procedure is asynchronous and thus this method returns immediately. To wait until thisServeris fully started up, wait for the returnedCompletableFuture:ServerBuilder builder = Server.builder(); ... Server server = builder.build(); server.start().get(); -
stop
Stops thisServerto close all activeServerPorts. Note that the shutdown procedure is asynchronous and thus this method returns immediately. To wait until thisServeris fully shut down, wait for the returnedCompletableFuture:Server server = ...; server.stop().get(); -
nextEventLoop
Returns aEventLoopfrom the worker group. This can be used for, e.g., scheduling background tasks for the lifetime of theServerusingEventExecutorGroup.scheduleAtFixedRate(Runnable, long, long, TimeUnit). It is very important that these tasks do not block as this would block all requests in the server on thatEventLoop. -
isClosing
public boolean isClosing()Description copied from interface:ListenableAsyncCloseableReturns whetherAsyncCloseable.close()orAsyncCloseable.closeAsync()has been called.- Specified by:
isClosingin interfaceListenableAsyncCloseable- See Also:
-
isClosed
public boolean isClosed()Description copied from interface:ListenableAsyncCloseableReturns whetherAsyncCloseable.close()orAsyncCloseable.closeAsync()operation has been completed.- Specified by:
isClosedin interfaceListenableAsyncCloseable- See Also:
-
whenClosed
Description copied from interface:ListenableAsyncCloseableReturns theCompletableFuturewhich is completed after theAsyncCloseable.close()orAsyncCloseable.closeAsync()operation is completed.- Specified by:
whenClosedin interfaceListenableAsyncCloseable
-
closeAsync
Description copied from interface:AsyncCloseableReleases any underlying resources held by this object asynchronously.- Specified by:
closeAsyncin interfaceAsyncCloseable- Returns:
- the
CompletableFuturewhich is completed after the resources are released
-
close
public void close()Description copied from interface:AsyncCloseableReleases any underlying resources held by this object synchronously.- Specified by:
closein interfaceAsyncCloseable- Specified by:
closein interfaceAutoCloseable
-
numConnections
public int numConnections()Returns the number of open connections on thisServer. -
blockUntilShutdown
Waits until the result ofCompletableFuturewhich is completed after theclose()orcloseAsync()operation is completed.- Throws:
InterruptedException
-
toString
-
reconfigure
Reconfigure Server configuration. This feature is only available once a server is configured and started. We do not allow ports to be reconfigured. -
closeOnJvmShutdown
Registers a JVM shutdown hook that closes thisServerwhen the current JVM terminates. -
closeOnJvmShutdown
Registers a JVM shutdown hook that closes thisServerwhen the current JVM terminates.
-