Interface Server
public interface Server
An HTTP server providing transport for Exonum transactions and read-requests.
-
Method Summary
Modifier and Type Method Description static Server
create()
Creates an HTTP server with no request handlers.io.vertx.ext.web.Router
createRouter()
Creates a request router.java.util.OptionalInt
getActualPort()
Returns a port this server is listening at, orOptionalInt.empty()
if it does not currently accept requests.void
mountSubRouter(java.lang.String mountPoint, io.vertx.ext.web.Router subRouter)
Mounts the sub router on the root router of this server.void
removeSubRouter(java.lang.String mountPoint)
Removes the sub router from the root router of this server registered by the given path.java.util.concurrent.CompletableFuture<java.lang.Integer>
start(int port)
Requests the server to start listening on the given TCP port.java.util.concurrent.CompletableFuture<java.lang.Void>
stop()
Requests the server to stop listening to incoming requests and release any resources.
-
Method Details
-
create
Creates an HTTP server with no request handlers.Use
start(int)
to start listening to incoming requests. -
createRouter
io.vertx.ext.web.Router createRouter()Creates a request router. The router is empty: it has no routes to request handlers set up.- Returns:
- a new request router
-
mountSubRouter
void mountSubRouter(java.lang.String mountPoint, io.vertx.ext.web.Router subRouter)Mounts the sub router on the root router of this server. You can do that before or after the server has started.Please note that the prefix is stripped from the path when request is forwarded to the sub-router. For example, to handle requests to '/cryptocurrency/send-money' and '/cryptocurrency/balance', use prefix '/cryptocurrency' and a router forwarding requests to '/send-money' and '/balance' to the appropriate handlers.
- Parameters:
mountPoint
- a mount point (a path prefix) to mount it onsubRouter
- a router responsible for handling requests that have the given path prefix
-
removeSubRouter
void removeSubRouter(java.lang.String mountPoint)Removes the sub router from the root router of this server registered by the given path. In case missing path nothing would happen.- Parameters:
mountPoint
- a mount point i.e. a mounted router path
-
start
java.util.concurrent.CompletableFuture<java.lang.Integer> start(int port)Requests the server to start listening on the given TCP port.- Parameters:
port
- a port to listen on- Returns:
- a future that is completed when the server is started or failed to do so; on success, will have the actual TCP port on which this server is currently listening
-
getActualPort
java.util.OptionalInt getActualPort()Returns a port this server is listening at, orOptionalInt.empty()
if it does not currently accept requests. -
stop
java.util.concurrent.CompletableFuture<java.lang.Void> stop()Requests the server to stop listening to incoming requests and release any resources. Blocking handlers processing requests will be interrupted.Subsequent invocations have no effect. Once stopped, the server cannot be restarted. Please create a new server.
- Returns:
- a future that is completed when the server is stopped
-