示例#1
0
  static {
    threadPools.put(
        Stage.TRANSCODER,
        new ThreadPoolExecutor(
            3,
            3,
            5 * 60,
            TimeUnit.SECONDS,
            new LinkedBlockingQueue<Runnable>(),
            new ThreadFactory() {
              public Thread newThread(Runnable r) {
                return ThreadPools.newThread(
                    r, "TranscoderThread-" + Stage.TRANSCODER + "-" + (transSeq++));
              }
            }));
    threadPools.put(
        Stage.RECOGNIZER,
        new ThreadPoolExecutor(
            3,
            3,
            5 * 60,
            TimeUnit.SECONDS,
            new LinkedBlockingQueue<Runnable>(),
            new ThreadFactory() {
              public Thread newThread(Runnable r) {
                return ThreadPools.newThread(
                    r, "TranscoderThread-" + Stage.RECOGNIZER + "-" + (transSeq++));
              }
            }));

    // register them too
    ThreadPools.getThreadPools()
        .put(Executors.class.getName() + "." + Stage.TRANSCODER, threadPools.get(Stage.TRANSCODER));
    ThreadPools.getThreadPools()
        .put(Executors.class.getName() + "." + Stage.RECOGNIZER, threadPools.get(Stage.RECOGNIZER));

    // fill the rest of the map too, so we don't have to think about it any more later on.
    for (Stage s : Stage.values()) {
      if (!threadPools.containsKey(s)) {
        threadPools.put(s, ThreadPools.jobsExecutor);
      }
    }
    // default configuration, 5 + 1 executors.
    for (int i = 0; i < 5; i++) {
      executorsMap.put(new CommandExecutor.Method(), Stage.TRANSCODER);
    }
    executorsMap.put(new CommandExecutor.Method(), Stage.RECOGNIZER);
    readConfiguration();
  }
 @Override
 protected List<List<String>> loadRecipes() {
   final String filename = parametersFile();
   @SuppressWarnings("unchecked")
   List<List<String>> recipes =
       (List<List<String>>) Resources.getResource("PARSED_RECIPE: " + filename);
   if (recipes == null) {
     final StringBuffer str =
         new CMFile(Resources.buildResourcePath("skills") + filename, null, CMFile.FLAG_LOGERRORS)
             .text();
     recipes = loadList(str);
     if (recipes.size() == 0) Log.errOut("LeatherWorking", "Recipes not found!");
     else {
       final List<List<String>> newRecipes = new Vector<List<String>>();
       for (int r = 0; r < recipes.size(); r++) {
         final List<String> V = recipes.get(r);
         if (V.size() > 0) {
           final String name = V.get(RCP_FINALNAME);
           final int baseLevel = CMath.s_int(V.get(RCP_LEVEL)) + 2;
           for (final Stage s : Stage.values()) {
             final List<String> V1 = new XVector<String>(V);
             V1.set(RCP_FINALNAME, s.name() + " " + name);
             final int level = baseLevel + s.recipeLevel;
             V1.set(RCP_LEVEL, "" + level);
             for (int i = 0; i <= newRecipes.size(); i++) {
               if (newRecipes.size() == i) {
                 newRecipes.add(V1);
                 break;
               } else if (CMath.s_int(newRecipes.get(i).get(RCP_LEVEL)) > level) {
                 newRecipes.add(i, V1);
                 break;
               }
             }
           }
         }
       }
       recipes.clear();
       recipes = newRecipes;
     }
     Resources.submitResource("PARSED_RECIPE: " + filename, recipes);
   }
   return recipes;
 }
示例#3
0
 public Lifecycle() {
   handlers = Maps.newHashMap();
   for (Stage stage : Stage.values()) {
     handlers.put(stage, new CopyOnWriteArrayList<Handler>());
   }
 }