public void init(@Nonnull GriffonApplication application) { boolean preferencesWereRead = false; try { preferencesPersistor.read(preferencesManager); preferencesWereRead = true; } catch (FileNotFoundException fnfe) { // most likely means preferences have not been initialized yet // let it continue preferencesWereRead = true; } catch (IOException e) { if (getLog().isWarnEnabled()) { getLog().warn("Cannot read preferences", sanitize(e)); } } if (preferencesWereRead) { application .getEventRouter() .addEventListener( ApplicationEvent.SHUTDOWN_START.getName(), new CallableWithArgs<Void>() { @Override @Nullable public Void call(@Nullable Object... args) { try { preferencesPersistor.write(preferencesManager); } catch (IOException e) { if (getLog().isWarnEnabled()) { getLog().warn("Cannot persist preferences", sanitize(e)); } } return null; } }); } }