shuber      2004/10/29 20:03:26 CEST

  Modified files:
    core/src/java/org/jahia/services/cache JMSHub.java 
                                           JMSHubPublisherHandler.java 
                                           JMSMessageQueue.java 
    core/src/java/org/jahia/settings SettingsBean.java 
    core/src/webapp/WEB-INF/etc/config jahia.skeleton 
  Log:
  Fix for JAHIA-218 :
  - Fix problem of cache flush that was causing OutOfMemory error when sending too 
many packages in a single JMS message. Added configuration parameter that allows to 
set a threshold for the max number of messages in a single JMS package. Set to 2000 by 
default.
  
  Revision  Changes    Path
  1.6       +17 -9     jahia/core/src/java/org/jahia/services/cache/JMSHub.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/core/src/java/org/jahia/services/cache/JMSHub.java.diff?r1=1.5&r2=1.6&f=h
  1.7       +10 -2     
jahia/core/src/java/org/jahia/services/cache/JMSHubPublisherHandler.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/core/src/java/org/jahia/services/cache/JMSHubPublisherHandler.java.diff?r1=1.6&r2=1.7&f=h
  1.5       +10 -4     
jahia/core/src/java/org/jahia/services/cache/JMSMessageQueue.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/core/src/java/org/jahia/services/cache/JMSMessageQueue.java.diff?r1=1.4&r2=1.5&f=h
  1.11      +3 -1      jahia/core/src/java/org/jahia/settings/SettingsBean.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/core/src/java/org/jahia/settings/SettingsBean.java.diff?r1=1.10&r2=1.11&f=h
  1.11      +1 -0      jahia/core/src/webapp/WEB-INF/etc/config/jahia.skeleton
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/core/src/webapp/WEB-INF/etc/config/jahia.skeleton.diff?r1=1.10&r2=1.11&f=h
  
  
  
  Index: JMSHub.java
  ===================================================================
  RCS file: 
/home/cvs/repository/jahia/core/src/java/org/jahia/services/cache/JMSHub.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- JMSHub.java       28 Jul 2004 17:36:35 -0000      1.5
  +++ JMSHub.java       29 Oct 2004 18:03:25 -0000      1.6
  @@ -39,17 +39,21 @@
   
   package org.jahia.services.cache;
   
  -import org.jahia.settings.SettingsBean;
  -import org.jahia.exceptions.JahiaInitializationException;
  -
  -import javax.naming.Context;
  -import javax.naming.NamingException;
  -import javax.naming.InitialContext;
  -import javax.jms.*;
  +import java.util.Hashtable;
  +import javax.jms.ExceptionListener;
  +import javax.jms.JMSException;
  +import javax.jms.MapMessage;
  +import javax.jms.Session;
  +import javax.jms.Topic;
   import javax.jms.TopicConnection;
  +import javax.jms.TopicConnectionFactory;
   import javax.jms.TopicSession;
  -import javax.jms.Topic;
  -import java.util.Hashtable;
  +import javax.naming.Context;
  +import javax.naming.InitialContext;
  +import javax.naming.NamingException;
  +
  +import org.jahia.exceptions.JahiaInitializationException;
  +import org.jahia.settings.SettingsBean;
   
   
   /** This class handles all the JMS Connections, the Message Publisher and Consumer, 
as
  @@ -711,4 +715,8 @@
           return cacheFactory;
       }
   
  +    public SettingsBean getSettings () {
  +        return settings;
  +    }
  +
   }
  
  
  
  Index: JMSHubPublisherHandler.java
  ===================================================================
  RCS file: 
/home/cvs/repository/jahia/core/src/java/org/jahia/services/cache/JMSHubPublisherHandler.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- JMSHubPublisherHandler.java       29 Oct 2004 15:07:20 -0000      1.6
  +++ JMSHubPublisherHandler.java       29 Oct 2004 18:03:25 -0000      1.7
  @@ -47,6 +47,7 @@
   import java.util.Map;
   import org.jahia.utils.InsertionSortedMap;
   import java.util.Iterator;
  +import org.jahia.settings.SettingsBean;
   
   
   /** <p>This class implements the Message Publisher's core process.</p>
  @@ -76,6 +77,8 @@
       final private static org.apache.log4j.Logger logger =
               org.apache.log4j.Logger.getLogger (JMSHubPublisherHandler.class);
   
  +    private int maxMessagesPerPackage = 1000;
  +
       /** message queues, one queue per cache. */
       // private Map queues;
       private JMSMessageQueue jmsMessageQueue;
  @@ -121,6 +124,10 @@
   
           jmsHub = hub;
   
  +        if 
(jmsHub.getSettings().lookupInt(SettingsBean.JMS_MAX_MESSAGES_IN_PACKAGE) > 0) {
  +            maxMessagesPerPackage = 
jmsHub.getSettings().lookupInt(SettingsBean.JMS_MAX_MESSAGES_IN_PACKAGE);
  +        }
  +
           // Initialize the publisher to the related topic
           try {
               TopicSession session = jmsHub.getTopicSession();
  @@ -170,8 +177,9 @@
               while (running) {
   
                  JMSCacheMessage[] messages = null;
  +               do {
                  synchronized (jmsMessageQueue) {
  -                   messages = jmsMessageQueue.extractMessages();
  +                   messages = 
jmsMessageQueue.extractMessages(maxMessagesPerPackage);
                  }
   
                       // the resulting message
  @@ -185,7 +193,7 @@
                       } else if (messages.length > 1) {
                          computeMultipleMessages(messages, message);
                      }
  -
  +               } while (messages.length > 0);
   
                   // wait until the next notification
                   synchronized (this) {
  
  
  
  Index: JMSMessageQueue.java
  ===================================================================
  RCS file: 
/home/cvs/repository/jahia/core/src/java/org/jahia/services/cache/JMSMessageQueue.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- JMSMessageQueue.java      28 Jul 2004 17:36:35 -0000      1.4
  +++ JMSMessageQueue.java      29 Oct 2004 18:03:25 -0000      1.5
  @@ -149,17 +149,23 @@
        *
        * @return  the extracted messages object array
        */
  -    public synchronized JMSCacheMessage[] extractMessages() {
  +    public synchronized JMSCacheMessage[] extractMessages(int sendCountThreshold) {
           if (queue.size() == 0)
               return new JMSCacheMessage[0];
   
  +        JMSCacheMessage[] messages = null;
  +        if (queue.size() < sendCountThreshold) {
           // extract all the messages
  -        JMSCacheMessage[] messages =
  -                (JMSCacheMessage[])queue.toArray(new JMSCacheMessage[queue.size()]);
  +            messages = (JMSCacheMessage[]) queue.toArray(new 
JMSCacheMessage[queue.size()]);
   
           // clear the queue
           queue.clear();
  -
  +        } else {
  +            messages = new JMSCacheMessage[sendCountThreshold];
  +            for (int i=0; i < sendCountThreshold; i++) {
  +                messages[i] = (JMSCacheMessage) queue.remove(0);
  +            }
  +        }
           return messages;
       }
   
  
  
  
  Index: SettingsBean.java
  ===================================================================
  RCS file: 
/home/cvs/repository/jahia/core/src/java/org/jahia/settings/SettingsBean.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- SettingsBean.java 8 Sep 2004 13:40:19 -0000       1.10
  +++ SettingsBean.java 29 Oct 2004 18:03:25 -0000      1.11
  @@ -1,4 +1,4 @@
  -// $Id: SettingsBean.java,v 1.10 2004/09/08 13:40:19 shuber Exp $
  +// $Id: SettingsBean.java,v 1.11 2004/10/29 18:03:25 shuber Exp $
   //
   //                                   ____.
   //                       __/\ ______|    |__/\.     _______
  @@ -171,6 +171,7 @@
       final public static String JMS_CONTEXT_PROVIDER_URL = 
"org.jahia.cache.jmsCacheContextProviderURL";
       final public static String JMS_TOPIC_CONNECTION_FACTORY_NAME = 
"org.jahia.cache.jmsCacheTopicConnectionFactoryName";
       final public static String JMS_TOPIC_NAME = "org.jahia.cache.jmsCacheTopicName";
  +    final public static String JMS_MAX_MESSAGES_IN_PACKAGE = 
"org.jahia.cache.jmsCacheMaxMessagesInPackage";
       final public static String JMS_SERVER_LOOKUP_SLEEP_TIME = 
"org.jahia.cache.jmsServerLookupSleepTime";
       final public static long JMS_SERVER_LOOKUP_SLEEP_TIME_DEFAULT = 5000;  // 5 
seconds
   
  @@ -393,6 +394,7 @@
               settings.put (JMS_TOPIC_CONNECTION_FACTORY_NAME,
                       getString (JMS_TOPIC_CONNECTION_FACTORY_NAME, null));
               settings.put (JMS_TOPIC_NAME, getString (JMS_TOPIC_NAME, null));
  +            settings.put (JMS_MAX_MESSAGES_IN_PACKAGE, new 
Integer(getInt(JMS_MAX_MESSAGES_IN_PACKAGE, 2000)));
               settings.put (JMS_SERVER_LOOKUP_SLEEP_TIME,
                       new Long (
                               getLong (JMS_SERVER_LOOKUP_SLEEP_TIME,
  
  
  
  Index: jahia.skeleton
  ===================================================================
  RCS file: 
/home/cvs/repository/jahia/core/src/webapp/WEB-INF/etc/config/jahia.skeleton,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- jahia.skeleton    28 Sep 2004 14:20:16 -0000      1.10
  +++ jahia.skeleton    29 Oct 2004 18:03:26 -0000      1.11
  @@ -153,6 +153,7 @@
   org.jahia.cache.jmsCacheContextProviderURL              = rmi://localhost:1099/
   org.jahia.cache.jmsCacheTopicConnectionFactoryName      = JmsTopicConnectionFactory
   org.jahia.cache.jmsCacheTopicName                       = jahiaCache
  +org.jahia.cache.jmsCacheMaxMessagesInPackage            = 2000
   org.jahia.cache.jmsServerLookupSleepTime                = 10000
   
   ### JMX Settings #####################
  

Reply via email to