]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.init/src/org/argeo/init/prefs/ThinPreferencesFactory.java
Improve init launch
[lgpl/argeo-commons.git] / org.argeo.init / src / org / argeo / init / prefs / ThinPreferencesFactory.java
1 package org.argeo.init.prefs;
2
3 import java.util.concurrent.CompletableFuture;
4 import java.util.concurrent.ExecutionException;
5 import java.util.prefs.Preferences;
6 import java.util.prefs.PreferencesFactory;
7
8 public class ThinPreferencesFactory implements PreferencesFactory {
9 private static CompletableFuture<ThinPreferencesFactory> INSTANCE = new CompletableFuture<>();
10
11 private SystemRootPreferences systemRootPreferences;
12
13 public ThinPreferencesFactory() {
14 systemRootPreferences = new SystemRootPreferences();
15 if (INSTANCE.isDone())
16 throw new IllegalStateException(
17 "There is already a " + ThinPreferencesFactory.class.getName() + " instance.");
18 INSTANCE.complete(this);
19 }
20
21 @Override
22 public Preferences systemRoot() {
23 return systemRootPreferences;
24 }
25
26 @Override
27 public Preferences userRoot() {
28 throw new UnsupportedOperationException();
29 }
30
31 public SystemRootPreferences getSystemRootPreferences() {
32 return systemRootPreferences;
33 }
34
35 public static ThinPreferencesFactory getInstance() {
36 try {
37 return INSTANCE.get();
38 } catch (InterruptedException | ExecutionException e) {
39 throw new IllegalStateException("Cannot get " + ThinPreferencesFactory.class.getName() + " instance.", e);
40 }
41 }
42 }