Class AbstractMemoryMonitor
- java.lang.Object
 - 
- mondrian.util.AbstractMemoryMonitor
 
 
- 
- All Implemented Interfaces:
 MemoryMonitor,MemoryMonitor.Test
- Direct Known Subclasses:
 NotificationMemoryMonitor
public abstract class AbstractMemoryMonitor extends Object implements MemoryMonitor, MemoryMonitor.Test
Abstract implementation ofMemoryMonitor. Base class for different memory monitoring strategies.- Since:
 - Feb 03 2007
 - Author:
 - Richard M. Emberson
 
 
- 
- 
Nested Class Summary
- 
Nested classes/interfaces inherited from interface mondrian.util.MemoryMonitor
MemoryMonitor.Listener, MemoryMonitor.Test 
 - 
 
- 
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractMemoryMonitor()Constructor of this base class. 
- 
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description booleanaddListener(MemoryMonitor.Listener listener)Adds aListenerusing the default threshold percentage.booleanaddListener(MemoryMonitor.Listener listener, int percentage)Adds aListenerto theMemoryMonitorwith a given threshold percentage.protected longconvertPercentageToThreshold(int percentage)Converts a percentage threshold to its corresponding memory value, (percentage * maximum-memory / 100).protected intconvertThresholdToPercentage(long threshold)Converts a memory value to its percentage.protected longgenerateLowThreshold()Returns the lowest threshold from the list ofListeners.intgetDefaultThresholdPercentage()Returns the default memory notification percentage.protected abstract org.apache.logging.log4j.LoggergetLogger()Returns theLogger.protected longgetLowThreshold()Returns the current lowest threshold of all registeredListeners.protected voidnotifyListeners(long usedMemory, long maxMemory)Notifies allListeners that memory is running short.protected voidnotifyNewLowThreshold(long newLowThreshold)Derived classes implement this method if they wish to be notified when there is a new lowest threshold.voidremoveAllListener()Clear out allListeners and turnoff JVM memory notification.booleanremoveListener(MemoryMonitor.Listener listener)Removes aListenerfrom theMemoryMonitor.voidresetFromTest()This should only be called when one is switching from a testMemoryMonitorback to the default systemMemoryMonitor.voidupdateListenerThreshold(MemoryMonitor.Listener listener, int percentage)Changes the threshold percentage of a givenListener.protected intusagePercentage()Returns how much memory is currently being used as a percentage.- 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait 
- 
Methods inherited from interface mondrian.util.MemoryMonitor
getMaxMemory, getUsedMemory 
 - 
 
 - 
 
- 
- 
Method Detail
- 
getLogger
protected abstract org.apache.logging.log4j.Logger getLogger()
Returns theLogger.- Returns:
 - the 
Logger. 
 
- 
getLowThreshold
protected long getLowThreshold()
Returns the current lowest threshold of all registeredListeners.- Returns:
 - the lowest threshold.
 
 
- 
getDefaultThresholdPercentage
public int getDefaultThresholdPercentage()
Returns the default memory notification percentage.This is the value of the Mondrian
MondrianProperties.MemoryMonitorThresholdproperty.- Returns:
 - the default threshold percentage.
 
 
- 
addListener
public boolean addListener(MemoryMonitor.Listener listener)
Description copied from interface:MemoryMonitorAdds aListenerusing the default threshold percentage.If the threshold is below the Java5 memory managment system's threshold, then the Listener is notified from within this method.
- Specified by:
 addListenerin interfaceMemoryMonitor- Parameters:
 listener- theListenerto be added.- Returns:
 trueif theListenerwas added andfalseotherwise.
 
- 
addListener
public boolean addListener(MemoryMonitor.Listener listener, int percentage)
Description copied from interface:MemoryMonitorAdds aListenerto theMemoryMonitorwith a given threshold percentage.If the threshold is below the Java5 memory managment system's threshold, then the Listener is notified from within this method.
- Specified by:
 addListenerin interfaceMemoryMonitor- Parameters:
 listener- theListenerto be added.percentage- the threshold percentage for thisListener.- Returns:
 trueif theListenerwas added andfalseotherwise.
 
- 
updateListenerThreshold
public void updateListenerThreshold(MemoryMonitor.Listener listener, int percentage)
Description copied from interface:MemoryMonitorChanges the threshold percentage of a givenListener.If the new value is below the system's current value, then the
Listenerwill have its notification callback called while in this method - so a client should always check if its notification method was called immediately after calling this method.This method can be used if, for example, an algorithm has different approaches that result in different memory usage profiles; one, large memory but fast and a second which is low-memory but slow. The algorithm starts with the large memory approach, receives a low memory notification, switches to the low memory approach and changes when it should be notified for this new approach. The first approach need to be notified at a lower percentage because it uses lots of memory, possibly quickly; while the second approach, possibly a file based algorithm, has smaller memory requirements and uses memory less quickly thus one can live with a higher notification threshold percentage.
- Specified by:
 updateListenerThresholdin interfaceMemoryMonitor- Parameters:
 listener- theListenerbeing updated.percentage- new percentage threshold.
 
- 
removeListener
public boolean removeListener(MemoryMonitor.Listener listener)
Description copied from interface:MemoryMonitorRemoves aListenerfrom theMemoryMonitor. Returnstrueif listener was removed andfalseotherwise.- Specified by:
 removeListenerin interfaceMemoryMonitor- Parameters:
 listener- the listener to be removed- Returns:
 trueif listener was removed.
 
- 
removeAllListener
public void removeAllListener()
Description copied from interface:MemoryMonitorClear out allListeners and turnoff JVM memory notification.- Specified by:
 removeAllListenerin interfaceMemoryMonitor
 
- 
generateLowThreshold
protected long generateLowThreshold()
Returns the lowest threshold from the list ofListeners. If there are noListeners, then return the maximum memory usage. ReturnsLong.MAX_VALUEif there are noListeners- Returns:
 - the lowest threshold or 
Long.MAX_VALUE 
 
- 
notifyListeners
protected void notifyListeners(long usedMemory, long maxMemory)Notifies allListeners that memory is running short.- Parameters:
 usedMemory- the current memory used.maxMemory- the maximum memory.
 
- 
notifyNewLowThreshold
protected void notifyNewLowThreshold(long newLowThreshold)
Derived classes implement this method if they wish to be notified when there is a new lowest threshold.- Parameters:
 newLowThreshold- the new low threshold.
 
- 
convertPercentageToThreshold
protected long convertPercentageToThreshold(int percentage)
Converts a percentage threshold to its corresponding memory value, (percentage * maximum-memory / 100).- Parameters:
 percentage- the threshold.- Returns:
 - the memory value.
 
 
- 
convertThresholdToPercentage
protected int convertThresholdToPercentage(long threshold)
Converts a memory value to its percentage.- Parameters:
 threshold- the memory value.- Returns:
 - the percentage.
 
 
- 
usagePercentage
protected int usagePercentage()
Returns how much memory is currently being used as a percentage.- Returns:
 - currently used memory as a percentage.
 
 
- 
resetFromTest
public void resetFromTest()
Description copied from interface:MemoryMonitor.TestThis should only be called when one is switching from a testMemoryMonitorback to the default systemMemoryMonitor. In particular, look at theMemoryMonitorFactory'sclearThreadLocalClassName()method for its usage.- Specified by:
 resetFromTestin interfaceMemoryMonitor.Test
 
 - 
 
 -