public void load(String filename) {
    Map data = FileUtil.readResilientConfigFile(filename, false);

    // horrendous recursive loading going on here due to logger + config depedencies. If already
    // loaded
    // then use the existing data as it might have already been written to...

    if (propertiesMap == null) {

      ConcurrentHashMapWrapper<String, Object> c_map =
          new ConcurrentHashMapWrapper<String, Object>(data.size() + 256, 0.75f, 8);

      c_map.putAll(data);

      propertiesMap = c_map;
    }

    /*
     * Can't do this yet.  Sometimes, there's a default set to x, but the code
     * calls get..Parameter(..., y).  y != x.  When the user sets the the parameter
     * to x, we remove it from the list.  Later, the get..Parameter(.., y) returns
     * y because there is no entry.
     *
     * The solution is to not allow get..Parameter(.., y) when there's a default
     * value.  Another reason to not allow it is that having two defaults confuses
     * coders.
     *
      	// Remove entries that are default.  Saves memory, reduces
      	// file size when saved again
        ConfigurationDefaults def = ConfigurationDefaults.getInstance();
      	Iterator it = new TreeSet(propertiesMap.keySet()).iterator();

    		while (it.hasNext()) {
    			String key = (String)it.next();
    			Object defValue = def.getDefaultValueAsObject(key);
    			if (defValue == null)
    				continue;

    			if (defValue instanceof Long) {
    				int iDefValue = ((Long)defValue).intValue();
    				int iValue = getIntParameter(key, iDefValue);
    				if (iValue == iDefValue)
    					propertiesMap.remove(key);
    			}
    			if (defValue instanceof String) {
    				String sDefValue = defValue.toString();
    				String sValue = getStringParameter(key, sDefValue);
    				if (sValue.compareTo(sDefValue) == 0)
    					propertiesMap.remove(key);
    			}
    		}
    */
  }
示例#2
0
  public static void setUDPProbeResult(URL tracker_url, boolean probe_ok) {
    String key = tracker_url.getHost();

    synchronized (udp_probe_results) {
      boolean changed = false;

      if (udp_probe_results.get(key) == null) {

        if (probe_ok) {

          // arbitrary max size here just in case something weird happens

          if (udp_probe_results.size() > 512) {

            udp_probe_results.clear();
          }

          udp_probe_results.put(key, new Long(SystemTime.getCurrentTime()));

          changed = true;
        }
      } else {

        if (!probe_ok) {

          if (udp_probe_results.remove(key) != null) {

            changed = true;
          }
        }
      }

      if (changed) {

        COConfigurationManager.setParameter("Tracker Client UDP Probe Results", udp_probe_results);
      }
    }
  }