Package mondrian.util
Class MemoryMonitorFactory
- java.lang.Object
-
- mondrian.util.ObjectFactory<T>
-
- mondrian.util.ObjectFactory.Singleton<MemoryMonitor>
-
- mondrian.util.MemoryMonitorFactory
-
public final class MemoryMonitorFactory extends ObjectFactory.Singleton<MemoryMonitor>
TheMemoryMonitorFactory
is used to get the application'sMemoryMonitor
. TheMemoryMonitorFactory
is based upon theObjectFactory.Singleton
generic. TheMemoryMonitorFactory
implementation has a single, defaultMemoryMonitor
per JVM instance which can be overridden using the providedThreadLocal
variable. Normally, thisThreadLocal
override should only be used during JUnit testing. The JUnit test, set theThreadLocal
variable to the name of its own implementation of theMemoryMonitor
interface and then calls theObjectFactory
getObject
method. After doing the test, theThreadLocal
variable should be cleared.The
ObjectFactory.Singleton
permits the use ofSystem
properties to provide a class name to the factory. This can be used to create aMemoryMonitor
that is not the default one. The property name is theMemoryMonitor
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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
clearThreadLocalClassName()
Clears the class name (regardless of whether a class name was set).protected boolean
enabled()
Returns whether the use of aMemoryMonitor
is enabled.protected String
getClassName()
Get the class name set in theThreadLocal
or null.protected MemoryMonitor
getDefault(Class[] parameterTypes, Object[] parameterValues)
TheMemoryMonitorFactory
's implementation of theObjectFactory
's abstract method which returns the defaultMemoryMonitor
instance.static MemoryMonitor
getMemoryMonitor()
Access theMemoryMonitorFactory
instance.protected org.eigenbase.util.property.StringProperty
getStringProperty()
Return theMemoryMonitorFactory
static void
setThreadLocalClassName(String className)
Sets the class name of aMemoryMonitor
implementation.-
Methods inherited from class mondrian.util.ObjectFactory.Singleton
getObject, getTestObject
-
Methods inherited from class mondrian.util.ObjectFactory
getClassName, getObject, getObject, getObject, getObject, removeContext, restoreContext
-
-
-
-
Method Detail
-
getMemoryMonitor
public static MemoryMonitor getMemoryMonitor()
Access theMemoryMonitorFactory
instance.- Returns:
- the
MemoryMonitor
.
-
setThreadLocalClassName
public static void setThreadLocalClassName(String className)
Sets the class name of aMemoryMonitor
implementation. This should be called (obviously) before calling theMemoryMonitorFactory
getMemoryMonitor
method to get theMemoryMonitor
implementation. 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 aMemoryMonitor
is enabled.- Returns:
true
if enabled andfalse
otherwise.
-
getClassName
protected String getClassName()
Get the class name set in theThreadLocal
or null.- Overrides:
getClassName
in classObjectFactory<MemoryMonitor>
- Returns:
- class name or null.
-
getStringProperty
protected org.eigenbase.util.property.StringProperty getStringProperty()
Return theMemoryMonitorFactory
- Specified by:
getStringProperty
in classObjectFactory<MemoryMonitor>
- Returns:
MemoryMonitorFactory
property name
-
getDefault
protected MemoryMonitor getDefault(Class[] parameterTypes, Object[] parameterValues) throws CreationException
TheMemoryMonitorFactory
's implementation of theObjectFactory
's abstract method which returns the defaultMemoryMonitor
instance. For Java4 or if theMemoryMonitorFactory
is not enabled then this method returns the "faux"MemoryMonitor
implementation, it does nothing. When enabled and for Java5 and above JVMs, and instance of theNotificationMemoryMonitor
is returned.- Specified by:
getDefault
in classObjectFactory<MemoryMonitor>
- Parameters:
parameterTypes
- not usedparameterValues
- not used- Returns:
MemoryMonitor
instance- Throws:
CreationException
- if theMemoryMonitor
can not be created.
-
-