-
- public void stop() {
- if (refreshConfigTask != null) {
- refreshConfigTask.dispose();
- refreshConfigTask = null;
- }
- }
-
- /**
- * Reads the configuration from file.
- */
- public void loadConfigurationFromFile() {
- String filepath = getLocalConfigurationFilePath();
- if (filepath == null) {
- logger.debug("No localconfiguration file used");
- return;
- }
- GsonBuilder gsonBuilder = new GsonBuilder();
- ServiceLoader.load(TypeAdapterFactory.class).forEach(gsonBuilder::registerTypeAdapterFactory);
-
- try (InputStream inputStream = createInputStream(filepath)) {
- JsonParser parser = new JsonParser();
- JsonObject rootObject = getJsonElement(parser, inputStream).getAsJsonObject();
- if (rootObject == null) {
- throw new JsonSyntaxException("Root is not a json object");
- }
- ApplicationConfigParser appParser = new ApplicationConfigParser();
- appParser.parse(rootObject);
- setConfiguration(appParser.getRicConfigs());
- logger.info("Local configuration file loaded: {}", filepath);
- } catch (JsonSyntaxException | ServiceException | IOException e) {
- logger.trace("Local configuration file not loaded: {}", filepath, e);
- }
- }
-
- JsonElement getJsonElement(JsonParser parser, InputStream inputStream) {
- return parser.parse(new InputStreamReader(inputStream));
- }
-
- InputStream createInputStream(@NotNull String filepath) throws IOException {
- return new BufferedInputStream(new FileInputStream(filepath));
- }