Search in sources :

Example 1 with FileMatch

use of com.sun.jmx.examples.scandir.config.FileMatch in project jdk8u_jdk by JetBrains.

the class ScanDirConfig method addDirectoryScanner.

// see ScanDirConfigMXBean
public DirectoryScannerConfig addDirectoryScanner(String name, String dir, String filePattern, long sizeExceedsMaxBytes, long sinceLastModified) {
    final DirectoryScannerConfig scanner = new DirectoryScannerConfig(name);
    scanner.setRootDirectory(dir);
    if (filePattern != null || sizeExceedsMaxBytes > 0 || sinceLastModified > 0) {
        final FileMatch filter = new FileMatch();
        filter.setFilePattern(filePattern);
        filter.setSizeExceedsMaxBytes(sizeExceedsMaxBytes);
        if (sinceLastModified > 0)
            filter.setLastModifiedBefore(new Date(new Date().getTime() - sinceLastModified));
        scanner.addIncludeFiles(filter);
    }
    synchronized (this) {
        config.putScan(scanner);
        status = MODIFIED;
    }
    LOG.fine("config: " + config);
    sendNotification(NOTIFICATION_MODIFIED);
    return scanner;
}
Also used : DirectoryScannerConfig(com.sun.jmx.examples.scandir.config.DirectoryScannerConfig) FileMatch(com.sun.jmx.examples.scandir.config.FileMatch) Date(java.util.Date)

Example 2 with FileMatch

use of com.sun.jmx.examples.scandir.config.FileMatch in project jdk8u_jdk by JetBrains.

the class ScanDirConfigTest method testAddDirectoryScanner.

/**
     * Test of addDirectoryScanner method, of class
     * com.sun.jmx.examples.scandir.ScanDirConfig.
     */
public void testAddDirectoryScanner() throws IOException {
    System.out.println("addDirectoryScanner");
    System.out.println("save");
    final File file = File.createTempFile("testconf", ".xml");
    final ScanDirConfig instance = new ScanDirConfig(file.getAbsolutePath());
    final ScanManagerConfig bean = new ScanManagerConfig("testSave");
    final DirectoryScannerConfig dir = new DirectoryScannerConfig("tmp");
    dir.setRootDirectory(file.getParent());
    FileMatch filter = new FileMatch();
    filter.setFilePattern(".*");
    dir.setIncludeFiles(new FileMatch[] { filter });
    instance.setConfiguration(bean);
    instance.addDirectoryScanner(dir.getName(), dir.getRootDirectory(), filter.getFilePattern(), filter.getSizeExceedsMaxBytes(), 0);
    instance.save();
    final ScanManagerConfig loaded = new XmlConfigUtils(file.getAbsolutePath()).readFromFile();
    assertNotNull(loaded.getScan(dir.getName()));
    assertEquals(dir, loaded.getScan(dir.getName()));
    assertEquals(instance.getConfiguration(), loaded);
    assertEquals(instance.getConfiguration().getScan(dir.getName()), dir);
}
Also used : ScanManagerConfig(com.sun.jmx.examples.scandir.config.ScanManagerConfig) DirectoryScannerConfig(com.sun.jmx.examples.scandir.config.DirectoryScannerConfig) XmlConfigUtils(com.sun.jmx.examples.scandir.config.XmlConfigUtils) File(java.io.File) FileMatch(com.sun.jmx.examples.scandir.config.FileMatch)

Aggregations

DirectoryScannerConfig (com.sun.jmx.examples.scandir.config.DirectoryScannerConfig)2 FileMatch (com.sun.jmx.examples.scandir.config.FileMatch)2 ScanManagerConfig (com.sun.jmx.examples.scandir.config.ScanManagerConfig)1 XmlConfigUtils (com.sun.jmx.examples.scandir.config.XmlConfigUtils)1 File (java.io.File)1 Date (java.util.Date)1