} else { watcher = new PropertyFileWatcher(layers); loadRules(watcher.getProperties()); loadRules(watcher.getProperties()); lastModified = System.currentTimeMillis();
/** * Either loads the default property file on the first access, or reloads it if it has been * modified since last access. * * @throws DataAccessResourceFailureException */ void checkUserMap() throws DataAccessResourceFailureException { try { if ((userMap == null) || userDefinitionsFile == null || userDefinitionsFile.isStale()) { if (userDefinitionsFile == null) { Resource propFile = findUserProperties(); userDefinitionsFile = new PropertyFileWatcher(propFile); } userMap = loadUsersFromProperties(userDefinitionsFile.getProperties()); } } catch (Exception e) { LOGGER.log(Level.SEVERE, "An error occurred loading user definitions", e); } }
public boolean isStale() { return isModified(); }
/** * Ensure the user data map matches the information in the user data file. This should be called * automatically, so that no code outside of this class needs to access this method. */ private void update() { try { if (myWatcher != null && myWatcher.isStale()) { Properties prop = myWatcher.getProperties(); UserAttributeEditor uae = new UserAttributeEditor(); myDetailStorage.clear(); Iterator<Object> it = prop.keySet().iterator(); while (it.hasNext()) { String username = (String) it.next(); uae.setAsText(prop.getProperty(username)); UserAttribute attrs = (UserAttribute) uae.getValue(); if (attrs != null) { myDetailStorage.put(username, makeUser(username, attrs)); } } } } catch (IOException ioe) { // TODO: handle the exception properly myDetailStorage.clear(); createDefaultUser(); } }
/** * Create an EditableUserDAO object. This currently entails: * * <ul> * <li>Finding the user configuration file * <li>Creating a PropertyFileWatcher to track changes to it * <li>Loading the user details into a map in memory * </ul> * * If no user information is found, a default user will be created. */ public EditableUserDAO() { myDetailStorage = new HashMap<String, UserDetails>(); try { myWatcher = new PropertyFileWatcher(getUserFile()); } catch (Exception e) { // TODO:log error someplace createDefaultUser(); } update(); if (myDetailStorage.isEmpty()) createDefaultUser(); }
/** * Get Mapping, update from file if changed * * @param typeName * @return the mapping */ public CatalogStoreMapping getMapping(String typeName) { PropertyFileWatcher watcher = watchers.get(typeName); if (watcher!=null && watcher.isModified() ) { try { addMapping (typeName, CatalogStoreMapping.parse(new HashMap<String, String>((Map) watcher.getProperties()))); } catch (IOException e) { LOGGER.log(Level.WARNING, e.toString()); } } return super.getMapping( typeName); }
public boolean isModified() { return watcher != null && watcher.isStale(); }
private Set<String> reloadConfiguration() throws IOException { Properties props = configFile.getProperties(); if(props == null){ //file doesn't exist return Collections.emptySet(); } return loadConfiguration(props); }
final File file = watcher.getFile(); RemoteProcessFactoryConfiguration newConfiguration = null; try { if (file.exists() && file.canRead()) { Properties properties = watcher.getProperties();
final Resource file = watcher.getResource(); DownloadServiceConfiguration newConfiguration = null; try { if (Resources.exists(file) && Resources.canRead(file)) { Properties properties = watcher.getProperties();
/** Writes down the current users map to file system */ public void storeUsers() throws IOException { OutputStream os = null; try { // turn back the users into a users map Properties p = storeUsersToProperties(userMap); // write out to the data dir Resource propFile = userDefinitionsFile.getResource(); os = propFile.out(); p.store(os, null); } catch (Exception e) { if (e instanceof IOException) throw (IOException) e; else throw (IOException) new IOException("Could not write updated users list to file system") .initCause(e); } finally { if (os != null) os.close(); } }
public DefaultControlFlowConfigurator() { configFile = new PropertyFileWatcher(new File( GeoserverDataDirectory.getGeoserverDataDirectory(), "controlflow.properties")); }
/** * Get Mapping, update from file if changed * * @param typeName * @return the mapping */ public CatalogStoreMapping getMapping(String typeName) { PropertyFileWatcher watcher = watchers.get(typeName); if (watcher != null && watcher.isModified()) { try { addMapping( typeName, CatalogStoreMapping.parse( new HashMap<String, String>((Map) watcher.getProperties()))); } catch (IOException e) { LOGGER.log(Level.WARNING, e.toString()); } } return super.getMapping(typeName); }
public boolean isStale() { return configFile.isStale(); }
public List<FlowController> buildFlowControllers() throws Exception { timeout = -1; Properties p = configFile.getProperties(); List<FlowController> newControllers = new ArrayList<FlowController>(); for (Object okey : p.keySet()) {
/** * Create GeoServerInternalCatalogStore * * @param geoserver * @throws IOException */ public GeoServerInternalCatalogStore(GeoServer geoserver) throws IOException { super( geoserver.getCatalog()); GeoServerResourceLoader loader = geoserver.getCatalog().getResourceLoader(); File dir = loader.findOrCreateDirectory("csw"); for (Name name : descriptorByType.keySet()) { String typeName = name.getLocalPart(); File f = new File(dir, typeName + ".properties"); PropertyFileWatcher watcher = new PropertyFileWatcher(f); watchers.put(typeName, watcher); if (!f.exists()) { IOUtils.copy(getClass().getResourceAsStream(typeName + ".default.properties"),f); } addMapping (typeName, CatalogStoreMapping.parse(new HashMap<String, String>((Map) watcher.getProperties()))); } }
if ((userMap == null) || userDefinitionsFile == null || userDefinitionsFile.isStale()) { try { if (userDefinitionsFile == null) { userDefinitionsFile = new PropertyFileWatcher(propFile); userMap = Collections.emptyMap(); } else { userMap = new HashMap(userDefinitionsFile.getProperties());
@Test public void testPropertyFileWatcher() throws Exception { final File file = new File("testfile"); file.createNewFile(); final AtomicBoolean hasCalled = new AtomicBoolean( ); PropertyFileWatcher propertyFileWatcher = new PropertyFileWatcher(file) { protected void onChange ( final File localFile ) { hasCalled.set( true ); assertEquals( file, localFile ); } } Timer timer = new Timer(); timer.schedule(propertyFileWatcher, 2000); FileWriter fw = new FileWriter(file); fw.write("blah"); fw.close(); Thread.sleep(8000); // check if propertyFileWatcher.onChange was called assertTrue( hasCalled.get() ); file.delete(); }
@Override public void run() { if (watcher.isStale()) { // reload DownloadServiceConfiguration newConfiguration = loadConfiguration(); if (newConfiguration != null) { synchronized (newConfiguration) { configuration = newConfiguration; if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("New configuration loaded:\n" + configuration); } } } } }