Author: bpapez
Date: Thu Aug 30 16:52:02 2007
New Revision: 18316

URL: https://svndev.jahia.net/websvn/listing.php?sc=3D1&rev=3D18316&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/MyPortal/pid/73?=
entryId=3D306)

Modified:
    trunk/core/src/java/org/jahia/registries/JahiaContainerDefinitionsRegis=
try.java
    trunk/core/src/java/org/jahia/registries/JahiaFieldDefinitionsRegistry.=
java
    trunk/core/src/java/org/jahia/services/acl/JahiaACLManagerService.java
    trunk/core/src/java/org/jahia/services/containers/ContainerFactory.java
    trunk/core/src/java/org/jahia/services/fields/JahiaFieldBaseService.java
    trunk/core/src/java/org/jahia/services/lock/LockPrerequisites.java
    trunk/core/src/java/org/jahia/services/lock/LockRegistry.java
    trunk/core/src/java/org/jahia/services/sites/JahiaSitesBaseService.java

Modified: trunk/core/src/java/org/jahia/registries/JahiaContainerDefinition=
sRegistry.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/trunk/core/src/java/o=
rg/jahia/registries/JahiaContainerDefinitionsRegistry.java&rev=3D18316&repn=
ame=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
--- trunk/core/src/java/org/jahia/registries/JahiaContainerDefinitionsRegis=
try.java (original)
+++ trunk/core/src/java/org/jahia/registries/JahiaContainerDefinitionsRegis=
try.java Thu Aug 30 16:52:02 2007
@@ -102,7 +102,7 @@
      * calls load_container_definitions in JahaiContainersDBService
      *
      */
-    private synchronized void loadAllDefinitions ()
+    private void loadAllDefinitions ()
         throws JahiaException {
         Vector defIDs =3D containersService.getAllContainerDefinitionIDs();
 =

@@ -210,36 +210,17 @@
      * @see          org.jahia.data.containers.JahiaContainerDefinition
      *
      */
-    public synchronized void setDefinition (JahiaContainerDefinition
+    public void setDefinition (JahiaContainerDefinition
                                             theContainerDef)
         throws JahiaException {
-        JahiaContainerDefinition aContainerDef;
-        aContainerDef =3D getDefinition(theContainerDef.getJahiaID(),
-                                      theContainerDef.getName());
-        if (aContainerDef !=3D null) {
-            // container definition already exists, just have to update
-            containersService.saveContainerDefinition(theContainerDef);
-        } else {
-            // container definition doesn't exist, need to add to registry
-            containersService.saveContainerDefinition(theContainerDef);
-//            containerDefByID.remove(new Integer(theContainerDef.getID())=
);
-//            containerDefBySiteIDAndName.remove(buildCacheKey(theContaine=
rDef.
-//                getName(),
-//                theContainerDef.getJahiaID()));
-        }
+        containersService.saveContainerDefinition(theContainerDef);
     } // end setDefinition
 =

     /***
      * remove a Container Definition
      */
-    public synchronized void removeContainerDefinition (int ctnDefID)
+    public void removeContainerDefinition (int ctnDefID)
         throws JahiaException {
-        JahiaContainerDefinition currentDef =3D getDefinition(ctnDefID);
-        if (currentDef !=3D null) {
-//            containerDefByID.remove(new Integer(ctnDefID));
-//            containerDefBySiteIDAndName.remove(buildCacheKey(currentDef.=
getName(),
-//                currentDef.getJahiaID()));
-        }
     } // end removeContainerDefinition
 =

     private String buildCacheKey (String containerDefinitionName, int site=
ID) {

Modified: trunk/core/src/java/org/jahia/registries/JahiaFieldDefinitionsReg=
istry.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/trunk/core/src/java/o=
rg/jahia/registries/JahiaFieldDefinitionsRegistry.java&rev=3D18316&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
--- trunk/core/src/java/org/jahia/registries/JahiaFieldDefinitionsRegistry.=
java (original)
+++ trunk/core/src/java/org/jahia/registries/JahiaFieldDefinitionsRegistry.=
java Thu Aug 30 16:52:02 2007
@@ -97,10 +97,8 @@
             Integer currentID =3D ( (Integer) fieldDefIDEnum.next());
             JahiaFieldDefinition curDefinition =3D fieldService.loadFieldD=
efinition(currentID.
                 intValue());
-            fieldDefTable.put(currentID, curDefinition);
             if (curDefinition !=3D null) {
-                fieldDefSiteAndNameTable.put(buildCacheKey(curDefinition.g=
etName(),
-                        curDefinition.getJahiaID()), curDefinition);
+                addToCache(curDefinition);
             }
         }
     }
@@ -109,9 +107,7 @@
         throws JahiaException {
         JahiaFieldDefinition curDefinition =3D fieldService.loadFieldDefin=
ition(defID);
         if (curDefinition !=3D null) {
-            fieldDefTable.put(new Integer(defID), curDefinition);
-            fieldDefSiteAndNameTable.put(buildCacheKey(curDefinition.getNa=
me(),
-                curDefinition.getJahiaID()), curDefinition);
+            addToCache(curDefinition);
         }
         return curDefinition;
     }
@@ -120,21 +116,23 @@
         throws JahiaException {
         JahiaFieldDefinition curDefinition =3D fieldService.loadFieldDefin=
ition(siteID, definitionName);
         if (curDefinition !=3D null) {
-            fieldDefTable.put(new Integer(curDefinition.getID()), curDefin=
ition);
-            fieldDefSiteAndNameTable.put(buildCacheKey(curDefinition.getNa=
me(),
-                curDefinition.getJahiaID()), curDefinition);
+            addToCache(curDefinition);
         }
         return curDefinition;
     }
+    =

+    private synchronized void addToCache(JahiaFieldDefinition curDefinitio=
n) {
+        fieldDefTable.put(new Integer(curDefinition.getID()), curDefinitio=
n);
+        fieldDefSiteAndNameTable.put(buildCacheKey(curDefinition.getName(),
+            curDefinition.getJahiaID()), curDefinition);
+    }     =

 =

     public JahiaFieldDefinition getDefinition (int defID)
         throws JahiaException {
         JahiaFieldDefinition result =3D (JahiaFieldDefinition) fieldDefTab=
le.get(new
             Integer(defID));
         if (result =3D=3D null) {
-            synchronized(this) {
-                result =3D loadDefinitionByID(defID);
-            }
+            result =3D loadDefinitionByID(defID);
         }
 =

         if (result !=3D null) {
@@ -187,40 +185,33 @@
         return result;
     } // end getDefinition
 =

-    public synchronized void setDefinition (JahiaFieldDefinition theFieldD=
ef)
+    public void setDefinition (JahiaFieldDefinition theFieldDef)
         throws JahiaException {
 =

         JahiaFieldDefinition aFieldDef =3D getDefinition(theFieldDef.getJa=
hiaID(),
             theFieldDef.getName());
         if (aFieldDef !=3D null) {
             // field definition already exists, just have to update
-
             // We ensure to perform an update
             theFieldDef.setID(aFieldDef.getID());
-            fieldService.saveFieldDefinition(theFieldDef);
-            fieldDefTable.put(new Integer(theFieldDef.getID()), theFieldDe=
f);
-            fieldDefSiteAndNameTable.put(buildCacheKey(theFieldDef.getName=
(),
-                theFieldDef.getJahiaID()), theFieldDef);
         } else {
             // field definition doesn't exist, need to add to registry
-
             //We ensure to create a new one
             theFieldDef.setID(0);
-
-            fieldService.saveFieldDefinition(theFieldDef);
-            fieldDefTable.put(new Integer(theFieldDef.getID()), theFieldDe=
f);
-            fieldDefSiteAndNameTable.put(buildCacheKey(theFieldDef.getName=
(),
-                theFieldDef.getJahiaID()), theFieldDef);
         }
+        fieldService.saveFieldDefinition(theFieldDef);
+        addToCache(theFieldDef);                =

     } // end setDefinition
 =

-    public synchronized void removeFieldDefinition (int fieldDefID)
+    public void removeFieldDefinition (int fieldDefID)
         throws JahiaException {
         JahiaFieldDefinition fieldDef =3D getDefinition(fieldDefID);
         if (fieldDef !=3D null) {
-            fieldDefTable.remove(new Integer(fieldDefID));
-            fieldDefSiteAndNameTable.remove(buildCacheKey(fieldDef.getName=
(),
-                fieldDef.getJahiaID()));
+            synchronized (this) {
+                fieldDefTable.remove(new Integer(fieldDefID));
+                fieldDefSiteAndNameTable.remove(buildCacheKey(fieldDef
+                        .getName(), fieldDef.getJahiaID()));
+            }
         }
 =

     } // end setDefinition
@@ -247,10 +238,7 @@
         }
 =

         try {
-            synchronized(this) {
-                loadAllDefinitions();
-            }
-
+            loadAllDefinitions();
         } catch (JahiaException e) {
             logger.warn("Could not reload the Field Definitions.", e);
         }

Modified: trunk/core/src/java/org/jahia/services/acl/JahiaACLManagerService=
.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/trunk/core/src/java/o=
rg/jahia/services/acl/JahiaACLManagerService.java&rev=3D18316&repname=3Djah=
ia
=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
--- trunk/core/src/java/org/jahia/services/acl/JahiaACLManagerService.java =
(original)
+++ trunk/core/src/java/org/jahia/services/acl/JahiaACLManagerService.java =
Thu Aug 30 16:52:02 2007
@@ -276,13 +276,15 @@
      * @throws JahiaException thrown if there was an error while loading A=
CLs
      *                        from the database.
      */
-    public synchronized void preloadContainerACLsByPage(int pageID)
+    public void preloadContainerACLsByPage(int pageID)
             throws JahiaException {
         if (!mPreloadedContainerACLsByPageCache
                 .containsKey(String.valueOf(pageID))) {
-            manager.preloadACLs(mACLCache);
-            this.mPreloadedContainerACLsByPageCache.put(String.valueOf(pag=
eID),
-                                                        String.valueOf(pag=
eID));
+            synchronized (this) {
+                manager.preloadACLs(mACLCache);
+                this.mPreloadedContainerACLsByPageCache.put(String
+                        .valueOf(pageID), String.valueOf(pageID));
+            }
         }
     }
 =

@@ -294,13 +296,15 @@
      * @throws JahiaException thrown if there was an error while loading A=
CLs
      *                        from the database.
      */
-    public synchronized void preloadFieldACLsByPage(int pageID)
+    public void preloadFieldACLsByPage(int pageID)
             throws JahiaException {
         if (!mPreloadedFieldACLsByPageCache
                 .containsKey(String.valueOf(pageID))) {
-            manager.preloadACLs(mACLCache);
-            this.mPreloadedFieldACLsByPageCache.put(String.valueOf(pageID),
-                                                    String.valueOf(pageID)=
);
+            synchronized (this) {
+                manager.preloadACLs(mACLCache);
+                this.mPreloadedFieldACLsByPageCache.put(String.valueOf(pag=
eID),
+                        String.valueOf(pageID));
+            }
         }
     }
 =


Modified: trunk/core/src/java/org/jahia/services/containers/ContainerFactor=
y.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/trunk/core/src/java/o=
rg/jahia/services/containers/ContainerFactory.java&rev=3D18316&repname=3Dja=
hia
=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
--- trunk/core/src/java/org/jahia/services/containers/ContainerFactory.java=
 (original)
+++ trunk/core/src/java/org/jahia/services/containers/ContainerFactory.java=
 Thu Aug 30 16:52:02 2007
@@ -105,63 +105,50 @@
         }
 =

         if (!container.isFieldsLoaded()) {
-            container.clearFields();
-            container.setFieldsLoaded(true);
-            // not already in fullyLoadedList -> load it
-            final List fieldIDs =3D ServicesRegistry.getInstance().getJahi=
aContainersService().
-                    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()) {
-            container.clearContainerLists();
-            container.setContainerListsLoaded(true);
-            final JahiaContainersService ctnServ =3D ServicesRegistry.getI=
nstance().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.getSubContainerLis=
tIDs(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.loadContainerLi=
st(listID.intValue(),
-                        loadFlag, jParams, loadRequest, cachedFieldsFromCo=
ntainers,
-                        cachedContainersFromContainerLists, cachedContaine=
rListsFromContainers);
+            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 ().getJahiaCo=
ntainersService ()
-                                .loadContainerList (cList.getID (), ctnids=
, loadFlag,
-                                        jParams, loadRequest, cachedFields=
FromContainers,
-                                        cachedContainersFromContainerLists=
);
-                    } else {
-                        cList =3D
-                                ServicesRegistry.getInstance ().getJahiaCo=
ntainersService ()
-                                .loadContainerList (cList.getID (), loadFl=
ag,
-                                        jParams, loadRequest, cachedFields=
FromContainers,
-                                        cachedContainersFromContainerLists=
);
-                    }
-                    cList =3D
-                            fullyLoadContainerList (cList, loadFlag, jPara=
ms, loadRequest,
-                                    cachedFieldsFromContainers,
-                                    cachedContainersFromContainerLists,
-                                    cachedContainerListsFromContainers);
-                    */
-                    container.addContainerList(cList);
+                    if (cList !=3D null) {
+                        container.addContainerList(cList);
+                    }
                 }
             }
         }

Modified: trunk/core/src/java/org/jahia/services/fields/JahiaFieldBaseServi=
ce.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/trunk/core/src/java/o=
rg/jahia/services/fields/JahiaFieldBaseService.java&rev=3D18316&repname=3Dj=
ahia
=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
--- trunk/core/src/java/org/jahia/services/fields/JahiaFieldBaseService.jav=
a (original)
+++ trunk/core/src/java/org/jahia/services/fields/JahiaFieldBaseService.jav=
a Thu Aug 30 16:52:02 2007
@@ -1446,7 +1446,7 @@
      *
      * @see org.jahia.data.fields.JahiaFieldDefinition
      */
-    public synchronized void saveFieldDefinition (JahiaFieldDefinition the=
Def)
+    public void saveFieldDefinition (JahiaFieldDefinition theDef)
             throws JahiaException {
         definitionManager.saveFieldDefinition(theDef);
     } // saveFieldDefinition

Modified: trunk/core/src/java/org/jahia/services/lock/LockPrerequisites.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/trunk/core/src/java/o=
rg/jahia/services/lock/LockPrerequisites.java&rev=3D18316&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
--- trunk/core/src/java/org/jahia/services/lock/LockPrerequisites.java (ori=
ginal)
+++ trunk/core/src/java/org/jahia/services/lock/LockPrerequisites.java Thu =
Aug 30 16:52:02 2007
@@ -84,7 +84,7 @@
      *         disgracious ! So there would be better to put these lock ve=
rification
      *         sequences in separate classes; one for each test.
      */
-    public synchronized boolean isLockAcquirable(final LockKey lockKey,
+    public boolean isLockAcquirable(final LockKey lockKey,
                                                  final JahiaUser owner,
                                                  final String lockID,
                                                  final boolean justTesting=
) {
@@ -305,7 +305,7 @@
         return lockPrerequisites;
     }
 =

-    protected void resetPrerequisite(final LockKey lockKey) {
+    protected synchronized void resetPrerequisite(final LockKey lockKey) {
         lockPrerequisitesResultMap.remove(lockKey);
         lockAlreadyAcquiredMap.remove(lockKey.getObjectKey());
 //        lockAlreadyAcquiredMap.remove(new GroupCacheKey(lockKey, new Arr=
ayList()));

Modified: trunk/core/src/java/org/jahia/services/lock/LockRegistry.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/trunk/core/src/java/o=
rg/jahia/services/lock/LockRegistry.java&rev=3D18316&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
--- trunk/core/src/java/org/jahia/services/lock/LockRegistry.java (original)
+++ trunk/core/src/java/org/jahia/services/lock/LockRegistry.java Thu Aug 3=
0 16:52:02 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,18 +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)) {
-            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);
+            }
         }
     }
 =

@@ -248,12 +250,14 @@
      *
      * Sorry, should be called "break" but it is a reserved word ;)
      */
-    public synchronized void nuke (final LockKey lockKey,
+    public void nuke (final LockKey lockKey,
                                    final JahiaUser owner,
                                    final String lockID) {
         if (hasAdminRights(lockKey, owner)) {
-            removeLock(lockKey, lockID);
-            LockPrerequisites.getInstance().resetPrerequisite(lockKey);
+            synchronized (this) {
+                removeLock(lockKey, lockID);
+                LockPrerequisites.getInstance().resetPrerequisite(lockKey);
+            }
         }
     }
 =

@@ -279,7 +283,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
@@ -309,7 +313,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));
@@ -324,7 +328,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);
@@ -343,7 +347,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) {
@@ -390,7 +394,7 @@
      * @param lockID The lock identifier.
      * @return True if the lock can be released, false otherwise.
      */
-    public synchronized boolean canRelease (final LockKey lockKey,
+    public boolean canRelease (final LockKey lockKey,
                                             final JahiaUser owner,
                                             final String lockID) {
         Lock lock =3D getLock(lockKey, lockID);
@@ -398,8 +402,10 @@
             return true; // By convention
         }
         if (lock.hasExpired()) {
-            removeLock(lockKey, lockID);
-            LockPrerequisites.getInstance().resetPrerequisite(lockKey);
+            synchronized (this) {
+                removeLock(lockKey, lockID);
+                LockPrerequisites.getInstance().resetPrerequisite(lockKey);
+            }
             return true;
         }
 =

@@ -413,7 +419,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: trunk/core/src/java/org/jahia/services/sites/JahiaSitesBaseServic=
e.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/trunk/core/src/java/o=
rg/jahia/services/sites/JahiaSitesBaseService.java&rev=3D18316&repname=3Dja=
hia
=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
--- trunk/core/src/java/org/jahia/services/sites/JahiaSitesBaseService.java=
 (original)
+++ trunk/core/src/java/org/jahia/services/sites/JahiaSitesBaseService.java=
 Thu Aug 30 16:52:02 2007
@@ -183,24 +183,29 @@
      *
      * @return JahiaSite the JahiaSite bean
      */
-    public JahiaSite getSite (int id)
-            throws JahiaException {
-        JahiaSite site =3D (JahiaSite) siteCacheByID.get (new Integer (id)=
);
-        if (site!=3Dnull) {
+    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 JahiaSitesPersistance.getInstance ().dbGetSite (id);
-              site =3D siteManager.getSiteById(id);
-            // if the site could be loaded, add it into the cache
-            if (site !=3D null) {
-                siteCacheByID.put (new Integer (id), site);
-                siteCacheByName.put(site.getServerName(), site);
-                siteCacheByKey.put(site.getSiteKey(),site);
+        // try to load from db
+        // site =3D JahiaSitesPersistance.getInstance ().dbGetSite (id);
+        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);
+    }    =

 =

 =

     /**
@@ -210,20 +215,17 @@
      *
      * @return JahiaSite the JahiaSite bean
      */
-    public JahiaSite getSiteByKey (String siteKey)
-            throws JahiaException {
+    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;
+        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) {
-            siteCacheByID.put (new Integer (site.getID ()), site);
-            siteCacheByKey.put(site.getSiteKey(),site);
-            siteCacheByName.put(site.getServerName(), site);
+            addToCache(site);
         }
 =

         return site;
@@ -231,35 +233,34 @@
 =

     /**
      * Find a site by it's server name value
-     *
-     * @param serverName the server name to look for
-     *
-     * @return if found, returns the site with the corresponding serverNam=
e,
-     *         or the first one if there are multiple, or null if there ar=
e none.
-     *
-     * @throws JahiaException thrown if there was a problem communicating =
with
-     *                        the database.
+     * =

+     * @param serverName
+     *                the server name to look for
+     * =

+     * @return if found, returns the site with the corresponding serverNam=
e, or the first one if there are multiple, or null if there are
+     *         none.
+     * =

+     * @throws JahiaException
+     *                 thrown if there was a problem communicating with th=
e database.
      */
-    public JahiaSite getSiteByServerName (String serverName)
+    public JahiaSite getSiteByServerName(String serverName)
             throws JahiaException {
         if (serverName =3D=3D null) {
             return null;
         }
         JahiaSite site =3D (JahiaSite) siteCacheByName.get(serverName);
 =

-        if (site!=3Dnull) {
-                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 JahiaSitesPersistance.getInstance ().dbGetSiteByServerN=
ame (serverName);
-          site =3D siteManager.getSiteByName(serverName);
+        // site =3D JahiaSitesPersistance.getInstance ().dbGetSiteByServer=
Name (serverName);
+        site =3D siteManager.getSiteByName(serverName);
         // if the site could be loaded from the database, add it into the =
cache.
         if (site !=3D null) {
-            siteCacheByID.put(new Integer(site.getID()), site);
-            siteCacheByKey.put(site.getSiteKey(),site);
-            siteCacheByName.put(serverName, site);
+            addToCache(site);
         }
 =

         return site;
@@ -275,31 +276,28 @@
      *
      * @return JahiaSite the JahiaSite bean or null
      */
-    public JahiaSite getSite (String name)
-            throws JahiaException {
+    public JahiaSite getSite(String name) throws JahiaException {
         if (name =3D=3D null) {
             return null;
         }
         JahiaSite site =3D (JahiaSite) siteCacheByName.get(name);
 =

-        if (site!=3Dnull) {
-                return site;
-            }
+        if (site !=3D null) {
+            return site;
+        }
 =

         // try to load the site from the database.
-        //site =3D JahiaSitesPersistance.getInstance ().dbGetSite (name);
+        // site =3D JahiaSitesPersistance.getInstance ().dbGetSite (name);
         site =3D siteManager.getSiteByName(name);
         if (site !=3D null) {
-            siteCacheByID.put(new Integer(site.getID()), site);
-            siteCacheByKey.put(site.getSiteKey(),site);
-            siteCacheByName.put(name, site);
+            addToCache(site);
         }
 =

         return site;
     }
 =

 =

-    //--------------------------------------------------------------------=
------
+    // -------------------------------------------------------------------=
-------
     /**
      * Add a new site only if there is no other site with same server name
      *
@@ -325,11 +323,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());
@@ -371,10 +365,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 {
@@ -394,9 +386,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