Ejemplo n.º 1
0
  /**
   * Constructs a server manager.
   *
   * @param store
   * @param rscManager
   */
  public EntryStore(final IdvObjectStore store, final IdvResourceManager rscManager) {
    notNull(store);
    notNull(rscManager);

    this.idvStore = store;
    this.trie = new PatriciaTrie<>(new CharSequenceKeyAnalyzer());
    this.ADDE_DIRECTORY = getAddeRootDirectory();
    this.ADDE_BIN = ADDE_DIRECTORY + File.separator + "bin";
    this.ADDE_DATA = ADDE_DIRECTORY + File.separator + "data";
    this.localPort = Constants.LOCAL_ADDE_PORT;
    this.restartingMcserv = false;
    this.lastAdded = arrList();
    AnnotationProcessor.process(this);

    McIDASV mcv = McIDASV.getStaticMcv();
    USER_DIRECTORY = mcv.getUserDirectory();
    ADDE_RESOLV = mcv.getUserFile("RESOLV.SRV");
    MCTRACE = "0";

    if (McIDASV.isWindows()) {
      ADDE_MCSERVL = ADDE_BIN + "\\mcservl.exe";
    } else {
      ADDE_MCSERVL = ADDE_BIN + "/mcservl";
    }

    try {
      Set<LocalAddeEntry> locals = EntryTransforms.readResolvFile(ADDE_RESOLV);
      putEntries(trie, locals);
    } catch (IOException e) {
      logger.warn("EntryStore: RESOLV.SRV missing; expected=\"" + ADDE_RESOLV + '"');
    }

    XmlResourceCollection userResource =
        rscManager.getXmlResources(ResourceManager.RSC_NEW_USERSERVERS);
    XmlResourceCollection sysResource =
        rscManager.getXmlResources(IdvResourceManager.RSC_ADDESERVER);

    Set<AddeEntry> systemEntries = extractResourceEntries(EntrySource.SYSTEM, sysResource);

    Set<AddeEntry> prefEntries = extractPreferencesEntries(store);
    prefEntries = removeDeletedSystemEntries(prefEntries, systemEntries);

    Set<AddeEntry> userEntries = extractUserEntries(userResource);
    userEntries = removeDeletedSystemEntries(userEntries, systemEntries);

    putEntries(trie, prefEntries);
    putEntries(trie, userEntries);
    putEntries(trie, systemEntries);
    saveEntries();
  }
Ejemplo n.º 2
0
 /**
  * Attempts to launch the browser pointed at by the {@literal "idv.browser.path"} IDV property, if
  * it has been set.
  *
  * @param url URL to open.
  * @return Either {@code true} if the command-line was executed, {@code false} if either the
  *     command-line wasn't launched or {@literal "idv.browser.path"} was not set.
  */
 private static boolean tryUserSpecifiedBrowser(final String url) {
   McIDASV mcv = McIDASV.getStaticMcv();
   boolean retVal = false;
   if (mcv != null) {
     String browserPath = mcv.getProperty("idv.browser.path", (String) null);
     if ((browserPath != null) && !browserPath.trim().isEmpty()) {
       try {
         Runtime.getRuntime().exec(browserPath + ' ' + url);
         retVal = true;
       } catch (Exception e) {
         LogUtil.logException("Executing browser: " + browserPath, e);
       }
     }
   }
   return retVal;
 }
Ejemplo n.º 3
0
 protected String[] getAddeCommands() {
   String mcvPID = Integer.toString(PosixModule.getpid());
   if (McIDASV.isWindows() || (mcvPID == null) || "0".equals(mcvPID)) {
     return new String[] {ADDE_MCSERVL, "-v", "-p", localPort};
   } else {
     return new String[] {ADDE_MCSERVL, "-v", "-p", localPort, "-i", mcvPID};
   }
 }
Ejemplo n.º 4
0
  /** Stops the local server thread if it is running. */
  public void stopLocalServer() {
    if (checkLocalServer()) {
      // TODO: stopProcess (actually Process.destroy()) hangs on Macs...
      //      doesn't seem to kill the children properly
      if (!McIDASV.isMac()) {
        thread.stopProcess();
      }

      thread.interrupt();
      thread = null;
      EventBus.publish(McservEvent.STOPPED);
      logger.debug("stopped mcservl? checkLocalServer={}", checkLocalServer());
    } else {
      logger.debug("mcservl is not running.");
    }
  }
Ejemplo n.º 5
0
  /**
   * Test to see if the thread can access userpath
   *
   * @return {@code true} if the local server can access userpath, {@code false} otherwise.
   */
  public boolean testLocalServer() {
    StringBuilder err = new StringBuilder();
    String[] cmds = {ADDE_MCSERVL, "-t"};
    String[] env = McIDASV.isWindows() ? getWindowsAddeEnv() : getUnixAddeEnv();

    try {
      Process proc = Runtime.getRuntime().exec(cmds, env);
      int result = proc.waitFor();
      if (result != 0) {
        return false;
      }
    } catch (Exception e) {
      return false;
    }
    return true;
  }