cmailleux    2005/11/09 16:04:28 CET

  Modified files:
    core/src/java/org/jahia/hibernate/manager 
                                              JahiaLockManager.java 
                                              JahiaWorkflowManager.java 
    core/src/webapp/WEB-INF/etc/spring 
                                       applicationcontext-manager.xml 
  Log:
  Replace Map with jahia cache
  
  Revision  Changes    Path
  1.5       +53 -13    
jahia/core/src/java/org/jahia/hibernate/manager/JahiaLockManager.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/core/src/java/org/jahia/hibernate/manager/JahiaLockManager.java.diff?r1=1.4&r2=1.5&f=h
  1.4       +38 -7     
jahia/core/src/java/org/jahia/hibernate/manager/JahiaWorkflowManager.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/core/src/java/org/jahia/hibernate/manager/JahiaWorkflowManager.java.diff?r1=1.3&r2=1.4&f=h
  1.7       +6 -0      
jahia/core/src/webapp/WEB-INF/etc/spring/applicationcontext-manager.xml
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/core/src/webapp/WEB-INF/etc/spring/applicationcontext-manager.xml.diff?r1=1.6&r2=1.7&f=h
  
  
  
  Index: JahiaLockManager.java
  ===================================================================
  RCS file: 
/home/cvs/repository/jahia/core/src/java/org/jahia/hibernate/manager/JahiaLockManager.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- JahiaLockManager.java     20 Sep 2005 17:03:08 -0000      1.4
  +++ JahiaLockManager.java     9 Nov 2005 15:04:27 -0000       1.5
  @@ -3,18 +3,18 @@
    */
   package org.jahia.hibernate.manager;
   
  -import org.apache.commons.collections.FastHashMap;
  +import org.jahia.exceptions.JahiaInitializationException;
   import org.jahia.hibernate.dao.JahiaLockDAO;
   import org.jahia.hibernate.model.JahiaLock;
   import org.jahia.hibernate.model.JahiaLockPK;
   import org.jahia.registries.ServicesRegistry;
  +import org.jahia.services.cache.Cache;
  +import org.jahia.services.cache.CacheService;
   import org.jahia.services.lock.Lock;
   import org.jahia.services.lock.LockKey;
   import org.jahia.services.usermanager.JahiaUser;
   import org.springframework.orm.ObjectRetrievalFailureException;
   
  -import java.util.Map;
  -
   /**
    * Created by IntelliJ IDEA.
    * User: Rincevent
  @@ -23,39 +23,63 @@
    * To change this template use File | Settings | File Templates.
    */
   public class JahiaLockManager {
  +    public static final String LOCK_CACHE_NAME = "JahiaLockManagerCache";
       private JahiaLockDAO dao = null;
  -    private Map fast = new FastHashMap(111);
  +    private Cache fast = null;
  +    private CacheService cacheService = null;
   
       public void setJahiaLockDAO(JahiaLockDAO dao) {
           this.dao = dao;
       }
   
  +    public void setCacheService(CacheService cacheService) {
  +        this.cacheService = cacheService;
  +    }
  +
       public void save(LockKey lockKey, Lock lock) {
           JahiaLockPK pk = new JahiaLockPK(lockKey.getName(), new 
Integer(lockKey.getId()), lockKey.getAction());
           JahiaLock jahiaLock = null;
  -            jahiaLock = new JahiaLock();
  -            jahiaLock.setComp_id(pk);
  +        jahiaLock = new JahiaLock();
  +        jahiaLock.setComp_id(pk);
           jahiaLock.setContextID(lock.getID());
           jahiaLock.setOwner(lock.getOwner().getUserKey());
           jahiaLock.setStolen(Boolean.toString(lock.isStealed()));
           long secondsTimeout = lock.getTimeout() / 1000;
           jahiaLock.setTimeout(new Integer(new 
Long(secondsTimeout).intValue()));
           dao.merge(jahiaLock);
  -        fast.remove(lockKey);
  +        if (fast == null) {
  +            try {
  +                fast = cacheService.createCacheInstance(LOCK_CACHE_NAME);
  +            } catch (JahiaInitializationException e) {
  +                e.printStackTrace();  //To change body of catch statement 
use File | Settings | File Templates.
  +            }
  +        }
  +        if (fast != null) {
  +            fast.remove(lockKey);
  +            fast.put(lockKey, lock);
  +        }
       }
   
       public Lock getLock(LockKey lockKey) {
           Lock lock = null;
  -        if (!fast.containsKey(lockKey)) {
  +        if (fast == null) {
  +            try {
  +                fast = cacheService.createCacheInstance(LOCK_CACHE_NAME);
  +            } catch (JahiaInitializationException e) {
  +                e.printStackTrace();  //To change body of catch statement 
use File | Settings | File Templates.
  +            }
  +        }
  +        if (fast == null || !fast.containsKey(lockKey)) {
               try {
                   JahiaLock jahiaLock = dao.findByPK(new 
JahiaLockPK(lockKey.getName(), new Integer(lockKey.getId()), 
lockKey.getAction()));
                   JahiaUser owner = 
ServicesRegistry.getInstance().getJahiaUserManagerService().lookupUser(jahiaLock.getOwner());
                   lock = new Lock(owner, jahiaLock.getContextID(), 
jahiaLock.getTimeout().intValue(),
  -                        Boolean.getBoolean(jahiaLock.getStolen()));
  +                                Boolean.getBoolean(jahiaLock.getStolen()));
               } catch (Exception e) {
   
               }
  -            fast.put(lockKey, lock);
  +            if (fast != null)
  +                fast.put(lockKey, lock);
           } else {
               lock = (Lock) fast.get(lockKey);
           }
  @@ -65,8 +89,16 @@
       public void remove(LockKey lockKey) {
           try {
               dao.delete(dao.findByPK(new JahiaLockPK(lockKey.getName(), new 
Integer(lockKey.getId()), lockKey.getAction())));
  -            fast.remove(lockKey);
  -        } catch(ObjectRetrievalFailureException e){ // nothing to delete 
  +            if (fast == null) {
  +                try {
  +                    fast = cacheService.createCacheInstance(LOCK_CACHE_NAME);
  +                } catch (JahiaInitializationException e) {
  +                    e.printStackTrace();  //To change body of catch 
statement use File | Settings | File Templates.
  +                }
  +            }
  +            if (fast != null)
  +                fast.remove(lockKey);
  +        } catch (ObjectRetrievalFailureException e) { // nothing to delete
           } catch (Exception e) {
               throw new RuntimeException(e);
           }
  @@ -74,6 +106,14 @@
   
       public void removeAllLocks() {
           dao.deleteAllLocks();
  -        fast.clear();
  +        if (fast == null) {
  +            try {
  +                fast = cacheService.createCacheInstance(LOCK_CACHE_NAME);
  +            } catch (JahiaInitializationException e) {
  +                e.printStackTrace();  //To change body of catch statement 
use File | Settings | File Templates.
  +            }
  +        }
  +        if (fast != null)
  +            fast.flush();
       }
   }
  
  
  
  Index: JahiaWorkflowManager.java
  ===================================================================
  RCS file: 
/home/cvs/repository/jahia/core/src/java/org/jahia/hibernate/manager/JahiaWorkflowManager.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- JahiaWorkflowManager.java 12 Jul 2005 13:52:55 -0000      1.3
  +++ JahiaWorkflowManager.java 9 Nov 2005 15:04:27 -0000       1.4
  @@ -6,8 +6,11 @@
   import org.apache.commons.collections.FastHashMap;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  +import org.jahia.exceptions.JahiaInitializationException;
   import org.jahia.hibernate.dao.JahiaWorkflowDAO;
   import org.jahia.hibernate.model.JahiaWorkflow;
  +import org.jahia.services.cache.Cache;
  +import org.jahia.services.cache.CacheService;
   import org.jahia.services.workflow.WorkflowService;
   
   import java.util.Map;
  @@ -20,27 +23,46 @@
    * To change this template use File | Settings | File Templates.
    */
   public class JahiaWorkflowManager {
  +    public static final String WORKFLOW_CACHE_NAME = 
"JahiaWorkflowManagerCache";
       private JahiaWorkflowDAO dao = null;
       private Log log = LogFactory.getLog(JahiaWorkflowManager.class);
  -    private Map fast = new FastHashMap(111);
  +    private Cache fast = null;
  +    private CacheService cacheService = null;
   
  -    public JahiaWorkflowManager() {
  -        ((FastHashMap) fast).setFast(true);
  -    }
   
       public void setJahiaWorkflowDAO(JahiaWorkflowDAO dao) {
           this.dao = dao;
       }
   
  +    public void setCacheService(CacheService cacheService) {
  +        this.cacheService = cacheService;
  +    }
  +
       public void createWorkflowEntry(String objectKey, int mode, String 
workflowName, String processId) {
           JahiaWorkflow workflow = new JahiaWorkflow(objectKey, new 
Integer(mode), workflowName, processId);
           dao.save(workflow);
  -        fast.remove(objectKey);
  +        if (fast == null) {
  +            try {
  +                fast = cacheService.createCacheInstance(WORKFLOW_CACHE_NAME);
  +            } catch (JahiaInitializationException e) {
  +                e.printStackTrace();  //To change body of catch statement 
use File | Settings | File Templates.
  +            }
  +        }
  +        if (fast != null)
  +            fast.remove(objectKey);
       }
   
       public void updateWorkflowEntry(String objectKey, int mode, String 
workflowName, String processId) {
           JahiaWorkflow workflow = new JahiaWorkflow(objectKey, new 
Integer(mode), workflowName, processId);
           dao.update(workflow);
  +        if (fast == null) {
  +            try {
  +                fast = cacheService.createCacheInstance(WORKFLOW_CACHE_NAME);
  +            } catch (JahiaInitializationException e) {
  +                e.printStackTrace();  //To change body of catch statement 
use File | Settings | File Templates.
  +            }
  +        }
  +        if (fast != null)
           fast.remove(objectKey);
       }
   
  @@ -49,7 +71,15 @@
               log.debug("getWorkflowEntry for object key : " + objectKey);
           }
           Map map = null;
  -        map = (Map) fast.get(objectKey);
  +        if (fast == null) {
  +            try {
  +                fast = cacheService.createCacheInstance(WORKFLOW_CACHE_NAME);
  +            } catch (JahiaInitializationException e) {
  +                e.printStackTrace();  //To change body of catch statement 
use File | Settings | File Templates.
  +            }
  +        }
  +        if (fast != null)
  +            map = (Map) fast.get(objectKey);
           if (map == null) {
               JahiaWorkflow workflow = null;
               map = new FastHashMap(3);
  @@ -63,7 +93,8 @@
               } catch (Exception e) {
                   log.warn("no entry for key " + objectKey, e);
               }
  -            fast.put(objectKey, map);
  +            if (fast != null)
  +                fast.put(objectKey, map);
           }
           return map;
       }
  
  
  
  Index: applicationcontext-manager.xml
  ===================================================================
  RCS file: 
/home/cvs/repository/jahia/core/src/webapp/WEB-INF/etc/spring/applicationcontext-manager.xml,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- applicationcontext-manager.xml    3 Nov 2005 13:22:47 -0000       1.6
  +++ applicationcontext-manager.xml    9 Nov 2005 15:04:28 -0000       1.7
  @@ -380,6 +380,9 @@
                   <property name="jahiaLockDAO">
                       <ref bean="jahiaLockDAO"/>
                   </property>
  +                <property name="cacheService">
  +                    <ref bean="JahiaCacheService"/>
  +                </property>
               </bean>
           </property>
       </bean>
  @@ -485,6 +488,9 @@
                   <property name="jahiaWorkflowDAO">
                       <ref bean="jahiaWorkflowDAO"/>
                   </property>
  +                <property name="cacheService">
  +                    <ref bean="JahiaCacheService"/>
  +                </property>
               </bean>
           </property>
       </bean>
  

Reply via email to