Example #1
0
 public void start(boolean restart) throws IOException {
   ProcessQuery processQuery = new ProcessQuery("soffice.bin", unoUrl.getAcceptString());
   long existingPid = processManager.findPid(processQuery);
   if (!(existingPid == PID_NOT_FOUND || existingPid == PID_UNKNOWN)) {
     throw new IllegalStateException(
         String.format(
             "a process with acceptString '%s' is already running; pid %d",
             unoUrl.getAcceptString(), existingPid));
   }
   if (!restart) {
     prepareInstanceProfileDir();
   }
   List<String> command = new ArrayList<String>();
   File executable = OfficeUtils.getOfficeExecutable(officeHome);
   if (runAsArgs != null) {
     command.addAll(Arrays.asList(runAsArgs));
   }
   command.add(executable.getAbsolutePath());
   command.add("-accept=" + unoUrl.getAcceptString() + ";urp;");
   command.add("-env:UserInstallation=" + OfficeUtils.toUrl(instanceProfileDir));
   command.add("-headless");
   command.add("-nocrashreport");
   command.add("-nodefault");
   command.add("-nofirststartwizard");
   command.add("-nolockcheck");
   command.add("-nologo");
   command.add("-norestore");
   ProcessBuilder processBuilder = new ProcessBuilder(command);
   if (PlatformUtils.isWindows()) {
     addBasisAndUrePaths(processBuilder);
   }
   logger.info(
       String.format(
           "starting process with acceptString '%s' and profileDir '%s'",
           unoUrl, instanceProfileDir));
   process = processBuilder.start();
   pid = processManager.findPid(processQuery);
   if (pid == PID_NOT_FOUND) {
     throw new IllegalStateException(
         String.format(
             "process with acceptString '%s' started but its pid could not be found",
             unoUrl.getAcceptString()));
   }
   logger.info("started process" + (pid != PID_UNKNOWN ? "; pid = " + pid : ""));
 }
  public OfficeManager buildOfficeManager() throws IllegalStateException {
    if (officeHome == null)
      throw new IllegalStateException("officeHome not set and could not be auto-detected");
    else if (!officeHome.isDirectory())
      throw new IllegalStateException(
          "officeHome doesn't exist or is not a directory: " + officeHome);
    else if (!OfficeUtils.getOfficeExecutable(officeHome).isFile())
      throw new IllegalStateException(
          "invalid officeHome: it doesn't contain soffice.bin: " + officeHome);
    if (templateProfileDir != null && !isValidProfileDir(templateProfileDir))
      throw new IllegalStateException(
          "templateProfileDir doesn't appear to contain a user profile: " + templateProfileDir);
    if (!workDir.isDirectory())
      throw new IllegalStateException("workDir doesn't exist or is not a directory: " + workDir);

    if (processManager == null) processManager = findBestProcessManager();

    final int numInstances =
        connectionProtocol == OfficeConnectionProtocol.PIPE ? pipeNames.length : portNumbers.length;
    final UnoUrl[] unoUrls = new UnoUrl[numInstances];
    for (int i = 0; i < numInstances; i++)
      unoUrls[i] =
          connectionProtocol == OfficeConnectionProtocol.PIPE
              ? UnoUrl.pipe(pipeNames[i])
              : UnoUrl.socket(portNumbers[i]);
    return new ProcessPoolOfficeManager(
        officeHome,
        unoUrls,
        runAsArgs,
        templateProfileDir,
        workDir,
        retryTimeout,
        taskQueueTimeout,
        taskExecutionTimeout,
        maxTasksPerProcess,
        processManager,
        manageExternalInstances);
  }
Example #3
0
 private File getInstanceProfileDir(File workDir, UnoUrl unoUrl) {
   String dirName =
       ".jodconverter_" + unoUrl.getAcceptString().replace(',', '_').replace('=', '-');
   return new File(workDir, dirName);
 }