/** * Unregisters a listener from this store. * * @param name The configuration name to listen for. * @param l The listener to unregister. * @return This object (for method chaining). */ public synchronized ConfigStore unregister(String name, ConfigStoreListener l) { name = resolveName(name); Set<ConfigStoreListener> s = listeners.get(name); if (s != null) s.remove(l); return this; }
/** * Unregisters a listener from this store. * * @param name The configuration name to listen for. * @param l The listener to unregister. * @return This object (for method chaining). */ public synchronized ConfigStore unregister(String name, ConfigStoreListener l) { name = resolveName(name); Set<ConfigStoreListener> s = listeners.get(name); if (s != null) s.remove(l); return this; }
/** * Convenience method for updating the contents of a file with lines. * * @param name The config name (e.g. the filename without the extension). * @param contentLines The new contents. * @return This object (for method chaining). */ public synchronized ConfigStore update(String name, String...contentLines) { name = resolveName(name); StringBuilder sb = new StringBuilder(); for (String l : contentLines) sb.append(l).append('\n'); return update(name, sb.toString()); }
/** * Registers a new listener on this store. * * @param name The configuration name to listen for. * @param l The new listener. * @return This object (for method chaining). */ public synchronized ConfigStore register(String name, ConfigStoreListener l) { name = resolveName(name); Set<ConfigStoreListener> s = listeners.get(name); if (s == null) { s = Collections.synchronizedSet(Collections.newSetFromMap(new IdentityHashMap<ConfigStoreListener,Boolean>())); listeners.put(name, s); } s.add(l); return this; }
/** * Registers a new listener on this store. * * @param name The configuration name to listen for. * @param l The new listener. * @return This object (for method chaining). */ public synchronized ConfigStore register(String name, ConfigStoreListener l) { name = resolveName(name); Set<ConfigStoreListener> s = listeners.get(name); if (s == null) { s = Collections.synchronizedSet(Collections.newSetFromMap(new IdentityHashMap<ConfigStoreListener,Boolean>())); listeners.put(name, s); } s.add(l); return this; }
/** * Convenience method for updating the contents of a file with lines. * * @param name The config name (e.g. the filename without the extension). * @param contentLines The new contents. * @return This object (for method chaining). */ public synchronized ConfigStore update(String name, String...contentLines) { name = resolveName(name); StringBuilder sb = new StringBuilder(); for (String l : contentLines) sb.append(l).append('\n'); return update(name, sb.toString()); }
/** * Called when the physical contents of a config file have changed. * * <p> * Triggers calls to {@link ConfigStoreListener#onChange(String)} on all registered listeners. * * @param name The config name (e.g. the filename without the extension). * @param contents The new contents. * @return This object (for method chaining). */ public synchronized ConfigStore update(String name, String contents) { name = resolveName(name); Set<ConfigStoreListener> s = listeners.get(name); if (s != null) for (ConfigStoreListener l : listeners.get(name)) l.onChange(contents); return this; }
/** * Called when the physical contents of a config file have changed. * * <p> * Triggers calls to {@link ConfigStoreListener#onChange(String)} on all registered listeners. * * @param name The config name (e.g. the filename without the extension). * @param contents The new contents. * @return This object (for method chaining). */ public synchronized ConfigStore update(String name, String contents) { name = resolveName(name); Set<ConfigStoreListener> s = listeners.get(name); if (s != null) for (ConfigStoreListener l : listeners.get(name)) l.onChange(contents); return this; }
/** * Returns a map file containing the parsed contents of a configuration. * * @param name The configuration name. * @return * The parsed configuration. * <br>Never <jk>null</jk>. * @throws IOException */ public synchronized ConfigMap getMap(String name) throws IOException { name = resolveName(name); ConfigMap cm = configMaps.get(name); if (cm != null) return cm; cm = new ConfigMap(this, name); ConfigMap cm2 = configMaps.putIfAbsent(name, cm); if (cm2 != null) return cm2; register(name, cm); return cm; }
/** * Returns a map file containing the parsed contents of a configuration. * * @param name The configuration name. * @return * The parsed configuration. * <br>Never <jk>null</jk>. * @throws IOException */ public synchronized ConfigMap getMap(String name) throws IOException { name = resolveName(name); ConfigMap cm = configMaps.get(name); if (cm != null) return cm; cm = new ConfigMap(this, name); ConfigMap cm2 = configMaps.putIfAbsent(name, cm); if (cm2 != null) return cm2; register(name, cm); return cm; }