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;
}
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);
}
Aggregations