站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > JBoss 4.0.1 sp1 messaging API Documentation 英文版文档

MessageCache (JBoss Messaging API) - JBoss 4.0.1 sp1 messaging API Documentation 英文版文档


org.jboss.mq.server
Class MessageCache

java.lang.Object
  extended byorg.jboss.mx.util.JBossNotificationBroadcasterSupport
      extended byorg.jboss.system.ServiceMBeanSupport
          extended byorg.jboss.mq.server.MessageCache
All Implemented Interfaces:
javax.management.MBeanRegistration, MessageCacheMBean, javax.management.NotificationBroadcaster, javax.management.NotificationEmitter, Runnable, org.jboss.system.Service, org.jboss.system.ServiceMBean

public class MessageCache
extends org.jboss.system.ServiceMBeanSupport
implements MessageCacheMBean, javax.management.MBeanRegistration, 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

Version:
$Revision: 1.31 $
Author:
Hiram Chirino, David Maplesden, Peter Antman, Adrian Brock

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
log, server, SERVICE_CONTROLLER_SIG, serviceName
 
Fields inherited from interface org.jboss.mq.server.MessageCacheMBean
OBJECT_NAME
 
Fields inherited from interface org.jboss.system.ServiceMBean
CREATE_EVENT, CREATED, DESTROY_EVENT, DESTROYED, FAILED, REGISTERED, START_EVENT, STARTED, STARTING, states, STOP_EVENT, STOPPED, STOPPING, UNREGISTERED
 
Constructor Summary
MessageCache()
           
 
Method Summary
 MessageReference add(SpyMessage message)
          Adds a message to the cache
 MessageReference add(SpyMessage message, BasicQueue queue, int stored)
          Adds a message to the cache.
 MessageReference add(SpyMessage message, BasicQueue queue, int stored, DurableSubscriptionID id)
          Adds a message to the cache.
 MessageReference addInternal(SpyMessage message, BasicQueue queue, int stored, DurableSubscriptionID id)
          Adds a message to the cache.
 long getCacheHits()
          Gets the cacheHits
 long getCacheMisses()
          Gets the cacheMisses
 javax.management.ObjectName getCacheStore()
          The getCacheStore method
 long getCurrentMemoryUsage()
          Gets the CurrentMemoryUsage
 int getHardRefCacheSize()
          Gets the hardRefCacheSize
 long getHighMemoryMark()
          Gets the highMemoryMark
 MessageCache 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
 String getName()
           
 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 mr)
          removes a message from the cache
 void removeDelayed(MessageReference 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 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(javax.management.ObjectName 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
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
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 org.jboss.system.ServiceMBean
getState, getStateString, jbossInternalLifecycle
 
Methods inherited from interface org.jboss.system.Service
create, destroy, start, stop
 
Methods inherited from interface javax.management.MBeanRegistration
postDeregister, postRegister, preDeregister, preRegister
 

Field Detail

ONE_MEGABYTE

public static final long ONE_MEGABYTE
See Also:
Constant Field Values

DEFAULT_HIGH_MEMORY_MARK

public static final long DEFAULT_HIGH_MEMORY_MARK
See Also:
Constant Field Values

DEFAULT_MAX_MEMORY_MARK

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

MessageCache

public MessageCache()
Method Detail

getInstance

public MessageCache getInstance()
The getInstance method

Specified by:
getInstance in interface MessageCacheMBean
Returns:
a MessageCache value

add

public MessageReference add(SpyMessage message)
                     throws javax.jms.JMSException
Adds a message to the cache

Throws:
javax.jms.JMSException

add

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

Throws:
javax.jms.JMSException

add

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

Throws:
javax.jms.JMSException

addInternal

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

Throws:
javax.jms.JMSException

remove

public void remove(MessageReference mr)
            throws javax.jms.JMSException
removes a message from the cache

Throws:
javax.jms.JMSException

removeDelayed

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

Throws:
javax.jms.JMSException

removeInternal

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

Throws:
javax.jms.JMSException

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 Runnable
See Also:
Runnable.run()

startService

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

Throws:
Exception

stopService

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


getHardRefCacheSize

public int getHardRefCacheSize()
Gets the hardRefCacheSize

Specified by:
getHardRefCacheSize in interface MessageCacheMBean
Returns:
Returns a int

getSoftenedSize

public long getSoftenedSize()
The getSoftenedSize method

Specified by:
getSoftenedSize in interface MessageCacheMBean
Returns:
a long value

getSoftRefCacheSize

public int getSoftRefCacheSize()
Gets the softRefCacheSize

Specified by:
getSoftRefCacheSize in interface MessageCacheMBean
Returns:
Returns a int

getTotalCacheSize

public int getTotalCacheSize()
Gets the totalCacheSize

Specified by:
getTotalCacheSize in interface MessageCacheMBean
Returns:
Returns a int

getCacheMisses

public long getCacheMisses()
Gets the cacheMisses

Specified by:
getCacheMisses in interface MessageCacheMBean
Returns:
Returns a int

getCacheHits

public long getCacheHits()
Gets the cacheHits

Specified by:
getCacheHits in interface MessageCacheMBean
Returns:
Returns a long

getMakeSoftReferences

public boolean getMakeSoftReferences()
Gets whether to make soft references

Specified by:
getMakeSoftReferences in interface MessageCacheMBean
Returns:
true when making soft references

setMakeSoftReferences

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

Specified by:
setMakeSoftReferences in interface MessageCacheMBean

getMinimumHard

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

Specified by:
getMinimumHard in interface MessageCacheMBean
Returns:
the minimum number of hard messages

setMinimumHard

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

Specified by:
setMinimumHard in interface MessageCacheMBean
Parameters:
minimumHard - the minimum number of hard messages

getMaximumHard

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

Specified by:
getMaximumHard in interface MessageCacheMBean
Returns:
the minimum number of hard messages

setMaximumHard

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

Specified by:
setMaximumHard in interface MessageCacheMBean
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

Specified by:
getSoftenWaitMillis in interface MessageCacheMBean
Returns:
the time to wait

setSoftenWaitMillis

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

Specified by:
setSoftenWaitMillis in interface MessageCacheMBean
Parameters:
millis - the time to wait in millis

getSoftenNoMoreOftenThanMillis

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

Specified by:
getSoftenNoMoreOftenThanMillis in interface MessageCacheMBean
Returns:
the time to wait

setSoftenNoMoreOftenThanMillis

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

Specified by:
setSoftenNoMoreOftenThanMillis in interface MessageCacheMBean

getSoftenAtLeastEveryMillis

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

Specified by:
getSoftenAtLeastEveryMillis in interface MessageCacheMBean
Returns:
the time

setSoftenAtLeastEveryMillis

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

Specified by:
setSoftenAtLeastEveryMillis in interface MessageCacheMBean

getHighMemoryMark

public long getHighMemoryMark()
Gets the highMemoryMark

Specified by:
getHighMemoryMark in interface MessageCacheMBean
Returns:
Returns a long

setHighMemoryMark

public void setHighMemoryMark(long highMemoryMark)
Sets the highMemoryMark

Specified by:
setHighMemoryMark in interface MessageCacheMBean
Parameters:
highMemoryMark - The highMemoryMark to set

getMaxMemoryMark

public long getMaxMemoryMark()
Gets the maxMemoryMark

Specified by:
getMaxMemoryMark in interface MessageCacheMBean
Returns:
Returns a long

setMaxMemoryMark

public void setMaxMemoryMark(long maxMemoryMark)
Sets the maxMemoryMark

Specified by:
setMaxMemoryMark in interface MessageCacheMBean
Parameters:
maxMemoryMark - The maxMemoryMark to set

getCurrentMemoryUsage

public long getCurrentMemoryUsage()
Gets the CurrentMemoryUsage

Specified by:
getCurrentMemoryUsage in interface MessageCacheMBean
Returns:
Returns a long

getName

public String getName()
Specified by:
getName in interface org.jboss.system.ServiceMBean
See Also:
ServiceMBeanSupport.getName()

setCacheStore

public void setCacheStore(javax.management.ObjectName cacheStoreName)
Specified by:
setCacheStore in interface MessageCacheMBean
See Also:
MessageCacheMBean.setCacheStore(ObjectName)

getCacheStore

public javax.management.ObjectName getCacheStore()
The getCacheStore method

Specified by:
getCacheStore in interface MessageCacheMBean
Returns:
an ObjectName value


Copyright © 2002 JBoss Group, LLC. All Rights Reserved.