Exemplo n.º 1
0
 /**
  * Creates a new map with the same mappings as the given map. The map is created with a capacity
  * of twice the number of mappings in the given map or 11 (whichever is greater), and a default
  * load factor.
  *
  * @param t the map
  */
 public ConcurrentHashMap(Map<? extends K, ? extends V> t) {
   this(
       Math.max((int) (t.size() / DEFAULT_LOAD_FACTOR) + 1, 11),
       DEFAULT_LOAD_FACTOR,
       DEFAULT_SEGMENTS);
   putAll(t);
 }
Exemplo n.º 2
0
 /**
  * Populates the internal collection of registered {@link AuthScheme authentication schemes} with
  * the content of the map passed as a parameter.
  *
  * @param map authentication schemes
  */
 public void setItems(final Map<String, AuthSchemeFactory> map) {
   if (map == null) {
     return;
   }
   registeredSchemes.clear();
   registeredSchemes.putAll(map);
 }
Exemplo n.º 3
0
 public OAbstractProfiler(final OAbstractProfiler profiler) {
   hooks.putAll(profiler.hooks);
   dictionary.putAll(profiler.dictionary);
   types.putAll(profiler.types);
 }
  public final void fillVersions(
      final ConcurrentHashMap<AddonVersionReference, AbstractAddon> versions) {

    for (ConcurrentHashMap.Entry<AddonDeveloperReference, AbstractAddonDeveloper> developer :
        developers.entrySet()) versions.putAll(developer.getValue().listVersions());
  }
Exemplo n.º 5
0
        @Override
        public void onChange(String resource) {
          try {
            LOG.debug("Reading " + resource);

            HashMap<CommandExecutor.Method, Stage> newexecutorsMap =
                new HashMap<CommandExecutor.Method, Stage>();
            Document document = getResourceLoader().getDocument(resource);
            Map<Stage, Integer> totals = new EnumMap<Stage, Integer>(Stage.class);

            if (document != null) {
              org.w3c.dom.NodeList ellist = document.getDocumentElement().getChildNodes();

              Stage prevStage = Stage.RECOGNIZER;
              for (int i = 0; i <= ellist.getLength(); i++) {
                if (ellist.item(i) instanceof Element) {
                  Element el = (Element) ellist.item(i);
                  if (el.getTagName().equals("localhost")) {
                    int max = Integer.parseInt(el.getAttribute("max_simultaneous_transcoders"));
                    Stage s = Stage.valueOf(el.getAttribute("stage").toUpperCase());
                    Integer t = totals.get(s);
                    if (t == null) t = 0;
                    t += max;
                    totals.put(s, t);
                    for (int j = 1; j <= max; j++) {
                      newexecutorsMap.put(new CommandExecutor.Method(), s);
                    }
                  } else if (el.getTagName().equals("server")) {
                    int max = Integer.parseInt(el.getAttribute("max_simultaneous_transcoders"));
                    Stage s = Stage.valueOf(el.getAttribute("stage").toUpperCase());
                    Integer t = totals.get(s);
                    if (t == null) t = 0;
                    t += max;
                    totals.put(s, t);
                    String host = el.getAttribute("host");
                    int port = Integer.parseInt(el.getAttribute("port"));
                    for (int j = 1; j <= max; j++) {
                      newexecutorsMap.put(new CommandExecutor.Method(host, port), s);
                    }
                  }
                }
              }
              for (Map.Entry<Stage, Integer> e : totals.entrySet()) {
                threadPools.get(e.getKey()).setCorePoolSize(e.getValue());
                threadPools.get(e.getKey()).setMaximumPoolSize(e.getValue());
              }
            } else {
              LOG.warn("No " + resource);
            }
            synchronized (executorsMap) {
              executorsMap.clear();
              executorsMap.putAll(newexecutorsMap);
            }
            LOG.service(
                "Reading of configuration file "
                    + resource
                    + " successfull. Executors "
                    + executorsMap
                    + ". Max simultaneous transcoders: "
                    + totals);
          } catch (Exception e) {
            LOG.error(
                e.getClass()
                    + " "
                    + e.getMessage()
                    + " In "
                    + resource
                    + " Executors now "
                    + executorsMap
                    + " (not changed)",
                e);
          }
        }