public interface HttpServer
Every instance of this HttpServer have a identity name() which also means that the different
instance should be isolated with others.
All the requests received would be handled by the request handler you set by handle(Consumer).
| 限定符和类型 | 方法和说明 |
|---|---|
SocketAddress |
address()
Returns the
SocketAddress that the server is listening on. |
void |
await()
Waits for this server to be closed.
|
void |
awaitUninterruptibly()
Waits for this server to be closed.
|
io.netty.channel.EventLoopGroup |
bossGroup()
Returns the boss
EventLoopGroup which is used to accepting new connections. |
void |
close()
Closes current server.
|
io.netty.util.concurrent.Future<Void> |
closeFuture()
Returns the
Future which is notified when server is closed(probably by calling close()). |
static HttpServer |
create()
Creates a new instance of
HttpServer by the default options. |
static HttpServer |
create(ServerOptions options)
Creates a new instance of
HttpServer by the options. |
static HttpServer |
create(String name,
ServerOptions options)
|
HttpServer |
handle(Consumer<RequestHandle> h)
Sets the handler for handing requests received.
|
io.netty.channel.EventLoopGroup |
ioGroup()
Returns the io
EventLoopGroup which is used to handing I/O events. |
HttpServer |
listen(int port)
Starts the server which is listening on the given
port. |
HttpServer |
listen(SocketAddress address)
Starts the server which is listening on the given
address. |
HttpServer |
listen(String host,
int port)
Starts the server which is listening on the given
host and port. |
Metrics |
metrics()
Returns the metrics of current server.
|
String |
name()
Returns the identity name of this server.
|
HttpServer |
onClose(Runnable closure)
Adds a close hook which will be called when server is about to closing.
|
HttpServer |
onConnected(Consumer<io.netty.channel.ChannelHandlerContext> h)
Sets the handler for listening connection connected.
|
HttpServer |
onDisconnected(Consumer<io.netty.channel.Channel> h)
Sets the handler for listening connection disconnected.
|
static HttpServer create()
HttpServer by the default options.HttpServerstatic HttpServer create(ServerOptions options)
HttpServer by the options.options - optionsHttpServerstatic HttpServer create(String name, ServerOptions options)
name - server nameoptions - optionsHttpServerHttpServer handle(Consumer<RequestHandle> h)
h - handlerHttpServer onConnected(Consumer<io.netty.channel.ChannelHandlerContext> h)
h - handlerHttpServer onDisconnected(Consumer<io.netty.channel.Channel> h)
h - handlerHttpServer onClose(Runnable closure)
closure - hookHttpServer listen(int port)
port.port - port to listen onHttpServer listen(String host, int port)
host and port.host - host to listen onport - port to listen onHttpServer listen(SocketAddress address)
address.address - address to listen onString name()
!Note: this name would not be same with the name you passed in the create(String, ServerOptions)
for avoiding passing the same many a time
void await()
throws InterruptedException
void awaitUninterruptibly()
io.netty.util.concurrent.Future<Void> closeFuture()
Future which is notified when server is closed(probably by calling close()).io.netty.channel.EventLoopGroup bossGroup()
EventLoopGroup which is used to accepting new connections.EventLoopGroup or null if server is not running.io.netty.channel.EventLoopGroup ioGroup()
EventLoopGroup which is used to handing I/O events.EventLoopGroup or null if server is not running.SocketAddress address()
SocketAddress that the server is listening on.SocketAddress or null if server is not running.Metrics metrics()
This method will never return null, but may return an Metrics which does not have any metrics.
void close()
Copyright © 2020. All rights reserved.