use of org.cubeengine.module.apiserver.exception.ApiStartupException in project modules-extra by CubeEngine.
the class ApiServer method onEnable.
@Listener
public void onEnable(GamePostInitializationEvent event) {
reflector.getDefaultConverterManager().registerConverter(new InetAddressConverter(), InetAddress.class);
this.configure(reflector.load(ApiConfig.class, moduleFolder.resolve("webapi.yml").toFile()));
try {
this.start();
final ObjectMapper mapper = new ObjectMapper();
LoggerUtil.attachCallback(null, (f, a, t, msg) -> {
ObjectNode node = mapper.createObjectNode();
node.put("msg", msg);
this.fireEvent("console", node);
});
} catch (ApiStartupException ex) {
this.logger.error(ex, "The web API will not be available as the server failed to start properly...");
}
this.registerApiHandlers(ApiServer.class, new CommandController(i18n, tm, cm));
}
use of org.cubeengine.module.apiserver.exception.ApiStartupException in project modules-extra by CubeEngine.
the class ApiServer method start.
/**
* Starts the server
*
* @return fluent interface
*/
public ApiServer start() throws ApiStartupException {
if (!this.isRunning()) {
final ServerBootstrap serverBootstrap = new ServerBootstrap();
try {
this.eventLoopGroup.set(new NioEventLoopGroup(this.maxThreads.get(), tf));
serverBootstrap.group(this.eventLoopGroup.get()).channel(NioServerSocketChannel.class).childHandler(new ApiServerInitializer(cm, am, this)).localAddress(this.bindAddress.get(), this.port.get());
this.bootstrap.set(serverBootstrap);
this.channel.set(serverBootstrap.bind().sync().channel());
} catch (Exception e) {
this.bootstrap.set(null);
this.channel.set(null);
this.eventLoopGroup.getAndSet(null).shutdownGracefully(2, 5, TimeUnit.SECONDS);
throw new ApiStartupException("The API server failed to start!", e);
}
}
return this;
}
Aggregations