use of com.firenio.common.Properties in project baseio by generallycloud.
the class TestHttpBootstrapEngine method bootstrap.
@Override
public void bootstrap(String rootPath, boolean prodMode) throws Exception {
ClassLoader cl = this.getClass().getClassLoader();
boolean debug = Util.isTrueValue(System.getProperty("http.debug"));
if (debug) {
for (; debug; ) {
Util.sleep(100);
}
}
DevelopConfig.NATIVE_DEBUG = true;
DevelopConfig.BUF_DEBUG = true;
DevelopConfig.BUF_PATH_DEBUG = true;
DevelopConfig.SSL_DEBUG = true;
DevelopConfig.CHANNEL_DEBUG = true;
DevelopConfig.DEBUG_ERROR = true;
Options.setEnableEpoll(true);
Options.setEnableUnsafe(true);
Options.setEnableOpenssl(true);
Options.setBufThreadYield(true);
// Options.setEnableUnsafeBuf(true);
HttpDateUtil.start();
final SpringHttpFrameHandle handle = new SpringHttpFrameHandle();
Properties properties = FileUtil.readPropertiesByCls("server.properties", cl);
NioEventLoopGroup group = new NioEventLoopGroup(true);
ChannelAcceptor context = new ChannelAcceptor(group);
ConfigurationParser.parseConfiguration("server.", context, properties);
ConfigurationParser.parseConfiguration("server.", group, properties);
context.setIoEventHandle(handle);
context.addChannelIdleEventListener(new ChannelAliveListener());
context.addChannelEventListener(new WebSocketChannelListener());
context.addChannelEventListener(new LoggerChannelOpenListener());
context.addChannelEventListener(new CountChannelListener());
context.setExecutorGroup(new ThreadEventLoopGroup());
context.addLifeCycleListener(new LifeCycleListener() {
@Override
public void lifeCycleStarting(LifeCycle lifeCycle) {
try {
handle.initialize(context, rootPath, prodMode);
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
}
@Override
public void lifeCycleStopped(LifeCycle lifeCycle) {
handle.destroy(context);
}
});
String[] applicationProtocols = null;
if (properties.getBooleanProperty("app.enableHttp2")) {
context.addProtocolCodec(new Http2Codec());
applicationProtocols = new String[] { "h2", "http/1.1" };
} else {
context.addProtocolCodec(new HttpCodec(4));
context.addProtocolCodec(new WebSocketCodec());
}
int defaultPort = 80;
String pem = properties.getProperty("server.sslPem");
if (!Util.isNullOrBlank(pem)) {
defaultPort = 443;
SslContext sslContext = loadSslContextFromPem(pem, applicationProtocols, cl);
context.setSslContext(sslContext);
}
int port = properties.getIntegerProperty("server.port", defaultPort);
context.setPort(port);
try {
context.bind();
} catch (Exception e) {
HttpDateUtil.stop();
group.stop();
throw e;
}
this.group = group;
this.context = context;
if (properties.getBooleanProperty("app.proxy")) {
NetDataTransferServer.get().startup(group, 18088);
}
}
Aggregations