Ejemplo n.º 1
0
 /// <summary>Returns a "null" context - one which does nothing.</summary>
 public static MetricsContext GetNullContext(string contextName)
 {
     lock (typeof(ContextFactory))
     {
         MetricsContext nullContext = nullContextMap[contextName];
         if (nullContext == null)
         {
             nullContext = new NullContext();
             nullContextMap[contextName] = nullContext;
         }
         return(nullContext);
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Returns the named MetricsContext instance, constructing it if necessary
 /// using the factory's current configuration attributes.
 /// </summary>
 /// <remarks>
 /// Returns the named MetricsContext instance, constructing it if necessary
 /// using the factory's current configuration attributes. <p/>
 /// When constructing the instance, if the factory property
 /// <i>contextName</i>.class</code> exists,
 /// its value is taken to be the name of the class to instantiate.  Otherwise,
 /// the default is to create an instance of
 /// <code>org.apache.hadoop.metrics.spi.NullContext</code>, which is a
 /// dummy "no-op" context which will cause all metric data to be discarded.
 /// </remarks>
 /// <param name="contextName">the name of the context</param>
 /// <returns>the named MetricsContext</returns>
 /// <exception cref="System.IO.IOException"/>
 /// <exception cref="System.TypeLoadException"/>
 /// <exception cref="InstantiationException"/>
 /// <exception cref="System.MemberAccessException"/>
 public virtual MetricsContext GetContext(string refName, string contextName)
 {
     lock (this)
     {
         MetricsContext metricsContext = contextMap[refName];
         if (metricsContext == null)
         {
             string classNameAttribute = refName + ContextClassSuffix;
             string className          = (string)GetAttribute(classNameAttribute);
             if (className == null)
             {
                 className = DefaultContextClassname;
             }
             Type contextClass = Runtime.GetType(className);
             metricsContext = (MetricsContext)System.Activator.CreateInstance(contextClass);
             metricsContext.Init(contextName, this);
             contextMap[contextName] = metricsContext;
         }
         return(metricsContext);
     }
 }