Exemple #1
0
  // see ScanDirConfigMXBean
  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);
  }
Exemple #2
0
  // see ScanDirConfigMXBean
  public void setConfiguration(ScanManagerConfig config) {
    synchronized (this) {
      if (config == null) {
        this.config = null;
        return;
      }

      if (configname == null) configname = config.getName();

      this.config = config.copy(configname);
      status = MODIFIED;
    }
    sendNotification(NOTIFICATION_MODIFIED);
  }
Exemple #3
0
 /**
  * Allows the MBean to perform any operations it needs before being registered in the MBean
  * server. If the name of the MBean is not specified, the MBean can provide a name for its
  * registration. If any exception is raised, the MBean will not be registered in the MBean server.
  *
  * @param server The MBean server in which the MBean will be registered.
  * @param name The object name of the MBean. This name is null if the name parameter to one of the
  *     createMBean or registerMBean methods in the MBeanServer interface is null. In that case,
  *     this method will try to guess its MBean name by examining its configuration data. If its
  *     configuration data is null (nothing was provided in the constructor) or doesn't contain a
  *     name, this method returns {@code null}, and registration will fail.
  *     <p>Otherwise, if {@code name} wasn't {@code null} or if a default name could be
  *     constructed, the name of the configuration will be set to the value of the ObjectName's
  *     {@code name=} key, and the configuration data will always be renamed to reflect this
  *     change.
  * @return The name under which the MBean is to be registered.
  * @throws Exception This exception will be caught by the MBean server and re-thrown as an
  *     MBeanRegistrationException.
  */
 public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception {
   if (name == null) {
     if (config == null) return null;
     if (config.getName() == null) return null;
     name = ScanManager.makeMBeanName(ScanDirConfigMXBean.class, config.getName());
   }
   objectName = name;
   mbeanServer = server;
   synchronized (this) {
     configname = name.getKeyProperty("name");
     if (config == null) config = new ScanManagerConfig(configname);
     else config = config.copy(configname);
   }
   return name;
 }
Exemple #4
0
 // see ScanDirConfigMXBean
 public DirectoryScannerConfig removeDirectoryScanner(String name)
     throws IOException, InstanceNotFoundException {
   final DirectoryScannerConfig scanner;
   synchronized (this) {
     scanner = config.removeScan(name);
     if (scanner == null) throw new IllegalArgumentException(name + ": scanner not found");
     status = MODIFIED;
   }
   sendNotification(NOTIFICATION_MODIFIED);
   return scanner;
 }
Exemple #5
0
 // 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;
 }