public static void Init(Configuration conf) { lock (typeof(RackResolver)) { if (initCalled) { return; } else { initCalled = true; } Type dnsToSwitchMappingClass = conf.GetClass <DNSToSwitchMapping>(CommonConfigurationKeysPublic .NetTopologyNodeSwitchMappingImplKey, typeof(ScriptBasedMapping)); try { DNSToSwitchMapping newInstance = ReflectionUtils.NewInstance(dnsToSwitchMappingClass , conf); // Wrap around the configured class with the Cached implementation so as // to save on repetitive lookups. // Check if the impl is already caching, to avoid double caching. dnsToSwitchMapping = ((newInstance is CachedDNSToSwitchMapping) ? newInstance : new CachedDNSToSwitchMapping(newInstance)); } catch (Exception e) { throw new RuntimeException(e); } } }
/// <summary> /// Query for a /// <see cref="DNSToSwitchMapping"/> /// instance being on a single /// switch. /// <p/> /// This predicate simply assumes that all mappings not derived from /// this class are multi-switch. /// </summary> /// <param name="mapping">the mapping to query</param> /// <returns> /// true if the base class says it is single switch, or the mapping /// is not derived from this class. /// </returns> public static bool IsMappingSingleSwitch(DNSToSwitchMapping mapping) { return(mapping != null && mapping is Org.Apache.Hadoop.Net.AbstractDNSToSwitchMapping && ((Org.Apache.Hadoop.Net.AbstractDNSToSwitchMapping)mapping).IsSingleSwitch()); }
/// <summary>Create an instance from the given raw mapping</summary> /// <param name="rawMap">raw DNSTOSwithMapping</param> public ScriptBasedMapping(DNSToSwitchMapping rawMap) : base(rawMap) { }
/// <summary>cache a raw DNS mapping</summary> /// <param name="rawMapping">the raw mapping to cache</param> public CachedDNSToSwitchMapping(DNSToSwitchMapping rawMapping) { this.rawMapping = rawMapping; }
private void AssertMultiSwitch(DNSToSwitchMapping mapping) { Assert.Equal("Expected a multi switch mapping " + mapping, false , AbstractDNSToSwitchMapping.IsMappingSingleSwitch(mapping)); }
private void AssertSingleSwitch(DNSToSwitchMapping mapping) { Assert.Equal("Expected a single switch mapping " + mapping, true , AbstractDNSToSwitchMapping.IsMappingSingleSwitch(mapping)); }