[exo-jcr-commits] exo-jcr SVN: r514 - in jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl: storage/jbosscache and 1 other directory.
do-not-reply at jboss.org
do-not-reply at jboss.org
Mon Nov 9 09:38:12 EST 2009
Author: tolusha
Date: 2009-11-09 09:38:12 -0500 (Mon, 09 Nov 2009)
New Revision: 514
Modified:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/LockManagerImpl.java
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorage.java
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/LockCacheLoader.java
Log:
EXOJCR-205: refactoring LockCacheLoader
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/LockManagerImpl.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/LockManagerImpl.java 2009-11-09 14:29:33 UTC (rev 513)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/LockManagerImpl.java 2009-11-09 14:38:12 UTC (rev 514)
@@ -814,4 +814,12 @@
{
return pendingLocks.containsKey(nodeIdentifier);
}
+
+ /**
+ * TODO: Added. Need for LockCacheLoader..
+ */
+ public boolean hasLockNode(String nodeIdentifier)
+ {
+ return locks.containsKey(nodeIdentifier);
+ }
}
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorage.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorage.java 2009-11-09 14:29:33 UTC (rev 513)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorage.java 2009-11-09 14:38:12 UTC (rev 514)
@@ -16,24 +16,6 @@
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
-/*
- * Copyright (C) 2009 eXo Platform SAS.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
package org.exoplatform.services.jcr.impl.storage.jbosscache;
import org.exoplatform.services.jcr.datamodel.QPath;
@@ -54,31 +36,33 @@
public abstract class JBossCacheStorage
{
+ public static final String SESSION = "$SESSION".intern();
+
public static final String NODES = "$NODES".intern();
-
+
public static final String PROPS = "$PROPS".intern();
-
+
public static final String OBSERVATION = "$OBSERVATION".intern();
public static final String ITEM_DATA = "$data".intern();
public static final String ITEM_ID = "$id".intern();
-
+
public static final String SESSION_ID = "$sessionId".intern();
-
+
public static final String USER_ID = "$userId".intern();
protected final Node<Serializable, Object> nodesRoot;
-
+
protected final Node<Serializable, Object> propsRoot;
protected JBossCacheStorage(Node<Serializable, Object> nodesRoot, Node<Serializable, Object> propsRoot)
{
this.nodesRoot = nodesRoot;
-
+
this.propsRoot = propsRoot;
}
-
+
/**
* Make Child Node relative Fqn, i.e. ./NIDxxx/NAMExxx.
*
@@ -92,7 +76,7 @@
//return Fqn.fromRelativeFqn(nodesRoot.getFqn(), Fqn.fromElements(parentId, nodeName.getAsString(true)));
return Fqn.fromElements(parentId, nodeName.getAsString(true));
}
-
+
/**
* Make Child Node relative Fqn. i.e. ./NAMExxx.
*
@@ -104,8 +88,6 @@
return Fqn.fromElements(nodeName.getAsString(true));
}
-
-
/**
* Make Node relative Fqn, i.e. ./NIDxxx.
*
@@ -129,5 +111,5 @@
//return Fqn.fromRelativeFqn(propsRoot, Fqn.fromElements(propId));
return Fqn.fromElements(propId);
}
-
+
}
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/LockCacheLoader.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/LockCacheLoader.java 2009-11-09 14:29:33 UTC (rev 513)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/LockCacheLoader.java 2009-11-09 14:38:12 UTC (rev 514)
@@ -16,8 +16,6 @@
*/
package org.exoplatform.services.jcr.impl.storage.jbosscache;
-import org.exoplatform.services.jcr.dataflow.ItemState;
-import org.exoplatform.services.jcr.dataflow.PlainChangesLog;
import org.exoplatform.services.jcr.datamodel.InternalQName;
import org.exoplatform.services.jcr.datamodel.PropertyData;
import org.exoplatform.services.jcr.impl.Constants;
@@ -27,10 +25,14 @@
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
import org.jboss.cache.CacheException;
+import org.jboss.cache.Fqn;
import org.jboss.cache.Modification;
import org.jboss.cache.Modification.ModificationType;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.List;
import javax.jcr.lock.LockException;
@@ -62,17 +64,76 @@
@Override
public void put(List<Modification> modifications) throws Exception
{
+ String sessionId = null;
+ HashSet<String> removedLock = new HashSet<String>();
List<Modification> lockChanges = new ArrayList<Modification>();
for (Modification m : modifications)
{
- if (m.getFqn().hasElement(JBossCacheStorage.PROPS))
+ if (m.getFqn().hasElement(JBossCacheStorage.SESSION))
{
switch (m.getType())
{
+ case PUT_DATA_ERASE :
+ break;
case PUT_DATA :
+ // changesLog begin
+ int pos = getElementPosition(m.getFqn(), JBossCacheStorage.SESSION);
+ sessionId = (String)m.getFqn().get(pos + 1);
break;
+ case PUT_KEY_VALUE :
+ break;
+ case REMOVE_DATA :
+ break;
+ case REMOVE_KEY_VALUE :
+ break;
+ case REMOVE_NODE :
+ // perform lock or unlock operation
+ if (lockChanges.size() == 2)
+ {
+ if (lockChanges.get(0).getType() == ModificationType.PUT_KEY_VALUE
+ && lockChanges.get(1).getType() == ModificationType.PUT_KEY_VALUE)
+ {
+ performLock(lockChanges, sessionId);
+ }
+ else if (lockChanges.get(0).getType() == ModificationType.REMOVE_KEY_VALUE
+ && lockChanges.get(1).getType() == ModificationType.REMOVE_KEY_VALUE)
+ {
+ performUnLock(lockChanges, sessionId);
+ }
+ else
+ {
+ log.error("Incorrect changes log contains lock and unlock operation simultaneously");
+ }
+ }
+ else if (lockChanges.size() != 0)
+ {
+ log.error("Incorrect changes log size for lock or unlock operation");
+ }
+ // changesLog end
+ for (String identifier : removedLock)
+ {
+ lockManager.internalUnLock(sessionId, identifier);
+ }
+
+ lockChanges = new ArrayList<Modification>();
+ sessionId = null;
+ break;
+ case MOVE :
+ break;
+ default :
+ throw new CacheException("Unknown modification " + m.getType());
+ }
+ }
+ else if (m.getFqn().hasElement(JBossCacheStorage.PROPS))
+ {
+ switch (m.getType())
+ {
+ case PUT_DATA_ERASE :
+ break;
+ case PUT_DATA :
+ break;
case PUT_KEY_VALUE :
if (m.getKey().equals(JBossCacheStorage.ITEM_DATA))
{
@@ -85,56 +146,63 @@
}
}
break;
-
case REMOVE_DATA :
break;
-
case REMOVE_KEY_VALUE :
- PropertyData propertyData = (PropertyData)m.getValue();
- InternalQName propertyName = propertyData.getQPath().getName();
+ if (m.getKey().equals(JBossCacheStorage.ITEM_DATA))
+ {
+ PropertyData propertyData = (PropertyData)m.getValue();
+ InternalQName propertyName = propertyData.getQPath().getName();
- if (propertyName.equals(Constants.JCR_LOCKISDEEP) || propertyName.equals(Constants.JCR_LOCKOWNER))
- {
- lockChanges.add(m);
+ if (propertyName.equals(Constants.JCR_LOCKISDEEP) || propertyName.equals(Constants.JCR_LOCKOWNER))
+ {
+ lockChanges.add(m);
+ }
}
break;
-
case REMOVE_NODE :
break;
-
case MOVE :
break;
-
default :
throw new CacheException("Unknown modification " + m.getType());
}
}
-
- if (lockChanges.size() == 2)
+ else if (m.getFqn().hasElement(JBossCacheStorage.NODES))
{
- if (lockChanges.get(0).getType() == ModificationType.PUT_KEY_VALUE
- && lockChanges.get(1).getType() == ModificationType.PUT_KEY_VALUE)
+ int nodesPos = getElementPosition(m.getFqn(), JBossCacheStorage.NODES);
+ if (m.getFqn().size() == nodesPos + 1)
{
- performLock(lockChanges);
+ // this is a node and node is locked
+ String nodeIdentifier = (String)m.getFqn().get(nodesPos + 1);
+ if (lockManager.hasLockNode(nodeIdentifier))
+ {
+ switch (m.getType())
+ {
+ case PUT_DATA_ERASE :
+ break;
+ case PUT_DATA :
+ removedLock.remove(nodeIdentifier);
+ break;
+ case PUT_KEY_VALUE :
+ break;
+ case REMOVE_DATA :
+ break;
+ case REMOVE_KEY_VALUE :
+ break;
+ case REMOVE_NODE :
+ removedLock.add(nodeIdentifier);
+ break;
+ case MOVE :
+ removedLock.remove(nodeIdentifier);
+ break;
+ default :
+ throw new CacheException("Unknown modification " + m.getType());
+ }
+ }
}
- else if (lockChanges.get(0).getType() == ModificationType.REMOVE_KEY_VALUE
- && lockChanges.get(1).getType() == ModificationType.REMOVE_KEY_VALUE)
- {
- performUnLock(lockChanges);
- }
- else
- {
-
- }
}
-
- lockChanges = new ArrayList<Modification>();
}
-
- if (lockChanges.size() != 0)
- {
- log.error("Incorrect changes log size for lock or unlock operation");
- }
}
/**
@@ -143,45 +211,70 @@
* @param lockChanges
* @throws LockException
*/
- private void performLock(List<Modification> lockChanges) throws Exception
+ private void performLock(List<Modification> lockChanges, String sessionId)
{
String nodeIdentifier = ((PropertyData)lockChanges.get(0).getValue()).getParentIdentifier();
- if (lockManager.hasPendingLocks(nodeIdentifier))
+ try
{
- lockManager.internalLock(nodeIdentifier);
- }
- else
- {
- log.warn("No lock in pendingLocks for identifier " + nodeIdentifier + " Probably lock come from replication.");
+ if (lockManager.hasPendingLocks(nodeIdentifier))
+ {
+ lockManager.internalLock(nodeIdentifier);
+ }
+ else
+ {
+ log.warn("No lock in pendingLocks for identifier " + nodeIdentifier
+ + " Probably lock come from replication.");
- String lockToken = IdGenerator.generate();
- Modification ownerModification = getModification(lockChanges, Constants.JCR_LOCKOWNER);
- Modification isDeepModification = getModification(lockChanges, Constants.JCR_LOCKISDEEP);
+ String lockToken = IdGenerator.generate();
+ Modification ownerModification = getModification(lockChanges, Constants.JCR_LOCKOWNER);
+ Modification isDeepModification = getModification(lockChanges, Constants.JCR_LOCKISDEEP);
- if (ownerModification != null && isDeepModification != null)
- {
+ if (ownerModification != null && isDeepModification != null)
+ {
- String owner =
- new String(((((TransientPropertyData)(ownerModification.getValue())).getValues()).get(0))
- .getAsByteArray(), Constants.DEFAULT_ENCODING);
+ String owner =
+ new String(((((TransientPropertyData)(ownerModification.getValue())).getValues()).get(0))
+ .getAsByteArray(), Constants.DEFAULT_ENCODING);
- boolean isDeep =
- Boolean.valueOf(
- new String(((((TransientPropertyData)(isDeepModification.getValue())).getValues()).get(0))
- .getAsByteArray(), Constants.DEFAULT_ENCODING)).booleanValue();
+ boolean isDeep =
+ Boolean.valueOf(
+ new String(((((TransientPropertyData)(isDeepModification.getValue())).getValues()).get(0))
+ .getAsByteArray(), Constants.DEFAULT_ENCODING)).booleanValue();
- // TODO sessionId
- lockManager.createRemoteLock("sessionId", nodeIdentifier, lockToken, isDeep, false, owner);
+ lockManager.createRemoteLock(sessionId, nodeIdentifier, lockToken, isDeep, false, owner);
+ }
}
}
+ catch (LockException e)
+ {
+ log.error(e.getLocalizedMessage(), e);
+ }
+ catch (UnsupportedEncodingException e)
+ {
+ log.error(e.getLocalizedMessage(), e);
+ }
+ catch (IllegalStateException e)
+ {
+ log.error(e.getLocalizedMessage(), e);
+ }
+ catch (IOException e)
+ {
+ log.error(e.getLocalizedMessage(), e);
+ }
}
- private void performUnLock(List<Modification> lockChanges) throws Exception
+ private void performUnLock(List<Modification> lockChanges, String sessionId)
{
- // TODO sessionId
- // TODO nodeIdentifier
- lockManager.internalUnLock("sessionId", "nodeIdentifier");
+ // TODO parent nodeIdentifier
+ try
+ {
+ lockManager.internalUnLock(sessionId, "nodeIdentifier");
+ }
+ catch (LockException e)
+ {
+ log.error(e.getLocalizedMessage(), e);
+ }
}
/**
@@ -201,4 +294,13 @@
return null;
}
+ private int getElementPosition(Fqn<String> fqn, String element)
+ {
+ for (int i = 0; i < fqn.size(); i++)
+ if (fqn.get(i).equals(element))
+ return i;
+
+ return -1;
+ }
+
}
More information about the exo-jcr-commits
mailing list