ContactCenters
V. 0.9.9.

umontreal.iro.lecuyer.util
Class LowMemoryNotifier

java.lang.Object
  extended by umontreal.iro.lecuyer.util.LowMemoryNotifier

public class LowMemoryNotifier
extends Object

Uses the Java 5 Management API to monitor memory usage, and notifies registered listeners when memory becomes low. Memory is partitionned into memory pools for the Management API. Each pool can have a usage threshold which triggers a notification when exceeded.

When constructing a low-memory notifier, one specifies a collection of memory pools to monitor. For each monitored pool supporting the usage threshold, the threshold is set to a fraction of the maximum memory available for that pool, the default fraction is 0.75. When memory usage exceeds this fraction, a notification is emitted by the memory pool, and this class notifies the registered low-memory listeners. If the maximum memory available for the pool has increased between the time the object was created and the low-memory notification, the usage fraction becomes smaller than the threshold usage fraction, and no listener is notified. The usage threshold of the concerned pool is then updated.


Constructor Summary
LowMemoryNotifier()
          Constructs a low-memory notifier with usage threshold set to 0.75 and monitoring every memory pool supporting usage threshold.
LowMemoryNotifier(Collection<MemoryPoolMXBean> pools)
          Constructs a low-memory notifier with usage threshold set to 0.75, and monitoring every memory pool in pools supporting usage threshold.
LowMemoryNotifier(Collection<MemoryPoolMXBean> pools, double usageThreshold)
          Constructs a low-memory notifier with usage threshold set to usageThreshold, and monitoring every memory pool in pools supporting usage threshold.
LowMemoryNotifier(double usageThreshold)
          Constructs a low-memory notifier with usage threshold set to usageThreshold and monitoring every memory pool supporting usage threshold.
 
Method Summary
 void addLowMemoryListener(LowMemoryListener listener1)
          Registers the low-memory listener listener.
 List<LowMemoryListener> getLowMemoryListeners()
          Returns the low-memory listeners currently registered with this object.
 Collection<MemoryPoolMXBean> getMemoryPools()
          Returns the memory pools monitored by this object.
 double getUsageThreshold()
          Returns the usage threshold used by this low-memory notifier.
 void removeLowMemoryListener(LowMemoryListener listener1)
          Unregisters the low-memory listener listener.
 void removeLowMemoryListeners()
          Removes all low-memory listeners registered with this object.
 void setUsageThreshold(double usageThreshold)
          Sets the usage threshold used by this low-memory notifier to usageThreshold
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LowMemoryNotifier

public LowMemoryNotifier()
Constructs a low-memory notifier with usage threshold set to 0.75 and monitoring every memory pool supporting usage threshold.


LowMemoryNotifier

public LowMemoryNotifier(double usageThreshold)
Constructs a low-memory notifier with usage threshold set to usageThreshold and monitoring every memory pool supporting usage threshold.

Parameters:
usageThreshold - the usage threshold.
Throws:
IllegalArgumentException - if usageThreshold is smaller than 0 or greater than 1.

LowMemoryNotifier

public LowMemoryNotifier(Collection<MemoryPoolMXBean> pools)
Constructs a low-memory notifier with usage threshold set to 0.75, and monitoring every memory pool in pools supporting usage threshold.

Parameters:
pools - the collection of memory pools.
Throws:
NullPointerException - if pools is null.

LowMemoryNotifier

public LowMemoryNotifier(Collection<MemoryPoolMXBean> pools,
                         double usageThreshold)
Constructs a low-memory notifier with usage threshold set to usageThreshold, and monitoring every memory pool in pools supporting usage threshold.

Parameters:
pools - the collection of memory pools.
usageThreshold - the usage threshold.
Throws:
NullPointerException - if pools is null.
IllegalArgumentException - if usageThreshold is smaller than 0 or greater than 1.
Method Detail

addLowMemoryListener

public void addLowMemoryListener(LowMemoryListener listener1)
Registers the low-memory listener listener.

Parameters:
listener1 - the new low-memory listener to be registered.
Throws:
NullPointerException - if listener is null.

removeLowMemoryListener

public void removeLowMemoryListener(LowMemoryListener listener1)
Unregisters the low-memory listener listener.

Parameters:
listener1 - the low-memory listener to be unregistered.

removeLowMemoryListeners

public void removeLowMemoryListeners()
Removes all low-memory listeners registered with this object.


getLowMemoryListeners

public List<LowMemoryListener> getLowMemoryListeners()
Returns the low-memory listeners currently registered with this object.

Returns:
the list of currently-registered low-memory listeners.

getUsageThreshold

public double getUsageThreshold()
Returns the usage threshold used by this low-memory notifier.

Returns:
the current usage threshold.

setUsageThreshold

public void setUsageThreshold(double usageThreshold)
Sets the usage threshold used by this low-memory notifier to usageThreshold

Parameters:
usageThreshold - the current usage threshold.
Throws:
IllegalArgumentException - if usageThreshold is smaller than 0 or greater than 1.

getMemoryPools

public Collection<MemoryPoolMXBean> getMemoryPools()
Returns the memory pools monitored by this object.

Returns:
the monitored memory pools.

ContactCenters
V. 0.9.9.

To submit a bug or ask questions, send an e-mail to Richard Simard.