Search in sources :

Example 1 with FileReloadContainer

use of org.opennms.core.spring.FileReloadContainer in project opennms by OpenNMS.

the class DirectoryWatcher method getContents.

/**
 * Gets the contents.
 *
 * @param fileName the file name
 * @return the contents
 * @throws FileNotFoundException the file not found exception
 */
public T getContents(String fileName) throws FileNotFoundException {
    File file = new File(m_directory, fileName);
    if (file.exists() && !file.isDirectory()) {
        FileReloadContainer<T> newContainer = new FileReloadContainer<T>(file, m_loader);
        newContainer.setReloadCheckInterval(0);
        FileReloadContainer<T> container = m_contents.putIfAbsent(fileName, newContainer);
        if (container == null) {
            LOG.debug("getting content of {}", file);
            container = newContainer;
        }
        return container.getObject();
    }
    m_contents.remove(fileName);
    throw new FileNotFoundException("there is no file called '" + fileName + "' in directory " + m_directory);
}
Also used : FileReloadContainer(org.opennms.core.spring.FileReloadContainer) FileNotFoundException(java.io.FileNotFoundException) File(java.io.File)

Aggregations

File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 FileReloadContainer (org.opennms.core.spring.FileReloadContainer)1