Example #1
0
 private boolean register(File f) {
   boolean rc = false;
   if (f.isDirectory()) {
     File file[] = f.listFiles(this);
     for (int i = 0; i < file.length; i++) {
       if (register(file[i])) rc = true;
     }
   } else if (dirMap.get(f) == null) {
     dirMap.put(f, new QEntry());
     rc = true;
   }
   return rc;
 }
Example #2
0
 private void deploy() {
   List startList = new ArrayList();
   Iterator iter = dirMap.entrySet().iterator();
   try {
     while (iter.hasNext() && !shutdown) {
       Map.Entry entry = (Map.Entry) iter.next();
       File f = (File) entry.getKey();
       QEntry qentry = (QEntry) entry.getValue();
       long deployed = qentry.getDeployed();
       if (deployed == 0) {
         if (deploy(f)) {
           if (qentry.isQBean()) startList.add(qentry.getInstance());
           qentry.setDeployed(f.lastModified());
         } else {
           // deploy failed, clean up.
           iter.remove();
         }
       } else if (deployed != f.lastModified()) {
         undeploy(f);
         iter.remove();
         loader.forceNewClassLoaderOnNextScan();
       }
     }
     iter = startList.iterator();
     while (iter.hasNext()) {
       start((ObjectInstance) iter.next());
     }
   } catch (Exception e) {
     log.error("deploy", e);
   }
 }
Example #3
0
  private void undeploy() {
    Object[] set = dirMap.entrySet().toArray();
    int l = set.length;

    while (l-- > 0) {
      Map.Entry entry = (Map.Entry) set[l];
      File f = (File) entry.getKey();
      undeploy(f);
    }
  }
Example #4
0
  private void undeploy(File f) {
    QEntry qentry = (QEntry) dirMap.get(f);
    try {
      if (log != null) log.trace("undeploying:" + f.getCanonicalPath());

      Object obj = qentry.getObject();
      ObjectName name = qentry.getObjectName();
      factory.destroyQBean(this, name, obj);
      if (log != null) log.info("undeployed:" + f.getCanonicalPath());
    } catch (Exception e) {
      getLog().warn("undeploy", e);
    }
  }
Example #5
0
  private boolean deploy(File f) {
    try {
      if (log != null) log.info("deploy:" + f.getCanonicalPath());
      QEntry qentry = (QEntry) dirMap.get(f);
      SAXBuilder builder = createSAXBuilder();
      Document doc;
      if (decorator != null && !f.getName().equals(LOGGER_CONFIG)) {
        doc = decrypt(builder.build(new StringReader(decorator.decorateFile(f))));
      } else {
        doc = decrypt(builder.build(f));
      }

      Element rootElement = doc.getRootElement();
      String iuuid = rootElement.getAttributeValue("instance");
      if (iuuid != null) {
        UUID uuid = UUID.fromString(iuuid);
        if (!uuid.equals(getInstanceId())) {
          deleteFile(f, iuuid);
          return false;
        }
      }
      Object obj = factory.instantiate(this, rootElement);
      qentry.setObject(obj);

      ObjectInstance instance = factory.createQBean(this, doc.getRootElement(), obj);
      qentry.setInstance(instance);
    } catch (InstanceAlreadyExistsException e) {
      /*
       * Ok, the file we tried to deploy, holds an object
       *  that already has been deployed.
       *
       * Rename it out of the way.
       *
       */
      tidyFileAway(f, DUPLICATE_EXTENSION);
      getLog().warn("deploy", e);
      return false;
    } catch (Exception e) {
      getLog().warn("deploy", e);
      tidyFileAway(f, ERROR_EXTENSION);
      // This will also save deploy error repeats...
      return false;
    } catch (Error e) {
      getLog().warn("deploy", e);
      tidyFileAway(f, ENV_EXTENSION);
      // This will also save deploy error repeats...
      return false;
    }
    return true;
  }
Example #6
0
 private void checkModified() {
   Iterator iter = dirMap.entrySet().iterator();
   while (iter.hasNext()) {
     Map.Entry entry = (Map.Entry) iter.next();
     File f = (File) entry.getKey();
     QEntry qentry = (QEntry) entry.getValue();
     if (qentry.isQBean() && qentry.isQPersist()) {
       ObjectName name = qentry.getObjectName();
       if (getState(name) == QBean.STARTED && isModified(name)) {
         qentry.setDeployed(persist(f, name));
       }
     }
   }
 }