Esempio n. 1
0
  public static void main(String[] args) throws CleverException {
    in = Initiator.getInstance(); // creo un oggetto Initiator
    in.start(); // faccio partire l'initiator

    while (true) {
      try {
        Thread.sleep(1000000);
      } catch (InterruptedException ex) {
        System.exit(1);
      }
    }
  }
 private void run(
     Runnable runnable, int numberOfRequests, final ConcurrentHashMap<String, Boolean> results)
     throws InterruptedException {
   Boolean finalResult = true;
   LOGGER.info("Tests start now!");
   final ArrayList<Thread> threads = new ArrayList<>();
   for (int i = 0; i < numberOfRequests; i++) {
     Thread t = new Thread(runnable, "pipeline" + i);
     threads.add(t);
   }
   for (Thread t : threads) {
     Thread.sleep(1000 * (new Random().nextInt(3) + 1));
     t.setUncaughtExceptionHandler(
         new Thread.UncaughtExceptionHandler() {
           public void uncaughtException(Thread t, Throwable e) {
             LOGGER.error("Exception " + e + " from thread " + t);
             results.put(t.getName(), false);
           }
         });
     t.start();
   }
   for (Thread t : threads) {
     int i = threads.indexOf(t);
     if (i == (numberOfRequests - 1)) {
       //                takeHeapDump(dumpDir, i);
     }
     t.join();
   }
   for (String threadId : results.keySet()) {
     finalResult = results.get(threadId) && finalResult;
   }
   assertThat(finalResult, is(true));
 }
Esempio n. 3
0
  /**
   * Starts Grid instance. Note that if grid is already started, then it will be looked up and
   * returned from this method.
   *
   * @return Started grid.
   */
  private Grid startGrid() {
    Properties props = System.getProperties();

    gridName = props.getProperty(GRIDGAIN_NAME.name());

    if (!props.containsKey(GRIDGAIN_NAME.name()) || G.state(gridName) != GridFactoryState.STARTED) {
      selfStarted = true;

      // Set class loader for the spring.
      ClassLoader curCl = Thread.currentThread().getContextClassLoader();

      // Add no-op logger to remove no-appender warning.
      Appender app = new NullAppender();

      Logger.getRootLogger().addAppender(app);

      try {
        Thread.currentThread().setContextClassLoader(getClass().getClassLoader());

        Grid grid = G.start(cfgPath);

        gridName = grid.name();

        System.setProperty(GRIDGAIN_NAME.name(), grid.name());

        return grid;
      } catch (GridException e) {
        throw new GridRuntimeException("Failed to start grid: " + cfgPath, e);
      } finally {
        Logger.getRootLogger().removeAppender(app);

        Thread.currentThread().setContextClassLoader(curCl);
      }
    }

    return G.grid(gridName);
  }
Esempio n. 4
0
  public static void main(String[] argv) throws InterruptedException {
    // Arguments:
    // 1st = Mode
    // 2nd = Parent Path  -- (Parent path must have children /data  and /output

    System.out.println("+----------------------------------+");
    System.out.println("| Running Athena Pallas Processor  |");
    System.out.println("|             9/12/12              |");
    System.out.println("+----------------------------------+");

    Athena_Server_Obj = new ATHENA_Server_Local();

    BasicConfigurator.configure();
    Logger.getRootLogger().setLevel(Level.WARN);

    // Get and verify parameters
    if (argv.length < 2) {
      System.out.println("Not enough parameters.");
      System.out.println("Expected 2 parameters: 1st is MODE, 2nd is path to working directory.");
      System.out.println("Exiting.");
      System.exit(0);
    }

    String mode = argv[0];
    String parentPath = argv[1];
    File inFilePath = new File(parentPath + "astronautdata/");
    File outFilePath = new File(parentPath + "output/");
    File kbFilePath = new File(parentPath + "kbs/");

    if (mode.equals("")) {
      System.out.println("Parameter 1 is empty.  Should be RUNMODE (e.g. 'HTN'). Exiting");
      System.exit(0);
    }

    if (inFilePath.isDirectory() == false) {
      System.out.println(inFilePath.getName() + " directory is missing. Exiting");
      System.exit(0);
    }

    if (outFilePath.isDirectory() == false) {
      System.out.println(outFilePath.getName() + " directory is missing. Exiting");
      System.exit(0);
    }

    if (kbFilePath.isDirectory() == false) {
      System.out.println(kbFilePath.getName() + " directory is missing. Exiting");
      System.exit(0);
    }

    String kbID = "";
    TStringList IgnoredFileNames = new TStringList();

    // Main Loop
    while (mainLoopRunning) {
      if (Verbose == true) {
        // System.out.println("New Loop");
      }
      fileProcessed = false;
      if (Verbose == true) {
        // System.out.println("Ignoring #" + IgnoredFileNames.Count() + " files.");
      }

      // (re)load if needed
      if (loadKB == true) {
        String[] kbInfo = Athena_Server_Obj.loadKBInfo(mode, parentPath);
        String kbFilenamePath = kbInfo[0];
        kbID = kbInfo[1];

        Athena_Server_Obj.loadKB(kbFilenamePath, kbID);
        loadKB = false;
      }

      File[] listOfFiles = inFilePath.listFiles();
      // for (File child : inFilePath.listFiles()) {
      for (int i = 0; i < listOfFiles.length; i++) {
        File child = listOfFiles[i];
        if (".".equals(child.getName()) || "..".equals(child.getName())) {
          continue;
        }
        if (child.getName().toUpperCase().equals(mode + "-CMD.TXT")) {
          try {
            handleCommands(child.getPath(), outFilePath, mode);
            // fileProcessed = true;
            if (child.delete() == false) {
              System.out.println("Unable to delete: " + child.getPath());
              Thread.sleep(1000);
            }
          } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
          // continue;
        }
        if (IgnoredFileNames.IndexOf(child.getName()) > -1) {
          // if (Verbose == true) {System.out.print("~");}
          continue;
        }
        if (Verbose == true) {
          System.out.println("Considering file: [" + child.getName() + "]");
        }
        String[] namePieces = child.getName().split("_");
        //  (should only open filenames with format of <MODE>_<DFN>.xml)
        if (Verbose == true) {
          System.out.println("File Name Is: " + child.getName());
        }
        String fileExt = GetFileExtension(child.getName());
        if (Verbose == true) {
          System.out.println("File Ext Is: " + fileExt);
        }
        // At times, there seems to be a race condition, where this java process
        //   tries to load in the file before the mump process is done writting
        // So I have modified the mumps process to that it outputs TWO files.
        //  1st the <MODE>_<DFN>.xml file
        //  2nd, after finished with above, it outputs <MODE>_<DFN>_READY.TXT
        // So the 2nd file must exist before opening the <MODE>_<DFN>.xml
        //  The 2nd file need not be opened or processed.  Just the fact that
        //  it exists on in the directory is signal that it is OK to process.
        if (fileExt.equals("xml") == false) {
          if (Verbose == true) {
            System.out.println("Skipping file due to wrong extension.");
          }
          IgnoredFileNames.Add(child.getName());
          continue;
        }
        if (((namePieces.length > 1) && (namePieces[0].equals(mode))) == false) {
          if (Verbose == true) {
            System.out.println("Skipping file due to wrong mode.");
          }
          IgnoredFileNames.Add(child.getName());
          continue;
        }
        Boolean finishFileExists = finishFileExist(child.getPath());
        if (Verbose == true) {
          System.out.println("Ready File Exists?: " + finishFileExists);
        }
        // NOTE: after processing the <MODE>_<DFN>.xml, both files should be deleted
        // NOTE: in java, one can't use '=' to compare strings -- that just compares a pointer to
        // the string.  Must use ".equals()"
        if (finishFileExists == true) {
          System.out.println("Found File to Process: [" + child.getName() + "]");
          fileProcessed = true;
          String patientID = namePieces[1];
          patientID = patientID.split("\\.")[0];
          File outFileName =
              new File(outFilePath.getPath() + "/" + mode + "_" + patientID + ".xml");
          String htmlFile = outFilePath.getPath() + "/" + mode + "_" + patientID + ".html";
          System.out.println("SENDING TO: [" + outFileName.getPath() + "]");
          String readyFileName;
          readyFileName = outFileName.getPath();
          try {
            processFile(patientID, child, outFileName, kbID, htmlFile);
          } catch (Throwable t) {
            try {
              FileWriter fwrite = new FileWriter(outFileName);
              fwrite.write(
                  "-1^CDSS/Clinical Decision Support Engine(Athena) Error. " + t.getMessage());
              fwrite.flush();
              fwrite.close();
            } catch (IOException e3) {
              System.out.println("Could not create error message");
            }
            System.out.println("Error Processing Recommendation: " + t.getMessage());
            // return;
          }
          System.out.println("Ready.TXT File Name Is: " + readyFileName); // Remove
          File readyFile = new File(readyFileName.replace(".xml", "_READY.TXT"));
          try {
            readyFile.createNewFile();
            FileWriter fstream = new FileWriter(readyFile);
            BufferedWriter out = new BufferedWriter(fstream);
            out.write("DONE");
            out.close();
            System.out.println("****SUCCESS****" + readyFile.getPath());
          } catch (java.io.IOException e0) {
            System.out.println("Error creating READY file");
          }
          if (child.delete() == false) {
            System.out.println("Unable to delete: " + child.getName());
            Thread.sleep(1000);
          }
          // Delete completed file
          File f = new File(getFinishFileName(child.getPath()));
          if (f.delete() == false) {
            System.out.println("Unable to delete: " + f.getName());
            Thread.sleep(1000);
          }
        }
      }
      if (fileProcessed == false) {
        Thread.sleep(1000);
        if (Verbose == true) {
          System.out.print(".");
        }
      } else {
        if (Verbose == true) {
          System.out.println("Found process, so won't sleep...");
        }
      }
      mainLoopRunning = false;
    } // for loop
    System.out.println("Finished with run.");
    System.exit(0);
  } // Main routine