org.opencms.monitor
Class CmsMemoryMonitor

java.lang.Object
  extended byorg.opencms.monitor.CmsMemoryMonitor
All Implemented Interfaces:
I_CmsScheduledJob

public class CmsMemoryMonitor
extends java.lang.Object
implements I_CmsScheduledJob

Monitors OpenCms memory consumtion.

Since:
6.0.0
Version:
$Revision: 1.58 $
Author:
Carsten Weinholz, Michael Emmerich, Alexander Kandzior

Constructor Summary
CmsMemoryMonitor()
          Empty constructor, required by OpenCms scheduler.
 
Method Summary
 boolean enabled()
          Returns if monitoring is enabled.
 CmsMemoryMonitorConfiguration getConfiguration()
          Returns the configuration.
 int getLogCount()
          Returns the log count.
static int getMemorySize(java.lang.Object obj)
          Returns the size of objects that are instances of byte[], String, CmsFile,I_CmsLruCacheObject.
 void initialize(CmsMemoryMonitorConfiguration configuration)
          Initializes the monitor with the provided configuration.
 java.lang.String launch(CmsObject cms, java.util.Map parameters)
          This method will be called when this scheduled job is executed.
 boolean lowMemory()
          Returns true if the system runs low on memory.
 void register(java.lang.String objectName, java.lang.Object object)
          Adds a new object to the monitor.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CmsMemoryMonitor

public CmsMemoryMonitor()
Empty constructor, required by OpenCms scheduler.

Method Detail

getMemorySize

public static int getMemorySize(java.lang.Object obj)
Returns the size of objects that are instances of byte[], String, CmsFile,I_CmsLruCacheObject.

For other objects, a size of 0 is returned.

Parameters:
obj - the object
Returns:
the size of the object

enabled

public boolean enabled()
Returns if monitoring is enabled.

Returns:
true if monitoring is enabled

getConfiguration

public CmsMemoryMonitorConfiguration getConfiguration()
Returns the configuration.

Returns:
the configuration

getLogCount

public int getLogCount()
Returns the log count.

Returns:
the log count

initialize

public void initialize(CmsMemoryMonitorConfiguration configuration)
Initializes the monitor with the provided configuration.

Parameters:
configuration - the configuration to use

launch

public java.lang.String launch(CmsObject cms,
                               java.util.Map parameters)
                        throws java.lang.Exception
Description copied from interface: I_CmsScheduledJob
This method will be called when this scheduled job is executed.

Depending on the configuration of this job, a new instance of the configured class will be instanciated every time the job is launched, or a new instance will be generated only the first time the job is launched, and re-used afterwards.

The result String will be written to the OpenCms logfile in the org.opencms.scheduler.CmsScheduleManager channel, on INFO log level.

Specified by:
launch in interface I_CmsScheduledJob
Parameters:
cms - will be initialized with the configured users cms context
parameters - the configured parameters
Returns:
a String that will be written to the OpenCms logfile
Throws:
java.lang.Exception - if something goes wrong
See Also:
I_CmsScheduledJob.launch(CmsObject, Map)

lowMemory

public boolean lowMemory()
Returns true if the system runs low on memory.

Returns:
true if the system runs low on memory

register

public void register(java.lang.String objectName,
                     java.lang.Object object)
Adds a new object to the monitor.

Parameters:
objectName - name of the object
object - the object for monitoring