Author: bpapez
Date: Mon Aug 27 12:29:56 2007
New Revision: 18272

URL: https://svndev.jahia.net/websvn/listing.php?sc=3D1&rev=3D18272&repname=
=3Djahia
Log:
Up-porting of the synchronized refactoring from Jahia 4.2 (see blog: http:/=
/intranet.jahia.com/jahia/Jahia/site/intranet/cache/bypass/pid/73?entryId=
=3D306)

Modified:
    branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/services/container=
s/ContainerFactory.java
    branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/services/lock/Lock=
Registry.java
    branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/services/sites/Jah=
iaSitesBaseService.java

Modified: branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/services/con=
tainers/ContainerFactory.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/branches/JAHIA-5-0-SP=
-BRANCH/core/src/java/org/jahia/services/containers/ContainerFactory.java&r=
ev=3D18272&repname=3Djahia
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/services/container=
s/ContainerFactory.java (original)
+++ branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/services/container=
s/ContainerFactory.java Mon Aug 27 12:29:56 2007
@@ -105,69 +105,51 @@
         }
 =

         if (!container.isFieldsLoaded()) {
-                       synchronized (container) {
-                               container.clearFields();
-                               container.setFieldsLoaded(true);
-                               // not already in fullyLoadedList -> load it
-                               final List fieldIDs =3D 
ServicesRegistry.getInstance()
-                                               
.getJahiaContainersService().getFieldIDsInContainer(
-                                                               
container.getID(), loadRequest);
-                               for (int i =3D 0; i < fieldIDs.size(); i++) {
-                                       final int fieldID =3D ((Integer) 
fieldIDs.get(i)).intValue();
-                                       final JahiaField aField =3D 
ServicesRegistry.getInstance()
-                                                       
.getJahiaFieldService().loadField(fieldID,
-                                                                       
loadFlag, jParams, loadRequest);
-                                       if (aField !=3D null) {
-                                               container.addField(aField);
-                                       }
-                               }
-                       }
-               }
+            synchronized (container) {
+                container.clearFields();
+                container.setFieldsLoaded(true);
+                // not already in fullyLoadedList -> load it
+                final List fieldIDs =3D ServicesRegistry.getInstance()
+                        .getJahiaContainersService().getFieldIDsInContaine=
r(
+                                container.getID(), loadRequest);
+                for (int i =3D 0; i < fieldIDs.size(); i++) {
+                    final int fieldID =3D ((Integer) fieldIDs.get(i)).intV=
alue();
+                    final JahiaField aField =3D ServicesRegistry.getInstan=
ce()
+                            .getJahiaFieldService().loadField(fieldID,
+                                    loadFlag, jParams, loadRequest);
+                    if (aField !=3D null) {
+                        container.addField(aField);
+                    }
+                }
+            }
+        }
 =

         if (!container.isContainerListsLoaded()) {
-               synchronized (container) {
-                               container.clearContainerLists();
-                               container.setContainerListsLoaded(true);
-                               final JahiaContainersService ctnServ =3D 
ServicesRegistry
-                                               
.getInstance().getJahiaContainersService();
-
-                               // load container lists
-                               // load the the containers for this one
-                               // apply containers search and filtering.
-                               // listIDs =3D 
ctnServ.getCtnListIDsInContainer(container.getID());
-                               final List listIDs =3D containerListManager
-                                               
.getSubContainerListIDs(container.getID(), loadRequest);
-                               final int size =3D listIDs.size();
-                               for (int i =3D 0; i < size; i++) {
-                                       final Integer listID =3D (Integer) 
listIDs.get(i);
-                                       final JahiaContainerList cList =3D 
ctnServ.loadContainerList(
-                                                       listID.intValue(), 
loadFlag, jParams, loadRequest,
-                                                       
cachedFieldsFromContainers,
-                                                       
cachedContainersFromContainerLists,
-                                                       
cachedContainerListsFromContainers);
+            synchronized (container) {
+                container.clearContainerLists();
+                container.setContainerListsLoaded(true);
+                final JahiaContainersService ctnServ =3D ServicesRegistry
+                        .getInstance().getJahiaContainersService();
+
+                // load container lists
+                // load the the containers for this one
+                // apply containers search and filtering.
+                // listIDs =3D ctnServ.getCtnListIDsInContainer(container.=
getID());
+                final List listIDs =3D containerListManager
+                        .getSubContainerListIDs(container.getID(), loadReq=
uest);
+                final int size =3D listIDs.size();
+                for (int i =3D 0; i < size; i++) {
+                    final Integer listID =3D (Integer) listIDs.get(i);
+                    final JahiaContainerList cList =3D ctnServ.loadContain=
erList(
+                            listID.intValue(), loadFlag, jParams, loadRequ=
est,
+                            cachedFieldsFromContainers,
+                            cachedContainersFromContainerLists,
+                            cachedContainerListsFromContainers);
 =

-                                       if (cList !=3D null) {
-                    /*
-                                        * Vector ctnids =3D 
doContainerFilterSearchSort (jParams,
-                                        * loadRequest, cList.getDefinition 
().getName (),
-                                        * cList.getID (), 
cachedContainersFromContainerLists); if
-                                        * (ctnids !=3D null) { cList =3D 
ServicesRegistry.getInstance
-                                        * ().getJahiaContainersService () 
.loadContainerList
-                                        * (cList.getID (), ctnids, loadFlag, 
jParams, loadRequest,
-                                        * cachedFieldsFromContainers,
-                                        * cachedContainersFromContainerLists); 
} else { cList =3D
-                                        * ServicesRegistry.getInstance 
().getJahiaContainersService ()
-                                        * .loadContainerList (cList.getID (), 
loadFlag, jParams,
-                                        * loadRequest, 
cachedFieldsFromContainers,
-                                        * cachedContainersFromContainerLists); 
} cList =3D
-                                        * fullyLoadContainerList (cList, 
loadFlag, jParams,
-                                        * loadRequest, 
cachedFieldsFromContainers,
-                                        * cachedContainersFromContainerLists,
-                                        * cachedContainerListsFromContainers);
-                                        */
-                    container.addContainerList(cList);
-                                       }
-                               }
+                    if (cList !=3D null) {
+                        container.addContainerList(cList);
+                    }
+                }
             }
         }
     }

Modified: branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/services/loc=
k/LockRegistry.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/branches/JAHIA-5-0-SP=
-BRANCH/core/src/java/org/jahia/services/lock/LockRegistry.java&rev=3D18272=
&repname=3Djahia
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/services/lock/Lock=
Registry.java (original)
+++ branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/services/lock/Lock=
Registry.java Mon Aug 27 12:29:56 2007
@@ -100,7 +100,7 @@
      * non expiration time lock use the constant NO_EXPIRATION_TIME.
      * @return True if the lock was acquired, false otherwise.
      */
-    public synchronized boolean acquire (final LockKey lockKey,
+    public boolean acquire (final LockKey lockKey,
                                          final JahiaUser owner,
                                          final String lockID,
                                          final int timeout) {
@@ -117,7 +117,7 @@
      * non expiration time lock use the constant NO_EXPIRATION_TIME.
      * @return True if the lock was acquired, false otherwise.
      */
-    public synchronized boolean acquire (final LockKey lockKey,
+    public boolean acquire (final LockKey lockKey,
                                          final JahiaUser owner,
                                          final String lockID,
                                          final int timeout,
@@ -154,7 +154,7 @@
      * @param lockID The lock ID
      * @return true if the lock is acquireable, false otherwise.
      */
-    public synchronized boolean isAcquireable (final LockKey lockKey,
+    public boolean isAcquireable (final LockKey lockKey,
                                                final JahiaUser owner,
                                                final String lockID) {
         return LockPrerequisites.getInstance().isLockAcquirable(lockKey, o=
wner, lockID, true);
@@ -167,7 +167,7 @@
      * @param owner The lock owner
      * @param lockID The lock identifier.
      */
-    public synchronized void release (final LockKey lockKey,
+    public void release (final LockKey lockKey,
                                       final JahiaUser owner,
                                       final String lockID) {
         if (canRelease(lockKey, owner, lockID)) {
@@ -182,7 +182,7 @@
      * @param lockKey The lock key identifying the lock.
      * @return The lock attributes
      */
-    public synchronized List getInfo (final LockKey lockKey) {
+    public List getInfo (final LockKey lockKey) {
         List results =3D new ArrayList();
         List locks =3D getLocks(lockKey);
         for (Iterator iterator =3D locks.iterator(); iterator.hasNext();) {
@@ -205,7 +205,7 @@
      * @param lockKey The lock key identifying the lock.
      * @return The lock tremaining time in second.
      */
-    public synchronized Long getTimeRemaining (LockKey lockKey, String loc=
kID) {
+    public Long getTimeRemaining (LockKey lockKey, String lockID) {
         Lock lock =3D getLock(lockKey, lockID);
         if (lock =3D=3D null) {
             return null;
@@ -222,20 +222,20 @@
      * @param newOwner The new lock owner.
      * @param lockID The new lock identifier.
      */
-    public synchronized void steal (final LockKey lockKey,
+    public void steal (final LockKey lockKey,
                                     final JahiaUser newOwner,
                                     final String lockID) {
         if (hasAdminRights(lockKey, newOwner)) {
-               synchronized (this) {
-                               List l =3D getLocks(lockKey);
-                               for (Iterator iterator =3D l.iterator(); 
iterator.hasNext();) {
-                                       Lock lock =3D (Lock) iterator.next();
-                                       lock.setStealed(true);
-                                       putLock(lockKey, lock);
-                               }
+            synchronized (this) {
+                List l =3D getLocks(lockKey);
+                for (Iterator iterator =3D l.iterator(); iterator.hasNext(=
);) {
+                    Lock lock =3D (Lock) iterator.next();
+                    lock.setStealed(true);
+                    putLock(lockKey, lock);
+                }
 =

-                               
LockPrerequisites.getInstance().resetPrerequisite(lockKey);
-                       }
+                LockPrerequisites.getInstance().resetPrerequisite(lockKey);
+            }
         }
     }
 =

@@ -257,10 +257,10 @@
                                    final JahiaUser owner,
                                    final String lockID) {
         if (hasAdminRights(lockKey, owner)) {
-               synchronized (this) {
-                               removeLock(lockKey, lockID);
-                               
LockPrerequisites.getInstance().resetPrerequisite(lockKey);
-                       }
+            synchronized (this) {
+                removeLock(lockKey, lockID);
+                LockPrerequisites.getInstance().resetPrerequisite(lockKey);
+            }
         }
     }
 =

@@ -287,7 +287,7 @@
      * @param lockKey The lock key identifying the lock.
      * @return True if the lock has already been acquired, false otherwise.
      */
-    public synchronized boolean isAlreadyAcquired (final LockKey lockKey) {
+    public boolean isAlreadyAcquired (final LockKey lockKey) {
         List locks =3D getLocks(lockKey);
         if (locks.isEmpty()) {
             return false; // By =C3=82=C2=A7convention
@@ -317,7 +317,7 @@
      * @param lockID The lock identifier.
          * @return True if the lock has been stolen in the context, false =
otherwise.
      */
-    public synchronized boolean isStealedInContext (final LockKey lockKey,
+    public boolean isStealedInContext (final LockKey lockKey,
                                                     final JahiaUser owner,
                                                     final String lockID) {
         return (isStealed(lockKey, lockID));
@@ -332,7 +332,7 @@
      * @return True if the lock has been already acquired in the context,
      * false otherwise.
      */
-    public synchronized boolean isAlreadyAcquiredInContext (final LockKey =
lockKey,
+    public boolean isAlreadyAcquiredInContext (final LockKey lockKey,
                                                             final JahiaUse=
r owner,
                                                             final String l=
ockID) {
         Lock lock =3D getLock(lockKey, lockID);
@@ -351,7 +351,7 @@
         return lock.getOwner().getUserKey().equals(owner.getUserKey()) && =
lock.getID().equals(lockID);
     }
 =

-    public synchronized Set getContexts(final LockKey lockKey) {
+    public Set getContexts(final LockKey lockKey) {
         Map allLocks =3D (Map) lockAlreadyAcquiredMap.get(lockKey.getObjec=
tKey());
 =

         if (allLocks =3D=3D null) {
@@ -406,10 +406,10 @@
             return true; // By convention
         }
         if (lock.hasExpired()) {
-               synchronized (this) {
-                               removeLock(lockKey, lockID);
-                               
LockPrerequisites.getInstance().resetPrerequisite(lockKey);
-                       }
+            synchronized (this) {
+                removeLock(lockKey, lockID);
+                LockPrerequisites.getInstance().resetPrerequisite(lockKey);
+            }
             return true;
         }
 =

@@ -423,7 +423,7 @@
      * @param owner The lock owner.
      * @return True if the user has admin rights, false otherwise.
      */
-    public synchronized boolean hasAdminRights (final LockKey lockKey,
+    public boolean hasAdminRights (final LockKey lockKey,
                                                 final JahiaUser owner) {
         if (lockKey =3D=3D null) return false;
         ObjectKey objectKey =3D lockKey.getObjectKey();

Modified: branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/services/sit=
es/JahiaSitesBaseService.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/branches/JAHIA-5-0-SP=
-BRANCH/core/src/java/org/jahia/services/sites/JahiaSitesBaseService.java&r=
ev=3D18272&repname=3Djahia
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/services/sites/Jah=
iaSitesBaseService.java (original)
+++ branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/services/sites/Jah=
iaSitesBaseService.java Mon Aug 27 12:29:56 2007
@@ -184,26 +184,28 @@
      * @return JahiaSite the JahiaSite bean
      */
     public JahiaSite getSite(int id) throws JahiaException {
-               JahiaSite site =3D (JahiaSite) siteCacheByID.get(new 
Integer(id));
-               if (site !=3D null) {
-                       return site;
-               }
-               // try to load from db
-
-               site =3D siteManager.getSiteById(id);
-               // if the site could be loaded, add it into the cache
-               if (site !=3D null) {
-                       addToCache(site);
-               }
-
-               return site;
-       }
-
-
-    private synchronized void addToCache (JahiaSite site) {
-               siteCacheByID.put(new Integer(site.getID()), site);
-               siteCacheByName.put(site.getServerName(), site);
-               siteCacheByKey.put(site.getSiteKey(), site);            =

+        JahiaSite site =3D (JahiaSite) siteCacheByID.get(new Integer(id));
+        if (site !=3D null) {
+            return site;
+        }
+        // try to load from db
+
+        site =3D siteManager.getSiteById(id);
+        // if the site could be loaded, add it into the cache
+        if (site !=3D null) {
+            addToCache(site);
+        }
+
+        return site;
+    }
+
+
+    private synchronized void addToCache(JahiaSite site) {
+        siteCacheByID.put(new Integer(site.getID()), site);
+        if (site.getServerName() !=3D null) {
+            siteCacheByName.put(site.getServerName(), site);
+        }
+        siteCacheByKey.put(site.getSiteKey(), site);
     }
     =

     /**
@@ -215,20 +217,20 @@
         * @return JahiaSite the JahiaSite bean
         */
     public JahiaSite getSiteByKey(String siteKey) throws JahiaException {
-               if (siteKey =3D=3D null) {
-                       return null;
-               }
-               JahiaSite site =3D (JahiaSite) siteCacheByKey.get(siteKey);
-               if (site !=3D null)
-                       return site;
-               site =3D siteManager.getSiteByKey(siteKey);
-               // if the site could be loaded from the database, add it into 
the cache.
-               if (site !=3D null) {
-                       addToCache(site);
-               }
+        if (siteKey =3D=3D null) {
+            return null;
+        }
+        JahiaSite site =3D (JahiaSite) siteCacheByKey.get(siteKey);
+        if (site !=3D null)
+            return site;
+        site =3D siteManager.getSiteByKey(siteKey);
+        // if the site could be loaded from the database, add it into the =
cache.
+        if (site !=3D null) {
+            addToCache(site);
+        }
 =

-               return site;
-       }
+        return site;
+    }
 =

     /**
         * Find a site by it's server name value
@@ -244,26 +246,26 @@
         *             database.
         */
     public JahiaSite getSiteByServerName(String serverName)
-                       throws JahiaException {
-               if (serverName =3D=3D null) {
-                       return null;
-               }
-               JahiaSite site =3D (JahiaSite) siteCacheByName.get(serverName);
-
-               if (site !=3D null) {
-                       return site;
-               }
-
-               // the site was not found in the cache, try to load it from the
-               // database.
-               site =3D siteManager.getSiteByName(serverName);
-               // if the site could be loaded from the database, add it into 
the cache.
-               if (site !=3D null) {
-                       addToCache(site);
-               }
+            throws JahiaException {
+        if (serverName =3D=3D null) {
+            return null;
+        }
+        JahiaSite site =3D (JahiaSite) siteCacheByName.get(serverName);
 =

-               return site;
-       }
+        if (site !=3D null) {
+            return site;
+        }
+
+        // the site was not found in the cache, try to load it from the
+        // database.
+        site =3D siteManager.getSiteByName(serverName);
+        // if the site could be loaded from the database, add it into the =
cache.
+        if (site !=3D null) {
+            addToCache(site);
+        }
+
+        return site;
+    }
 =

 =

     // -------------------------------------------------------------------=
-------
@@ -276,23 +278,23 @@
      * @return JahiaSite the JahiaSite bean or null
      */
     public JahiaSite getSite(String name) throws JahiaException {
-               if (name =3D=3D null) {
-                       return null;
-               }
-               JahiaSite site =3D (JahiaSite) siteCacheByName.get(name);
-
-               if (site !=3D null) {
-                       return site;
-               }
-
-               // try to load the site from the database.
-               site =3D siteManager.getSiteByName(name);
-               if (site !=3D null) {
-                       addToCache(site);
-               }
+        if (name =3D=3D null) {
+            return null;
+        }
+        JahiaSite site =3D (JahiaSite) siteCacheByName.get(name);
 =

-               return site;
-       }
+        if (site !=3D null) {
+            return site;
+        }
+
+        // try to load the site from the database.
+        site =3D siteManager.getSiteByName(name);
+        if (site !=3D null) {
+            addToCache(site);
+        }
+
+        return site;
+    }
 =

 =

     // -------------------------------------------------------------------=
-------
@@ -322,11 +324,7 @@
                 return false;
             }
 =

-            siteCacheByID.put (new Integer (site.getID ()), site);
-            siteCacheByKey.put(site.getSiteKey(),site);
-            if (site.getServerName() !=3D null) {
-                siteCacheByName.put(site.getServerName(), site);
-            }
+            addToCache(site);
 =

             ServicesRegistry.getInstance().getJahiaSearchService()
                     .createSearchHandler(site.getID());
@@ -368,10 +366,8 @@
             siteManager.setDefaultSite(site);
         }
         sitePropertyManager.save(site);
-        siteCacheByID.put (new Integer (site.getID ()), site);
         siteCacheByName.flush();
-        siteCacheByName.put(site.getServerName(), site);
-        siteCacheByKey.put(site.getSiteKey(),site);
+        addToCache(site);
     }
 =

     public synchronized void removeSiteProperties (JahiaSite site,List pro=
pertiesToBeRemoved) throws JahiaException {
@@ -391,9 +387,7 @@
                 JahiaSite site =3D (JahiaSite) sites.get (i);
                 // start and create the site's new templates folder if not=
 exists
                 JahiaSiteTools.startTemplateObserver (site, settingsBean, =
templateDeployerService, fileWatcherService);
-                siteCacheByID.put (new Integer (site.getID ()), site);
-                siteCacheByName.put(site.getServerName(), site);
-                siteCacheByKey.put(site.getSiteKey(),site);
+                addToCache(site);
             }
         }
     }

_______________________________________________
cvs_list mailing list
[email protected]
http://lists.jahia.org/cgi-bin/mailman/listinfo/cvs_list

Reply via email to