com.sun.jmx.examples.scandir.config.XmlConfigUtils Java Examples

The following examples show how to use com.sun.jmx.examples.scandir.config.XmlConfigUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ScanDirConfigTest.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Test of load method, of class com.sun.jmx.examples.scandir.ScanDirConfig.
 */
public void testLoad() throws Exception {
    System.out.println("load");

    final File file = File.createTempFile("testconf",".xml");
    final ScanDirConfig instance = new ScanDirConfig(file.getAbsolutePath());
    final ScanManagerConfig bean =
            new  ScanManagerConfig("testLoad");
    final DirectoryScannerConfig dir =
            new DirectoryScannerConfig("tmp");
    dir.setRootDirectory(file.getParent());
    bean.putScan(dir);
    XmlConfigUtils.write(bean,new FileOutputStream(file),false);
    instance.load();

    assertEquals(bean,instance.getConfiguration());
    bean.removeScan(dir.getName());
    XmlConfigUtils.write(bean,new FileOutputStream(file),false);

    assertNotSame(bean,instance.getConfiguration());

    instance.load();

    assertEquals(bean,instance.getConfiguration());

}
 
Example #2
Source File: ScanDirConfig.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
static String guessConfigName(String configFileName,String defaultFile) {
    try {
        if (configFileName == null) return DEFAULT;
        final File f = new File(configFileName);
        if (f.canRead()) {
            final String confname = XmlConfigUtils.read(f).getName();
            if (confname != null && confname.length()>0) return confname;
        }
        final File f2 = new File(defaultFile);
        if (f.equals(f2)) return DEFAULT;
        final String guess = getBasename(f.getName());
        if (guess == null) return DEFAULT;
        if (guess.length()==0) return DEFAULT;
        return guess;
    } catch (Exception x) {
        return DEFAULT;
    }
}
 
Example #3
Source File: ScanDirConfigTest.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Test of getXmlConfigString method, of class com.sun.jmx.examples.scandir.ScanDirConfig.
 */
public void testGetXmlConfigString() throws Exception {
    System.out.println("getXmlConfigString");

    try {
        final File file = File.createTempFile("testconf",".xml");
        final ScanDirConfig instance = new ScanDirConfig(file.getAbsolutePath());
        final ScanManagerConfig bean =
            new  ScanManagerConfig("testGetXmlConfigString");
        final DirectoryScannerConfig dir =
            new DirectoryScannerConfig("tmp");
        dir.setRootDirectory(file.getParent());
        bean.putScan(dir);
        instance.setConfiguration(bean);
        System.out.println("Expected: " + XmlConfigUtils.toString(bean));
        System.out.println("Received: " +
                instance.getConfiguration().toString());
        assertEquals(XmlConfigUtils.toString(bean),
            instance.getConfiguration().toString());
    } catch (Exception x) {
        x.printStackTrace();
        throw x;
    }
}
 
Example #4
Source File: ScanDirConfigTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Test of load method, of class com.sun.jmx.examples.scandir.ScanDirConfig.
 */
public void testLoad() throws Exception {
    System.out.println("load");

    final File file = File.createTempFile("testconf",".xml");
    final ScanDirConfig instance = new ScanDirConfig(file.getAbsolutePath());
    final ScanManagerConfig bean =
            new  ScanManagerConfig("testLoad");
    final DirectoryScannerConfig dir =
            new DirectoryScannerConfig("tmp");
    dir.setRootDirectory(file.getParent());
    bean.putScan(dir);
    XmlConfigUtils.write(bean,new FileOutputStream(file),false);
    instance.load();

    assertEquals(bean,instance.getConfiguration());
    bean.removeScan(dir.getName());
    XmlConfigUtils.write(bean,new FileOutputStream(file),false);

    assertNotSame(bean,instance.getConfiguration());

    instance.load();

    assertEquals(bean,instance.getConfiguration());

}
 
Example #5
Source File: ScanDirConfigTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Test of getXmlConfigString method, of class com.sun.jmx.examples.scandir.ScanDirConfig.
 */
public void testGetXmlConfigString() throws Exception {
    System.out.println("getXmlConfigString");

    try {
        final File file = File.createTempFile("testconf",".xml");
        final ScanDirConfig instance = new ScanDirConfig(file.getAbsolutePath());
        final ScanManagerConfig bean =
            new  ScanManagerConfig("testGetXmlConfigString");
        final DirectoryScannerConfig dir =
            new DirectoryScannerConfig("tmp");
        dir.setRootDirectory(file.getParent());
        bean.putScan(dir);
        instance.setConfiguration(bean);
        System.out.println("Expected: " + XmlConfigUtils.toString(bean));
        System.out.println("Received: " +
                instance.getConfiguration().toString());
        assertEquals(XmlConfigUtils.toString(bean),
            instance.getConfiguration().toString());
    } catch (Exception x) {
        x.printStackTrace();
        throw x;
    }
}
 
Example #6
Source File: ScanDirConfig.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
static String guessConfigName(String configFileName,String defaultFile) {
    try {
        if (configFileName == null) return DEFAULT;
        final File f = new File(configFileName);
        if (f.canRead()) {
            final String confname = XmlConfigUtils.read(f).getName();
            if (confname != null && confname.length()>0) return confname;
        }
        final File f2 = new File(defaultFile);
        if (f.equals(f2)) return DEFAULT;
        final String guess = getBasename(f.getName());
        if (guess == null) return DEFAULT;
        if (guess.length()==0) return DEFAULT;
        return guess;
    } catch (Exception x) {
        return DEFAULT;
    }
}
 
Example #7
Source File: ScanDirConfigTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Test of getXmlConfigString method, of class com.sun.jmx.examples.scandir.ScanDirConfig.
 */
public void testGetXmlConfigString() throws Exception {
    System.out.println("getXmlConfigString");

    try {
        final File file = File.createTempFile("testconf",".xml");
        final ScanDirConfig instance = new ScanDirConfig(file.getAbsolutePath());
        final ScanManagerConfig bean =
            new  ScanManagerConfig("testGetXmlConfigString");
        final DirectoryScannerConfig dir =
            new DirectoryScannerConfig("tmp");
        dir.setRootDirectory(file.getParent());
        bean.putScan(dir);
        instance.setConfiguration(bean);
        System.out.println("Expected: " + XmlConfigUtils.toString(bean));
        System.out.println("Received: " +
                instance.getConfiguration().toString());
        assertEquals(XmlConfigUtils.toString(bean),
            instance.getConfiguration().toString());
    } catch (Exception x) {
        x.printStackTrace();
        throw x;
    }
}
 
Example #8
Source File: ScanDirConfig.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
static String guessConfigName(String configFileName,String defaultFile) {
    try {
        if (configFileName == null) return DEFAULT;
        final File f = new File(configFileName);
        if (f.canRead()) {
            final String confname = XmlConfigUtils.read(f).getName();
            if (confname != null && confname.length()>0) return confname;
        }
        final File f2 = new File(defaultFile);
        if (f.equals(f2)) return DEFAULT;
        final String guess = getBasename(f.getName());
        if (guess == null) return DEFAULT;
        if (guess.length()==0) return DEFAULT;
        return guess;
    } catch (Exception x) {
        return DEFAULT;
    }
}
 
Example #9
Source File: ScanDirConfigTest.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Test of load method, of class com.sun.jmx.examples.scandir.ScanDirConfig.
 */
public void testLoad() throws Exception {
    System.out.println("load");

    final File file = File.createTempFile("testconf",".xml");
    final ScanDirConfig instance = new ScanDirConfig(file.getAbsolutePath());
    final ScanManagerConfig bean =
            new  ScanManagerConfig("testLoad");
    final DirectoryScannerConfig dir =
            new DirectoryScannerConfig("tmp");
    dir.setRootDirectory(file.getParent());
    bean.putScan(dir);
    XmlConfigUtils.write(bean,new FileOutputStream(file),false);
    instance.load();

    assertEquals(bean,instance.getConfiguration());
    bean.removeScan(dir.getName());
    XmlConfigUtils.write(bean,new FileOutputStream(file),false);

    assertNotSame(bean,instance.getConfiguration());

    instance.load();

    assertEquals(bean,instance.getConfiguration());

}
 
Example #10
Source File: ScanDirConfig.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
static String guessConfigName(String configFileName,String defaultFile) {
    try {
        if (configFileName == null) return DEFAULT;
        final File f = new File(configFileName);
        if (f.canRead()) {
            final String confname = XmlConfigUtils.read(f).getName();
            if (confname != null && confname.length()>0) return confname;
        }
        final File f2 = new File(defaultFile);
        if (f.equals(f2)) return DEFAULT;
        final String guess = getBasename(f.getName());
        if (guess == null) return DEFAULT;
        if (guess.length()==0) return DEFAULT;
        return guess;
    } catch (Exception x) {
        return DEFAULT;
    }
}
 
Example #11
Source File: ScanDirConfigTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Test of getXmlConfigString method, of class com.sun.jmx.examples.scandir.ScanDirConfig.
 */
public void testGetXmlConfigString() throws Exception {
    System.out.println("getXmlConfigString");

    try {
        final File file = File.createTempFile("testconf",".xml");
        final ScanDirConfig instance = new ScanDirConfig(file.getAbsolutePath());
        final ScanManagerConfig bean =
            new  ScanManagerConfig("testGetXmlConfigString");
        final DirectoryScannerConfig dir =
            new DirectoryScannerConfig("tmp");
        dir.setRootDirectory(file.getParent());
        bean.putScan(dir);
        instance.setConfiguration(bean);
        System.out.println("Expected: " + XmlConfigUtils.toString(bean));
        System.out.println("Received: " +
                instance.getConfiguration().toString());
        assertEquals(XmlConfigUtils.toString(bean),
            instance.getConfiguration().toString());
    } catch (Exception x) {
        x.printStackTrace();
        throw x;
    }
}
 
Example #12
Source File: ScanDirConfig.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
static String guessConfigName(String configFileName,String defaultFile) {
    try {
        if (configFileName == null) return DEFAULT;
        final File f = new File(configFileName);
        if (f.canRead()) {
            final String confname = XmlConfigUtils.read(f).getName();
            if (confname != null && confname.length()>0) return confname;
        }
        final File f2 = new File(defaultFile);
        if (f.equals(f2)) return DEFAULT;
        final String guess = getBasename(f.getName());
        if (guess == null) return DEFAULT;
        if (guess.length()==0) return DEFAULT;
        return guess;
    } catch (Exception x) {
        return DEFAULT;
    }
}
 
Example #13
Source File: ScanDirConfigTest.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Test of getXmlConfigString method, of class com.sun.jmx.examples.scandir.ScanDirConfig.
 */
public void testGetXmlConfigString() throws Exception {
    System.out.println("getXmlConfigString");

    try {
        final File file = File.createTempFile("testconf",".xml");
        final ScanDirConfig instance = new ScanDirConfig(file.getAbsolutePath());
        final ScanManagerConfig bean =
            new  ScanManagerConfig("testGetXmlConfigString");
        final DirectoryScannerConfig dir =
            new DirectoryScannerConfig("tmp");
        dir.setRootDirectory(file.getParent());
        bean.putScan(dir);
        instance.setConfiguration(bean);
        System.out.println("Expected: " + XmlConfigUtils.toString(bean));
        System.out.println("Received: " +
                instance.getConfiguration().toString());
        assertEquals(XmlConfigUtils.toString(bean),
            instance.getConfiguration().toString());
    } catch (Exception x) {
        x.printStackTrace();
        throw x;
    }
}
 
Example #14
Source File: ScanDirConfig.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
static String guessConfigName(String configFileName,String defaultFile) {
    try {
        if (configFileName == null) return DEFAULT;
        final File f = new File(configFileName);
        if (f.canRead()) {
            final String confname = XmlConfigUtils.read(f).getName();
            if (confname != null && confname.length()>0) return confname;
        }
        final File f2 = new File(defaultFile);
        if (f.equals(f2)) return DEFAULT;
        final String guess = getBasename(f.getName());
        if (guess == null) return DEFAULT;
        if (guess.length()==0) return DEFAULT;
        return guess;
    } catch (Exception x) {
        return DEFAULT;
    }
}
 
Example #15
Source File: ScanDirConfig.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
static String guessConfigName(String configFileName,String defaultFile) {
    try {
        if (configFileName == null) return DEFAULT;
        final File f = new File(configFileName);
        if (f.canRead()) {
            final String confname = XmlConfigUtils.read(f).getName();
            if (confname != null && confname.length()>0) return confname;
        }
        final File f2 = new File(defaultFile);
        if (f.equals(f2)) return DEFAULT;
        final String guess = getBasename(f.getName());
        if (guess == null) return DEFAULT;
        if (guess.length()==0) return DEFAULT;
        return guess;
    } catch (Exception x) {
        return DEFAULT;
    }
}
 
Example #16
Source File: ScanDirConfigTest.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Test of load method, of class com.sun.jmx.examples.scandir.ScanDirConfig.
 */
public void testLoad() throws Exception {
    System.out.println("load");

    final File file = File.createTempFile("testconf",".xml");
    final ScanDirConfig instance = new ScanDirConfig(file.getAbsolutePath());
    final ScanManagerConfig bean =
            new  ScanManagerConfig("testLoad");
    final DirectoryScannerConfig dir =
            new DirectoryScannerConfig("tmp");
    dir.setRootDirectory(file.getParent());
    bean.putScan(dir);
    XmlConfigUtils.write(bean,new FileOutputStream(file),false);
    instance.load();

    assertEquals(bean,instance.getConfiguration());
    bean.removeScan(dir.getName());
    XmlConfigUtils.write(bean,new FileOutputStream(file),false);

    assertNotSame(bean,instance.getConfiguration());

    instance.load();

    assertEquals(bean,instance.getConfiguration());

}
 
Example #17
Source File: ScanDirConfig.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
static String guessConfigName(String configFileName,String defaultFile) {
    try {
        if (configFileName == null) return DEFAULT;
        final File f = new File(configFileName);
        if (f.canRead()) {
            final String confname = XmlConfigUtils.read(f).getName();
            if (confname != null && confname.length()>0) return confname;
        }
        final File f2 = new File(defaultFile);
        if (f.equals(f2)) return DEFAULT;
        final String guess = getBasename(f.getName());
        if (guess == null) return DEFAULT;
        if (guess.length()==0) return DEFAULT;
        return guess;
    } catch (Exception x) {
        return DEFAULT;
    }
}
 
Example #18
Source File: ScanDirConfigTest.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Test of getXmlConfigString method, of class com.sun.jmx.examples.scandir.ScanDirConfig.
 */
public void testGetXmlConfigString() throws Exception {
    System.out.println("getXmlConfigString");

    try {
        final File file = File.createTempFile("testconf",".xml");
        final ScanDirConfig instance = new ScanDirConfig(file.getAbsolutePath());
        final ScanManagerConfig bean =
            new  ScanManagerConfig("testGetXmlConfigString");
        final DirectoryScannerConfig dir =
            new DirectoryScannerConfig("tmp");
        dir.setRootDirectory(file.getParent());
        bean.putScan(dir);
        instance.setConfiguration(bean);
        System.out.println("Expected: " + XmlConfigUtils.toString(bean));
        System.out.println("Received: " +
                instance.getConfiguration().toString());
        assertEquals(XmlConfigUtils.toString(bean),
            instance.getConfiguration().toString());
    } catch (Exception x) {
        x.printStackTrace();
        throw x;
    }
}
 
Example #19
Source File: ScanDirConfig.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
static String guessConfigName(String configFileName,String defaultFile) {
    try {
        if (configFileName == null) return DEFAULT;
        final File f = new File(configFileName);
        if (f.canRead()) {
            final String confname = XmlConfigUtils.read(f).getName();
            if (confname != null && confname.length()>0) return confname;
        }
        final File f2 = new File(defaultFile);
        if (f.equals(f2)) return DEFAULT;
        final String guess = getBasename(f.getName());
        if (guess == null) return DEFAULT;
        if (guess.length()==0) return DEFAULT;
        return guess;
    } catch (Exception x) {
        return DEFAULT;
    }
}
 
Example #20
Source File: ScanDirConfigTest.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Test of load method, of class com.sun.jmx.examples.scandir.ScanDirConfig.
 */
public void testLoad() throws Exception {
    System.out.println("load");

    final File file = File.createTempFile("testconf",".xml");
    final ScanDirConfig instance = new ScanDirConfig(file.getAbsolutePath());
    final ScanManagerConfig bean =
            new  ScanManagerConfig("testLoad");
    final DirectoryScannerConfig dir =
            new DirectoryScannerConfig("tmp");
    dir.setRootDirectory(file.getParent());
    bean.putScan(dir);
    XmlConfigUtils.write(bean,new FileOutputStream(file),false);
    instance.load();

    assertEquals(bean,instance.getConfiguration());
    bean.removeScan(dir.getName());
    XmlConfigUtils.write(bean,new FileOutputStream(file),false);

    assertNotSame(bean,instance.getConfiguration());

    instance.load();

    assertEquals(bean,instance.getConfiguration());

}
 
Example #21
Source File: ResultLogManager.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private void logToFile(ResultRecord record) throws IOException {
    final String basename;
    final long   maxRecords;
    synchronized (this) {
        if (logFile == null) return;
        basename = getLogFileName(false);
        maxRecords = fileCapacity;
    }

    // Get the stream into which we should log.
    final OutputStream stream =
            checkLogFile(basename,maxRecords,false);

    // logging to file now disabled - too bad.
    if (stream == null) return;

    synchronized (this) {
        try {
            XmlConfigUtils.write(record,stream,true);
            stream.flush();
            // don't increment logCount if we were not logging in logStream.
            if (stream == logStream) logCount++;
        } catch (JAXBException x) {
            final IllegalArgumentException iae =
                    new IllegalArgumentException("bad record",x);
            LOG.finest("Failed to log record: "+x);
            throw iae;
        }
    }
}
 
Example #22
Source File: ScanDirConfigTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #23
Source File: ScanDirConfig.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void load() throws IOException {
    if (filename == null)
        throw new UnsupportedOperationException("load");

    synchronized(this) {
        config = new XmlConfigUtils(filename).readFromFile();
        if (configname != null) config = config.copy(configname);
        else configname = config.getName();

        status=LOADED;
    }
    sendNotification(NOTIFICATION_LOADED);
}
 
Example #24
Source File: DirectoryScanner.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a new {@code DirectoryScanner}.
 * <p>This constructor is
 * package protected, and this MBean cannot be created by a remote
 * client, because it needs a reference to the {@link ResultLogManager},
 * which cannot be provided from remote.
 * </p>
 * <p>This is a conscious design choice: {@code DirectoryScanner} MBeans
 * are expected to be completely managed (created, registered, unregistered)
 * by the {@link ScanManager} which does provide this reference.
 * </p>
 *
 * @param config This {@code DirectoryScanner} configuration.
 * @param logManager The info log manager with which to log the info
 *        records.
 * @throws IllegalArgumentException if one of the parameter is null, or if
 *         the provided {@code config} doesn't have its {@code name} set,
 *         or if the {@link DirectoryScannerConfig#getRootDirectory
 *         root directory} provided in the {@code config} is not acceptable
 *         (not provided or not found or not readable, etc...).
 **/
public DirectoryScanner(DirectoryScannerConfig config,
                        ResultLogManager logManager)
    throws IllegalArgumentException {
    if (logManager == null)
        throw new IllegalArgumentException("log=null");
    if (config == null)
        throw new IllegalArgumentException("config=null");
    if (config.getName() == null)
        throw new IllegalArgumentException("config.name=null");

     broadcaster = new NotificationBroadcasterSupport();

     // Clone the config: ensure data encapsulation.
     //
     this.config = XmlConfigUtils.xmlClone(config);

     // Checks that the provided root directory is valid.
     // Throws IllegalArgumentException if it isn't.
     //
     rootFile = validateRoot(config.getRootDirectory());

     // Initialize the Set<Action> for which this DirectoryScanner
     // is configured.
     //
     if (config.getActions() == null)
         actions = Collections.emptySet();
     else
         actions = EnumSet.copyOf(Arrays.asList(config.getActions()));
     this.logManager = logManager;
}
 
Example #25
Source File: ScanDirConfigTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Test of save method, of class com.sun.jmx.examples.scandir.ScanDirConfig.
 */
public void testSave() throws Exception {
    System.out.println("save");

    final File file = File.createTempFile("testconf",".xml");
    final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    final ScanManagerMXBean manager = ScanManager.register(mbs);

    try {
        final ScanDirConfigMXBean instance =
                manager.createOtherConfigurationMBean("testSave",file.getAbsolutePath());
        assertTrue(mbs.isRegistered(
                ScanManager.makeScanDirConfigName("testSave")));
        final ScanManagerConfig bean =
            new  ScanManagerConfig("testSave");
        final DirectoryScannerConfig dir =
            new DirectoryScannerConfig("tmp");
        dir.setRootDirectory(file.getParent());
        bean.putScan(dir);
        instance.setConfiguration(bean);
        instance.save();
        final ScanManagerConfig loaded =
            new XmlConfigUtils(file.getAbsolutePath()).readFromFile();
        assertEquals(instance.getConfiguration(),loaded);
        assertEquals(bean,loaded);

        instance.getConfiguration().removeScan("tmp");
        instance.save();
        assertNotSame(loaded,instance.getConfiguration());
        final ScanManagerConfig loaded2 =
            new XmlConfigUtils(file.getAbsolutePath()).readFromFile();
        assertEquals(instance.getConfiguration(),loaded2);
    } finally {
        manager.close();
        mbs.unregisterMBean(ScanManager.SCAN_MANAGER_NAME);
    }
    final ObjectName all =
            new ObjectName(ScanManager.SCAN_MANAGER_NAME.getDomain()+":*");
    assertEquals(0,mbs.queryNames(all,null).size());
}
 
Example #26
Source File: ResultLogManager.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private void logToFile(ResultRecord record) throws IOException {
    final String basename;
    final long   maxRecords;
    synchronized (this) {
        if (logFile == null) return;
        basename = getLogFileName(false);
        maxRecords = fileCapacity;
    }

    // Get the stream into which we should log.
    final OutputStream stream =
            checkLogFile(basename,maxRecords,false);

    // logging to file now disabled - too bad.
    if (stream == null) return;

    synchronized (this) {
        try {
            XmlConfigUtils.write(record,stream,true);
            stream.flush();
            // don't increment logCount if we were not logging in logStream.
            if (stream == logStream) logCount++;
        } catch (JAXBException x) {
            final IllegalArgumentException iae =
                    new IllegalArgumentException("bad record",x);
            LOG.finest("Failed to log record: "+x);
            throw iae;
        }
    }
}
 
Example #27
Source File: DirectoryScanner.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a new {@code DirectoryScanner}.
 * <p>This constructor is
 * package protected, and this MBean cannot be created by a remote
 * client, because it needs a reference to the {@link ResultLogManager},
 * which cannot be provided from remote.
 * </p>
 * <p>This is a conscious design choice: {@code DirectoryScanner} MBeans
 * are expected to be completely managed (created, registered, unregistered)
 * by the {@link ScanManager} which does provide this reference.
 * </p>
 *
 * @param config This {@code DirectoryScanner} configuration.
 * @param logManager The info log manager with which to log the info
 *        records.
 * @throws IllegalArgumentException if one of the parameter is null, or if
 *         the provided {@code config} doesn't have its {@code name} set,
 *         or if the {@link DirectoryScannerConfig#getRootDirectory
 *         root directory} provided in the {@code config} is not acceptable
 *         (not provided or not found or not readable, etc...).
 **/
public DirectoryScanner(DirectoryScannerConfig config,
                        ResultLogManager logManager)
    throws IllegalArgumentException {
    if (logManager == null)
        throw new IllegalArgumentException("log=null");
    if (config == null)
        throw new IllegalArgumentException("config=null");
    if (config.getName() == null)
        throw new IllegalArgumentException("config.name=null");

     broadcaster = new NotificationBroadcasterSupport();

     // Clone the config: ensure data encapsulation.
     //
     this.config = XmlConfigUtils.xmlClone(config);

     // Checks that the provided root directory is valid.
     // Throws IllegalArgumentException if it isn't.
     //
     rootFile = validateRoot(config.getRootDirectory());

     // Initialize the Set<Action> for which this DirectoryScanner
     // is configured.
     //
     if (config.getActions() == null)
         actions = Collections.emptySet();
     else
         actions = EnumSet.copyOf(Arrays.asList(config.getActions()));
     this.logManager = logManager;
}
 
Example #28
Source File: ScanDirConfig.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public void save() throws IOException {
    if (filename == null)
        throw new UnsupportedOperationException("load");
    synchronized (this) {
        new XmlConfigUtils(filename).writeToFile(config);
        status = SAVED;
    }
    sendNotification(NOTIFICATION_SAVED);
}
 
Example #29
Source File: ScanDirConfig.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public void load() throws IOException {
    if (filename == null)
        throw new UnsupportedOperationException("load");

    synchronized(this) {
        config = new XmlConfigUtils(filename).readFromFile();
        if (configname != null) config = config.copy(configname);
        else configname = config.getName();

        status=LOADED;
    }
    sendNotification(NOTIFICATION_LOADED);
}
 
Example #30
Source File: ScanDirConfigTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
}