Package mondrian.util
Class MemoryMonitorFactory
The
MemoryMonitorFactory is used to get the application's
MemoryMonitor. The MemoryMonitorFactory is
based upon the ObjectFactory.Singleton generic. The
MemoryMonitorFactory implementation has a single, default
MemoryMonitor per JVM instance which can be overridden
using the provided ThreadLocal variable. Normally, this
ThreadLocal override should only be used during JUnit testing.
The JUnit test, set the ThreadLocal variable to the name of its
own implementation of the MemoryMonitor interface and
then calls the ObjectFactory getObject method.
After doing the test, the ThreadLocal variable should
be cleared.
The ObjectFactory.Singleton permits the use
of System properties to provide a class name to the
factory. This can be used to create a MemoryMonitor
that is not the default one. The property name is the
MemoryMonitor class name, "mondrian.util.MemoryMonitor".
- Since:
- Feb 03 2007
- Author:
- Richard M. Emberson
-
Nested Class Summary
Nested classes/interfaces inherited from class mondrian.util.ObjectFactory
ObjectFactory.Context, ObjectFactory.Singleton<T> -
Field Summary
Fields inherited from class mondrian.util.ObjectFactory.Singleton
singleInstance, testSingleInstance -
Method Summary
Modifier and TypeMethodDescriptionstatic voidClears the class name (regardless of whether a class name was set).protected booleanenabled()Returns whether the use of aMemoryMonitoris enabled.protected StringGet the class name set in theThreadLocalor null.protected MemoryMonitorgetDefault(Class[] parameterTypes, Object[] parameterValues) TheMemoryMonitorFactory's implementation of theObjectFactory's abstract method which returns the defaultMemoryMonitorinstance.static MemoryMonitorAccess theMemoryMonitorFactoryinstance.protected org.eigenbase.util.property.StringPropertyReturn theMemoryMonitorFactory</code property name.static voidsetThreadLocalClassName(String className) Sets the class name of aMemoryMonitorimplementation.Methods inherited from class mondrian.util.ObjectFactory.Singleton
getObject, getTestObjectMethods inherited from class mondrian.util.ObjectFactory
getClassName, getObject, getObject, getObject, getObject, removeContext, restoreContext
-
Method Details
-
getMemoryMonitor
Access theMemoryMonitorFactoryinstance.- Returns:
- the
MemoryMonitor.
-
setThreadLocalClassName
Sets the class name of aMemoryMonitorimplementation. This should be called (obviously) before calling theMemoryMonitorFactorygetMemoryMonitormethod to get theMemoryMonitorimplementation. Generally, this is only used for testing.- Parameters:
className- Class name
-
clearThreadLocalClassName
public static void clearThreadLocalClassName()Clears the class name (regardless of whether a class name was set). When a class name is set usingsetThreadLocalClassName, the setting whould be done in a try-block and a call to this clear method should be in the finally-clause of that try-block. -
enabled
protected boolean enabled()Returns whether the use of aMemoryMonitoris enabled.- Returns:
trueif enabled andfalseotherwise.
-
getClassName
Get the class name set in theThreadLocalor null.- Overrides:
getClassNamein classObjectFactory<MemoryMonitor>- Returns:
- class name or null.
-
getStringProperty
protected org.eigenbase.util.property.StringProperty getStringProperty()Return theMemoryMonitorFactory</code property name.- Specified by:
getStringPropertyin classObjectFactory<MemoryMonitor>- Returns:
MemoryMonitorFactoryproperty name
-
getDefault
protected MemoryMonitor getDefault(Class[] parameterTypes, Object[] parameterValues) throws CreationException TheMemoryMonitorFactory's implementation of theObjectFactory's abstract method which returns the defaultMemoryMonitorinstance. For Java4 or if theMemoryMonitorFactoryis not enabled then this method returns the "faux"MemoryMonitorimplementation, it does nothing. When enabled and for Java5 and above JVMs, and instance of theNotificationMemoryMonitoris returned.- Specified by:
getDefaultin classObjectFactory<MemoryMonitor>- Parameters:
parameterTypes- not usedparameterValues- not used- Returns:
MemoryMonitorinstance- Throws:
CreationException- if theMemoryMonitorcan not be created.
-