- private static boolean starting = false;
- private static boolean ready = false;
-
- private static List<Callback> callbacks = new ArrayList<TransliteratorManager.Callback>();
-
- public static synchronized boolean init(final Callback callback) {
- if (ready) {
- return true;
+ private static boolean starting = false;
+ private static boolean ready = false;
+ private static ThreadSetup threadSetup = null;
+ private static final LRUCacheMap<String, Transliterator> cache = new LRUCacheMap<>(4);
+
+ // Whom to notify when we're all set up and ready to go.
+ private static final List<Callback> callbacks = new ArrayList<>();
+
+ public static Transliterator get(String rules) {
+ // DO NOT make the method synchronized!
+ // synchronizing on the class would break the whole
+ // asynchronous init concept, since the runnable
+ // then holds the same lock as the init function needs.
+ Transliterator result;
+ synchronized (cache) {
+ result = cache.get(rules);
+ if (result == null) {
+ result = Transliterator.createFromRules("", rules, Transliterator.FORWARD);
+ cache.put(rules, result);
+ }
+ }
+ return result;