Class ContextFactory
- java.lang.Object
-
- com.mapr.org.apache.hadoop.metrics.ContextFactory
-
@LimitedPrivate({"HDFS","MapReduce"}) @Evolving public class ContextFactory extends java.lang.ObjectFactory class for creating MetricsContext objects. To obtain an instance of this class, use the staticgetFactory()method.
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedContextFactory()Creates a new instance of ContextFactory
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Collection<MetricsContext>getAllContexts()Returns all MetricsContexts built by this factory.java.lang.ObjectgetAttribute(java.lang.String attributeName)Returns the value of the named attribute, or null if there is no attribute of that name.java.lang.String[]getAttributeNames()Returns the names of all the factory's attributes.MetricsContextgetContext(java.lang.String contextName)MetricsContextgetContext(java.lang.String refName, java.lang.String contextName)Returns the named MetricsContext instance, constructing it if necessary using the factory's current configuration attributes.static ContextFactorygetFactory()Returns the singleton ContextFactory instance, constructing it if necessary.static MetricsContextgetNullContext(java.lang.String contextName)Returns a "null" context - one which does nothing.voidremoveAttribute(java.lang.String attributeName)Removes the named attribute if it exists.voidsetAttribute(java.lang.String attributeName, java.lang.Object value)Sets the named factory attribute to the specified value, creating it if it did not already exist.
-
-
-
Method Detail
-
getAttribute
public java.lang.Object getAttribute(java.lang.String attributeName)
Returns the value of the named attribute, or null if there is no attribute of that name.- Parameters:
attributeName- the attribute name- Returns:
- the attribute value
-
getAttributeNames
public java.lang.String[] getAttributeNames()
Returns the names of all the factory's attributes.- Returns:
- the attribute names
-
setAttribute
public void setAttribute(java.lang.String attributeName, java.lang.Object value)Sets the named factory attribute to the specified value, creating it if it did not already exist. If the value is null, this is the same as calling removeAttribute.- Parameters:
attributeName- the attribute namevalue- the new attribute value
-
removeAttribute
public void removeAttribute(java.lang.String attributeName)
Removes the named attribute if it exists.- Parameters:
attributeName- the attribute name
-
getContext
public MetricsContext getContext(java.lang.String refName, java.lang.String contextName) throws java.io.IOException, java.lang.ClassNotFoundException, java.lang.InstantiationException, java.lang.IllegalAccessException
Returns the named MetricsContext instance, constructing it if necessary using the factory's current configuration attributes. When constructing the instance, if the factory property contextName.class exists, its value is taken to be the name of the class to instantiate. Otherwise, the default is to create an instance oforg.apache.hadoop.metrics.spi.NullContext, which is a dummy "no-op" context which will cause all metric data to be discarded.- Parameters:
contextName- the name of the context- Returns:
- the named MetricsContext
- Throws:
java.io.IOExceptionjava.lang.ClassNotFoundExceptionjava.lang.InstantiationExceptionjava.lang.IllegalAccessException
-
getContext
public MetricsContext getContext(java.lang.String contextName) throws java.io.IOException, java.lang.ClassNotFoundException, java.lang.InstantiationException, java.lang.IllegalAccessException
- Throws:
java.io.IOExceptionjava.lang.ClassNotFoundExceptionjava.lang.InstantiationExceptionjava.lang.IllegalAccessException
-
getAllContexts
public java.util.Collection<MetricsContext> getAllContexts()
Returns all MetricsContexts built by this factory.
-
getNullContext
public static MetricsContext getNullContext(java.lang.String contextName)
Returns a "null" context - one which does nothing.
-
getFactory
public static ContextFactory getFactory() throws java.io.IOException
Returns the singleton ContextFactory instance, constructing it if necessary. When the instance is constructed, this method checks if the filehadoop-metrics.propertiesexists on the class path. If it exists, it must be in the format defined by java.util.Properties, and all the properties in the file are set as attributes on the newly created ContextFactory instance.- Returns:
- the singleton ContextFactory instance
- Throws:
java.io.IOException
-
-