public class StartupServer extends AbstractNettyServer
public static void main(String[] args) {
StartupServer startupServer = new StartupServer(8080);
List<AbstractProtocol> protocols = new ArrayList<>();
protocols.add(newHttpServletProtocol());
for (AbstractProtocol protocol : protocols) {
startupServer.getProtocolHandlers().add(protocol);
startupServer.getServerListeners().add(protocol);
}
startupServer.start();
}
private static HttpServletProtocol newHttpServletProtocol(){
ServletContext servletContext = new ServletContext();
servletContext.addServlet("myHttpServlet",new MyHttpServlet())
.addMapping("/test/sayHello");
HttpServletProtocol protocol = new HttpServletProtocol(null, servletContext);
protocol.setMaxBufferBytes(1024 * 1024);//The upper limit of the output stream buffer each connection, good speed write large dots. (Bytes. 1M)
return protocol;
}
you config this.| 构造器和说明 |
|---|
StartupServer(InetSocketAddress serverAddress) |
StartupServer(int port) |
| 限定符和类型 | 方法和说明 |
|---|---|
DynamicProtocolChannelHandler |
getDynamicProtocolChannelHandler() |
Collection<ProtocolHandler> |
getProtocolHandlers()
Gets the protocol registry list
|
Collection<ServerListener> |
getServerListeners()
Gets the server listener list
|
static InetSocketAddress |
getServerSocketAddress(InetAddress address,
int port) |
ServletContext |
getServletContext() |
void |
setDynamicProtocolChannelHandler(DynamicProtocolChannelHandler dynamicProtocolChannelHandler) |
void |
start() |
void |
stop() |
getBootstrap, getBoss, getIoRatio, getIoThreadCount, getName, getPort, getServerAddress, getServerChannel, getWorker, init, isEnableEpoll, run, setIoRatio, setIoThreadCount, toStringpublic StartupServer(int port)
public StartupServer(InetSocketAddress serverAddress)
public void start()
throws IllegalStateException
public void stop()
throws IllegalStateException
stop 在类中 AbstractNettyServerIllegalStateExceptionpublic ServletContext getServletContext()
public Collection<ProtocolHandler> getProtocolHandlers()
public Collection<ServerListener> getServerListeners()
public DynamicProtocolChannelHandler getDynamicProtocolChannelHandler()
public void setDynamicProtocolChannelHandler(DynamicProtocolChannelHandler dynamicProtocolChannelHandler)
public static InetSocketAddress getServerSocketAddress(InetAddress address, int port)
Copyright © 2021. All rights reserved.