コード例 #1
0
ファイル: MainServer.java プロジェクト: gagazhn/Minicat
  public void serverRun() {
    try {
      // the socket
      server = new ServerSocket(port);

      // the Console
      Console console = new Console(this);
      console.start();

      // init the ServletContainer
      ServletContainer.init();

      // Threads started here
      System.out.println("Server started!:");
      while (true) {
        Socket socket = server.accept();
        new ServerThread(socket, webConfigureReader, servletContext).start();
      }
    } catch (IOException ex) {
      ex.printStackTrace();
    }
  }
コード例 #2
0
ファイル: ReasonerMain.java プロジェクト: markhibberd/SPINdle
  public static void main(String... args) {
    // read in the file and start reasoning process
    System.out.println(ReasonerUtilities.getAppStartMessage());
    System.out.flush();

    Map<String, String> configs = new Hashtable<String, String>();
    List<String> theoryFiles = new ArrayList<String>();
    List<URL> filenames = null;

    // print application message
    boolean isPrintAppMessage = false;
    try {
      Utilities.extractArguments(args, AppConst.ARGUMENT_PREFIX, configs, theoryFiles);

      if (theoryFiles.size() > 0) {
        filenames = new ArrayList<URL>();
        for (String f : theoryFiles) {
          filenames.addAll(ReasonerUtilities.getFilenames(f));
        }
      }

      isPrintAppMessage = ReasonerUtilities.printAppMessage(configs);
    } catch (Exception e) {
      e.printStackTrace(System.err);
      System.err.flush();
      System.exit(1);
    }

    // reasoning engine start here
    if (configs.containsKey(ConfTag.USE_CONSOLE)) {
      Console console = null;
      try {
        console = new Console(configs);
        console.start((null == filenames || filenames.size() == 0) ? null : filenames);
      } catch (Exception e) {
        e.printStackTrace();
      } finally {
        if (null != console) {
          console.terminate();
          console = null;
        }
      }
    } else if (!isPrintAppMessage) {
      if (null == filenames || filenames.size() == 0) {
        System.out.flush();
        System.out.println("\n" + AppConst.APP_USAGE);
        System.out.flush();
        System.err.flush();
        System.err.println(
            Messages.getSystemMessage(SystemMessage.APPLICATION_NO_THEORY_TO_PROCESS) + "\n");
        System.err.flush();
      } else {
        Conf.initializeApplicationContext(configs);

        long sleepTime = Conf.getReasoningFileSleeptime();

        performanceStatistics = new ArrayList<PerformanceStatistic>();
        memoryMonitor = new MemoryMonitor();
        messageListener = new AbstractReasonerMessageListener(System.out);

        Timer timer = null;
        try {
          timer = new Timer();
          timer.schedule(
              new TimerTask() {
                @Override
                public void run() {
                  memoryMonitor.checkMemoryUsed();
                }
              },
              10,
              Conf.getMemoryMonitorTimeInterval());

          for (int i = 0; i < filenames.size(); i++) {
            URL filename = filenames.get(i);
            try {
              runReasoner(filename);
            } catch (Exception e) {
              e.printStackTrace(System.out);
              System.out.flush();
            } finally {
              System.gc();
            }

            if (i != filenames.size() - 1) {
              try {
                long m =
                    performanceStatistics.get(performanceStatistics.size() - 1).getNoOfRules()
                        / 8000;
                if (m > 1) m = 1;
                Thread.sleep(m * sleepTime);
              } catch (Exception e) {
              }
            }
          }
        } finally {
          if (null != timer) {
            timer.cancel();
            timer = null;
          }

          // print out the performance statistics
          ReasonerUtilities.printPerformanceStatistics(performanceStatistics);
          performanceStatistics = null;
        }
      }
    }
  }