Class ContextFactory
java.lang.Object
com.mapr.org.apache.hadoop.metrics.ContextFactory
Factory class for creating MetricsContext objects. To obtain an instance
of this class, use the static
getFactory() method.-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCreates a new instance of ContextFactory -
Method Summary
Modifier and TypeMethodDescriptionReturns all MetricsContexts built by this factory.getAttribute(String attributeName) Returns the value of the named attribute, or null if there is no attribute of that name.String[]Returns the names of all the factory's attributes.getContext(String contextName) getContext(String refName, String contextName) Returns the named MetricsContext instance, constructing it if necessary using the factory's current configuration attributes.static ContextFactoryReturns the singleton ContextFactory instance, constructing it if necessary.static MetricsContextgetNullContext(String contextName) Returns a "null" context - one which does nothing.voidremoveAttribute(String attributeName) Removes the named attribute if it exists.voidsetAttribute(String attributeName, Object value) Sets the named factory attribute to the specified value, creating it if it did not already exist.
-
Constructor Details
-
ContextFactory
protected ContextFactory()Creates a new instance of ContextFactory
-
-
Method Details
-
getAttribute
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
Returns the names of all the factory's attributes.- Returns:
- the attribute names
-
setAttribute
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
Removes the named attribute if it exists.- Parameters:
attributeName- the attribute name
-
getContext
public MetricsContext getContext(String refName, String contextName) throws IOException, ClassNotFoundException, InstantiationException, 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:
IOExceptionClassNotFoundExceptionInstantiationExceptionIllegalAccessException
-
getContext
public MetricsContext getContext(String contextName) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException -
getAllContexts
Returns all MetricsContexts built by this factory. -
getNullContext
Returns a "null" context - one which does nothing. -
getFactory
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:
IOException
-