/** * Loads configuration from a file * * @throws RuntimeException if the file is invalid or non existent */ private StatfulMetricsOptions buildFromFile(final Vertx vertx, final String configPath) { FileResolver fileResolver = new FileResolver(vertx); File file = fileResolver.resolveFile(configPath); try (Scanner scanner = new Scanner(file)) { scanner.useDelimiter("\\A"); String metricsConfigString = scanner.next(); return new StatfulMetricsOptions(new JsonObject(metricsConfigString)); } catch (IOException | DecodeException exception) { LOGGER.error("Error while reading metrics config file", exception); throw new RuntimeException("wrong configuration provided"); } }
private JsonObject loadOptionsFile(String configPath, FileResolver fileResolver) { File file = fileResolver.resolveFile(configPath); try (Scanner scanner = new Scanner(file)) { scanner.useDelimiter("\\A"); String metricsConfigString = scanner.next(); return new JsonObject(metricsConfigString); } catch (IOException ioe) { logger.error("Error while reading metrics config file", ioe); } catch (DecodeException de) { logger.error("Error while decoding metrics config file into JSON", de); } return new JsonObject(); }
/** * 配置vertx的文件缓存功能,默认关闭 */ protected static void configureVertxFileCaching() { if (System.getProperty(FileResolver.DISABLE_CP_RESOLVING_PROP_NAME) == null) { System.setProperty(FileResolver.DISABLE_CP_RESOLVING_PROP_NAME, "true"); } }