org.jboss.mq.server
Class MessageCache

java.lang.Object
  extended byorg.jboss.mx.util.JBossNotificationBroadcasterSupport (src) 
      extended byorg.jboss.system.ServiceMBeanSupport (src) 
          extended byorg.jboss.mq.server.MessageCache
All Implemented Interfaces:
MBeanRegistration (src) , NotificationBroadcaster (src) , NotificationEmitter (src) , java.lang.Runnable, Service (src) , ServiceMBean (src)

public class MessageCache
extends ServiceMBeanSupport (src)
implements MBeanRegistration (src) , java.lang.Runnable

This class implements a Message cache so that larger amounts of messages can be processed without running out of memory. When memory starts getting tight it starts moving messages out of memory and into a file so that they can be recovered later. The locks should be obtained in the following order:
mr, the relevent message we are working with
lruCache, when maintaining the usage order


Field Summary
static long DEFAULT_HIGH_MEMORY_MARK
           
static long DEFAULT_MAX_MEMORY_MARK
           
static long ONE_MEGABYTE
           
 
Fields inherited from class org.jboss.system.ServiceMBeanSupport (src)
log, server, SERVICE_CONTROLLER_SIG, serviceName
 
Fields inherited from interface org.jboss.system.ServiceMBean (src)
CREATE_EVENT, CREATED, DESTROY_EVENT, DESTROYED, FAILED, REGISTERED, START_EVENT, STARTED, STARTING, states, STOP_EVENT, STOPPED, STOPPING, UNREGISTERED
 
Constructor Summary
MessageCache()
           
 
Method Summary
 MessageReference (src) add(SpyMessage (src)  message, BasicQueue (src)  queue, int stored)
          Adds a message to the cache.
 MessageReference (src) add(SpyMessage (src)  message, BasicQueue (src)  queue, int stored, DurableSubscriptionID (src)  id)
          Adds a message to the cache.
 MessageReference (src) addInternal(SpyMessage (src)  message, BasicQueue (src)  queue, int stored, DurableSubscriptionID (src)  id)
          Adds a message to the cache.
 long getCacheHits()
          Gets the cacheHits
 long getCacheMisses()
          Gets the cacheMisses
 ObjectName (src) getCacheStore()
          The getCacheStore method
 long getCurrentMemoryUsage()
          Gets the CurrentMemoryUsage
 int getHardRefCacheSize()
          Gets the hardRefCacheSize
 long getHighMemoryMark()
          Gets the highMemoryMark
 MessageCache (src) getInstance()
          The getInstance method
 boolean getMakeSoftReferences()
          Gets whether to make soft references
 int getMaximumHard()
          Gets the maximum number of hard messages
 long getMaxMemoryMark()
          Gets the maxMemoryMark
 int getMinimumHard()
          Gets the minimum number of hard messages
 java.lang.String getName()
          Use the short class name as the default for the service name.
 long getSoftenAtLeastEveryMillis()
          Gets the maximum length between softening checks
 long getSoftenedSize()
          The getSoftenedSize method
 long getSoftenNoMoreOftenThanMillis()
          Gets the minimum length between softening checks
 long getSoftenWaitMillis()
          Gets the length of time to wait before checking whether we should soften
 int getSoftRefCacheSize()
          Gets the softRefCacheSize
 int getTotalCacheSize()
          Gets the totalCacheSize
 void remove(MessageReference (src)  mr)
          removes a message from the cache
 void removeDelayed(MessageReference (src)  mr)
          removes a message from the cache without returning it to the pool used in two phase removes for joint cache/persistence
protected  void removeInternal(MessageReference (src)  mr, boolean clear, boolean reset)
          removes a message from the cache
 void run()
          The strategy is that we keep the most recently used messages as Hard references.
 void setCacheStore(ObjectName (src)  cacheStoreName)
           
 void setHighMemoryMark(long highMemoryMark)
          Sets the highMemoryMark
 void setMakeSoftReferences(boolean makeSoftReferences)
          Sets whether to make soft references
 void setMaximumHard(int maximumHard)
          Sets the maximum number of hard messages
 void setMaxMemoryMark(long maxMemoryMark)
          Sets the maxMemoryMark
 void setMinimumHard(int minimumHard)
          Sets the minimum number of hard messages
 void setSoftenAtLeastEveryMillis(long millis)
          Sets the minimum length between softening checks
 void setSoftenNoMoreOftenThanMillis(long millis)
          Sets the minimum length between softening checks
 void setSoftenWaitMillis(long millis)
          Sets the length of time to wait before checking whether we should soften
protected  void startService()
          This gets called to start the cache service.
protected  void stopService()
          This gets called to stop the cache service.
 
Methods inherited from class org.jboss.system.ServiceMBeanSupport (src)
create, createService, destroy, destroyService, getLog, getNextNotificationSequenceNumber, getObjectName, getServer, getServiceName, getState, getStateString, jbossInternalCreate, jbossInternalDescription, jbossInternalDestroy, jbossInternalLifecycle, jbossInternalStart, jbossInternalStop, postDeregister, postRegister, preDeregister, preRegister, start, stop
 
Methods inherited from class org.jboss.mx.util.JBossNotificationBroadcasterSupport (src)
addNotificationListener, getNotificationInfo, handleNotification, removeNotificationListener, removeNotificationListener, sendNotification
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.management.MBeanRegistration (src)
postDeregister, postRegister, preDeregister, preRegister
 

Field Detail

ONE_MEGABYTE

public static final long ONE_MEGABYTE
See Also:
Constant Field Values (src)

DEFAULT_HIGH_MEMORY_MARK

public static final long DEFAULT_HIGH_MEMORY_MARK
See Also:
Constant Field Values (src)

DEFAULT_MAX_MEMORY_MARK

public static final long DEFAULT_MAX_MEMORY_MARK
See Also:
Constant Field Values (src)
Constructor Detail

MessageCache

public MessageCache()
Method Detail

getInstance

public MessageCache (src)  getInstance()
The getInstance method

Returns:
a MessageCache value

add

public MessageReference (src)  add(SpyMessage (src)  message,
                            BasicQueue (src)  queue,
                            int stored)
                     throws JMSException (src) 
Adds a message to the cache.

Throws:
JMSException (src)

add

public MessageReference (src)  add(SpyMessage (src)  message,
                            BasicQueue (src)  queue,
                            int stored,
                            DurableSubscriptionID (src)  id)
                     throws JMSException (src) 
Adds a message to the cache.

Throws:
JMSException (src)

addInternal

public MessageReference (src)  addInternal(SpyMessage (src)  message,
                                    BasicQueue (src)  queue,
                                    int stored,
                                    DurableSubscriptionID (src)  id)
                             throws JMSException (src) 
Adds a message to the cache.

Throws:
JMSException (src)

remove

public void remove(MessageReference (src)  mr)
            throws JMSException (src) 
removes a message from the cache

Throws:
JMSException (src)

removeDelayed

public void removeDelayed(MessageReference (src)  mr)
                   throws JMSException (src) 
removes a message from the cache without returning it to the pool used in two phase removes for joint cache/persistence

Throws:
JMSException (src)

removeInternal

protected void removeInternal(MessageReference (src)  mr,
                              boolean clear,
                              boolean reset)
                       throws JMSException (src) 
removes a message from the cache

Throws:
JMSException (src)

run

public void run()
The strategy is that we keep the most recently used messages as Hard references. Then we make the older ones soft references. Making something a soft reference stores it to disk so we need to avoid making soft references if we can avoid it. But once it is made a soft reference does not mean that it is removed from memory. Depending on how agressive the JVM's GC is, it may stay around long enough for it to be used by a client doing a read, saving us read from the file system. If memory gets tight the GC will remove the soft references. What we want to do is make sure there are at least some soft references available so that the GC can reclaim memory.

Specified by:
run in interface java.lang.Runnable
See Also:
Runnable.run()

startService

protected void startService()
                     throws java.lang.Exception
This gets called to start the cache service. Synch. by start

Overrides:
startService in class ServiceMBeanSupport (src)
Throws:
java.lang.Exception

stopService

protected void stopService()
This gets called to stop the cache service.

Overrides:
stopService in class ServiceMBeanSupport (src)

getHardRefCacheSize

public int getHardRefCacheSize()
Gets the hardRefCacheSize

Returns:
Returns a int

getSoftenedSize

public long getSoftenedSize()
The getSoftenedSize method

Returns:
a long value

getSoftRefCacheSize

public int getSoftRefCacheSize()
Gets the softRefCacheSize

Returns:
Returns a int

getTotalCacheSize

public int getTotalCacheSize()
Gets the totalCacheSize

Returns:
Returns a int

getCacheMisses

public long getCacheMisses()
Gets the cacheMisses

Returns:
Returns a int

getCacheHits

public long getCacheHits()
Gets the cacheHits

Returns:
Returns a long

getMakeSoftReferences

public boolean getMakeSoftReferences()
Gets whether to make soft references

Returns:
true when making soft references

setMakeSoftReferences

public void setMakeSoftReferences(boolean makeSoftReferences)
Sets whether to make soft references


getMinimumHard

public int getMinimumHard()
Gets the minimum number of hard messages

Returns:
the minimum number of hard messages

setMinimumHard

public void setMinimumHard(int minimumHard)
Sets the minimum number of hard messages

Parameters:
minimumHard - the minimum number of hard messages

getMaximumHard

public int getMaximumHard()
Gets the maximum number of hard messages

Returns:
the minimum number of hard messages

setMaximumHard

public void setMaximumHard(int maximumHard)
Sets the maximum number of hard messages

Parameters:
maximumHard - the maximum number of hard messages

getSoftenWaitMillis

public long getSoftenWaitMillis()
Gets the length of time to wait before checking whether we should soften

Returns:
the time to wait

setSoftenWaitMillis

public void setSoftenWaitMillis(long millis)
Sets the length of time to wait before checking whether we should soften

Parameters:
millis - the time to wait in millis

getSoftenNoMoreOftenThanMillis

public long getSoftenNoMoreOftenThanMillis()
Gets the minimum length between softening checks

Returns:
the time to wait

setSoftenNoMoreOftenThanMillis

public void setSoftenNoMoreOftenThanMillis(long millis)
Sets the minimum length between softening checks


getSoftenAtLeastEveryMillis

public long getSoftenAtLeastEveryMillis()
Gets the maximum length between softening checks

Returns:
the time

setSoftenAtLeastEveryMillis

public void setSoftenAtLeastEveryMillis(long millis)
Sets the minimum length between softening checks


getHighMemoryMark

public long getHighMemoryMark()
Gets the highMemoryMark

Returns:
Returns a long

setHighMemoryMark

public void setHighMemoryMark(long highMemoryMark)
Sets the highMemoryMark

Parameters:
highMemoryMark - The highMemoryMark to set

getMaxMemoryMark

public long getMaxMemoryMark()
Gets the maxMemoryMark

Returns:
Returns a long

setMaxMemoryMark

public void setMaxMemoryMark(long maxMemoryMark)
Sets the maxMemoryMark

Parameters:
maxMemoryMark - The maxMemoryMark to set

getCurrentMemoryUsage

public long getCurrentMemoryUsage()
Gets the CurrentMemoryUsage

Returns:
Returns a long

getName

public java.lang.String getName()
Description copied from class: ServiceMBeanSupport (src)
Use the short class name as the default for the service name.

Specified by:
getName in interface ServiceMBean (src)
Overrides:
getName in class ServiceMBeanSupport (src)
See Also:
ServiceMBeanSupport.getName()

setCacheStore

public void setCacheStore(ObjectName (src)  cacheStoreName)
See Also:
MessageCacheMBean#setCacheStore(ObjectName)

getCacheStore

public ObjectName (src)  getCacheStore()
The getCacheStore method

Returns:
an ObjectName value