org.exolab.jms.gc
Class GarbageCollectionService

java.lang.Object
  |
  +--org.exolab.core.service.Service
        |
        +--org.exolab.core.service.BasicService
              |
              +--org.exolab.jms.gc.GarbageCollectionService
All Implemented Interfaces:
EventHandler, java.lang.Runnable, java.io.Serializable, org.exolab.core.service.Serviceable

public class GarbageCollectionService
extends org.exolab.core.service.BasicService
implements EventHandler

The garbage collection service is responsible for managing all transient garbage collection for OpenJMS, which includes messages, destinations, endpoints etc. It does not deal with persistent data, which is handled through the database service. Other services or managers can register themselves with GarbageCollectionService if they implement the GarbageCollectable interface.

Gargabe collection will be initiated when the amount of free memory falls below a low water mark, which is calculated as a percentage of total memory. By default garbage collection will run when free memory falls below 20% of total memory, this can be changed through the configuration file.

The service will check the memory usage every 30 seconds by default. but this can also be modified through the configuration file.

In addition the garbage collection service can also be configured to execute at regular intervals regardless the amount of residual free memory. This option can be employed to ease the burden of performing wholesale garbage collection when memory falls below the low water mark threshold. The default value for this is 300 seconds. Setting this value to 0 will disable this capability.

This service makes use of the BasicEventManager to register events for garbage collection.

Version:
$Revision: 1.14 $ $Date: 2003/08/17 01:32:23 $
Author:
Jim Alateras
See Also:
Serialized Form

Method Summary
 boolean belowLowWaterThreshold()
          Check whether the low water threshold has been reached.
 org.exolab.core.foundation.HandleIfc getHandle()
          Return a handle to this event handler for the purpose of storing and restoring it.
 void handleEvent(int event, java.lang.Object callback, long time)
          Handle the specified event, generated by the EventManager.
static GarbageCollectionService instance()
          Return the singleton instance of the GarbageCollectionService
 void register(GarbageCollectable entry)
          Register an entity that wishes to participate in the garbage collection process.
 void run()
           
 void start()
           
 void stop()
           
 void unregister(GarbageCollectable entry)
          Unregister the specified entry from the list of garbge collectable entities
 
Methods inherited from class org.exolab.core.service.BasicService
toString
 
Methods inherited from class org.exolab.core.service.Service
getName, getState, restart, setState
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

instance

public static GarbageCollectionService instance()
                                         throws GarbageCollectionServiceException
Return the singleton instance of the GarbageCollectionService
Returns:
GarbageCollectionService
Throws:
GarbageCollectionServiceException -  

belowLowWaterThreshold

public boolean belowLowWaterThreshold()
Check whether the low water threshold has been reached.
Returns:
boolean - true if it has; false otherwise

register

public void register(GarbageCollectable entry)
Register an entity that wishes to participate in the garbage collection process. This entity will be added to the list of other registered entities and will be called when GC is triggered.
Parameters:
entry - - entry to add to list

unregister

public void unregister(GarbageCollectable entry)
Unregister the specified entry from the list of garbge collectable entities
Parameters:
entry - - entry to remove

run

public void run()
Overrides:
run in class org.exolab.core.service.BasicService

start

public void start()
           throws org.exolab.core.service.ServiceException
Overrides:
start in class org.exolab.core.service.BasicService

stop

public void stop()
          throws org.exolab.core.service.ServiceException
Overrides:
stop in class org.exolab.core.service.BasicService

getHandle

public org.exolab.core.foundation.HandleIfc getHandle()
Description copied from interface: EventHandler
Return a handle to this event handler for the purpose of storing and restoring it. If you want event handlers to persist across subsequent invocations of the EventManager then you must support this method, otherwise this method can simply return null.
Specified by:
getHandle in interface EventHandler
Following copied from interface: org.exolab.jms.events.EventHandler
Returns:
HandleIfc return a reference to the handle.

handleEvent

public void handleEvent(int event,
                        java.lang.Object callback,
                        long time)
Description copied from interface: EventHandler
Handle the specified event, generated by the EventManager. The event handler pressumably knows how to handle the callback object and should cast it appropriately before using it.

This methodshould not throw any exceptions

Specified by:
handleEvent in interface EventHandler
Following copied from interface: org.exolab.jms.events.EventHandler
Parameters:
event - the event to handle
callback - the callback object
time - the absolute time, in ms, that the event fired.


Copyright © 1999-2004 The OpenJMS Group. All Rights Reserved.