Save This Page
Home » JBoss-5.1.0 » org » jboss » mq » server » [javadoc | source]
org.jboss.mq.server
public class: MessageCache [javadoc | source]
java.lang.Object
   org.jboss.mx.util.JBossNotificationBroadcasterSupport
      org.jboss.system.ServiceMBeanSupport
         org.jboss.mq.server.MessageCache

All Implemented Interfaces:
    MessageCacheMBean, Runnable, MBeanRegistration, KernelControllerContextAware, ServiceMBean, NotificationEmitter

Direct Known Subclasses:
    MessageCache

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
Nested Class Summary:
class  MessageCache.LRUCache  This class implements a simple, efficient LRUCache. It is pretty much a cut down version of the code in org.jboss.pool.cache.LeastRecentlyUsedCache 
static class  MessageCache.Node   
Field Summary
public static final  long ONE_MEGABYTE     
public static final  long DEFAULT_HIGH_MEMORY_MARK     
public static final  long DEFAULT_MAX_MEMORY_MARK     
 long cacheHits     
 long cacheMisses     
protected  CacheStore cacheStore     
 ObjectName cacheStoreName     
 int softRefCacheSize     
 int totalCacheSize     
 ReferenceQueue referenceQueue     
 long softenedSize     
 boolean checkSoftReferenceDepth     
Fields inherited from org.jboss.system.ServiceMBeanSupport:
SERVICE_CONTROLLER_SIG,  log,  server,  serviceName
Method from org.jboss.mq.server.MessageCache Summary:
add,   add,   addInternal,   getCacheHits,   getCacheMisses,   getCacheStore,   getCurrentMemoryUsage,   getHardRefCacheSize,   getHighMemoryMark,   getInstance,   getMakeSoftReferences,   getMaxMemoryMark,   getMaximumHard,   getMinimumHard,   getName,   getSoftRefCacheSize,   getSoftenAtLeastEveryMillis,   getSoftenNoMoreOftenThanMillis,   getSoftenWaitMillis,   getSoftenedSize,   getTotalCacheSize,   loadFromStorage,   messageReferenceUsedEvent,   remove,   removeDelayed,   removeFromStorage,   removeInternal,   run,   saveToStorage,   setCacheStore,   setHighMemoryMark,   setMakeSoftReferences,   setMaxMemoryMark,   setMaximumHard,   setMinimumHard,   setSoftenAtLeastEveryMillis,   setSoftenNoMoreOftenThanMillis,   setSoftenWaitMillis,   setupCacheStore,   soften,   startService,   stopService,   validateSoftReferenceDepth
Methods from org.jboss.system.ServiceMBeanSupport:
create,   createService,   destroy,   destroyService,   getDeploymentInfo,   getLog,   getName,   getNextNotificationSequenceNumber,   getObjectName,   getServer,   getServiceName,   getState,   getStateString,   jbossInternalCreate,   jbossInternalDescription,   jbossInternalDestroy,   jbossInternalLifecycle,   jbossInternalStart,   jbossInternalStop,   pojoChange,   pojoCreate,   pojoDestroy,   pojoStart,   pojoStop,   postDeregister,   postRegister,   preDeregister,   preRegister,   setKernelControllerContext,   start,   startService,   stop,   stopService,   unsetKernelControllerContext
Methods from org.jboss.mx.util.JBossNotificationBroadcasterSupport:
addNotificationListener,   getNotificationInfo,   handleNotification,   nextNotificationSequenceNumber,   removeNotificationListener,   removeNotificationListener,   sendNotification
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.jboss.mq.server.MessageCache Detail:
 public MessageReference add(SpyMessage message,
    BasicQueue queue,
    int stored) throws JMSException 
    Adds a message to the cache.
 public MessageReference add(SpyMessage message,
    BasicQueue queue,
    int stored,
    DurableSubscriptionID id) throws JMSException 
    Adds a message to the cache.
 public MessageReference addInternal(SpyMessage message,
    BasicQueue queue,
    int stored,
    DurableSubscriptionID id) throws JMSException 
    Adds a message to the cache.
 public long getCacheHits() 
    Gets the cacheHits
 public long getCacheMisses() 
    Gets the cacheMisses
 public ObjectName getCacheStore() 
    The getCacheStore method
 public long getCurrentMemoryUsage() 
    Gets the CurrentMemoryUsage
 public int getHardRefCacheSize() 
    Gets the hardRefCacheSize
 public long getHighMemoryMark() 
    Gets the highMemoryMark
 public MessageCache getInstance() 
    The getInstance method
 public boolean getMakeSoftReferences() 
    Gets whether to make soft references
 public long getMaxMemoryMark() 
    Gets the maxMemoryMark
 public int getMaximumHard() 
    Gets the maximum number of hard messages
 public int getMinimumHard() 
    Gets the minimum number of hard messages
 public String getName() 
 public int getSoftRefCacheSize() 
    Gets the softRefCacheSize
 public long getSoftenAtLeastEveryMillis() 
    Gets the maximum length between softening checks
 public long getSoftenNoMoreOftenThanMillis() 
    Gets the minimum length between softening checks
 public long getSoftenWaitMillis() 
    Gets the length of time to wait before checking whether we should soften
 public long getSoftenedSize() 
    The getSoftenedSize method
 public int getTotalCacheSize() 
    Gets the totalCacheSize
 SpyMessage loadFromStorage(MessageReference mh) throws JMSException 
  void messageReferenceUsedEvent(MessageReference mh,
    boolean wasHard) throws JMSException 
    This gets called when a MessageReference is de-referenced. We will pop it to the top of the RLU
 public  void remove(MessageReference mr) throws JMSException 
    removes a message from the cache
 public  void removeDelayed(MessageReference mr) throws JMSException 
    removes a message from the cache without returning it to the pool used in two phase removes for joint cache/persistence
  void removeFromStorage(MessageReference mh) throws JMSException 
 protected  void removeInternal(MessageReference mr,
    boolean clear,
    boolean reset) throws JMSException 
    removes a message from the cache
 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.
  void saveToStorage(MessageReference mh,
    SpyMessage message) throws JMSException 
 public  void setCacheStore(ObjectName cacheStoreName) 
 public  void setHighMemoryMark(long highMemoryMark) 
    Sets the highMemoryMark
 public  void setMakeSoftReferences(boolean makeSoftReferences) 
    Sets whether to make soft references
 public  void setMaxMemoryMark(long maxMemoryMark) 
    Sets the maxMemoryMark
 public  void setMaximumHard(int maximumHard) 
    Sets the maximum number of hard messages
 public  void setMinimumHard(int minimumHard) 
    Sets the minimum number of hard messages
 public  void setSoftenAtLeastEveryMillis(long millis) 
    Sets the minimum length between softening checks
 public  void setSoftenNoMoreOftenThanMillis(long millis) 
    Sets the minimum length between softening checks
 public  void setSoftenWaitMillis(long millis) 
    Sets the length of time to wait before checking whether we should soften
 protected  void setupCacheStore() throws Exception 
  void soften(MessageReference mr) throws JMSException 
    removes a message from the cache but does not clear it, used in softening
 protected  void startService() throws Exception 
    This gets called to start the cache service. Synch. by start
 protected  void stopService() 
    This gets called to stop the cache service.
 boolean validateSoftReferenceDepth() throws JMSException 
    This method is in charge of determining if it time to convert some hard references over to soft references.