exo-jcr SVN: r1465 - in jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent: jbosscache and 1 other directory.
by do-not-reply@jboss.org
Author: skabashnyuk
Date: 2010-01-18 09:40:17 -0500 (Mon, 18 Jan 2010)
New Revision: 1465
Modified:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CacheableWorkspaceDataManager.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCache.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java
Log:
EXOJCR-391 : put in cache on get now is out of scope of transaction
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CacheableWorkspaceDataManager.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CacheableWorkspaceDataManager.java 2010-01-18 14:24:35 UTC (rev 1464)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CacheableWorkspaceDataManager.java 2010-01-18 14:40:17 UTC (rev 1465)
@@ -309,79 +309,6 @@
}
}
- protected class CacheNodesInTransaction extends StorageTxIsolatedOperation
- {
- final List<NodeData> childs;
-
- final NodeData parent;
-
- CacheNodesInTransaction(NodeData parent, List<NodeData> childs)
- {
- this.parent = parent;
- this.childs = childs;
- }
-
- @Override
- protected void action() throws RepositoryException
- {
- cache.addChildNodes(parent, childs);
- }
- }
-
- protected class CachePropertiesInTransaction extends StorageTxIsolatedOperation
- {
- final List<PropertyData> childs;
-
- final NodeData parent;
-
- CachePropertiesInTransaction(NodeData parent, List<PropertyData> childs)
- {
- this.parent = parent;
- this.childs = childs;
- }
-
- @Override
- protected void action() throws RepositoryException
- {
- cache.addChildProperties(parent, childs);
- }
- }
-
- protected class CachePropertiesListInTransaction extends StorageTxIsolatedOperation
- {
- final List<PropertyData> childsList;
-
- final NodeData parent;
-
- CachePropertiesListInTransaction(NodeData parent, List<PropertyData> childsList)
- {
- this.parent = parent;
- this.childsList = childsList;
- }
-
- @Override
- protected void action() throws RepositoryException
- {
- cache.addChildPropertiesList(parent, childsList);
- }
- }
-
- protected class CacheItemInTransaction extends StorageTxIsolatedOperation
- {
- final ItemData item;
-
- CacheItemInTransaction(ItemData item)
- {
- this.item = item;
- }
-
- @Override
- protected void action() throws RepositoryException
- {
- cache.put(item);
- }
- }
-
/**
* CacheableWorkspaceDataManager constructor.
*
@@ -644,48 +571,7 @@
if (parentData != null)
{
- if (isTxAware())
{
- new CacheNodesInTransaction(parentData, childNodes).perform();
-
- // TODO
- // try
- // {
- // if (transactionManager.getStatus() == Status.STATUS_ACTIVE)
- // {
- // cache.addChildNodes(parentData, childNodes);
- // }
- // else
- // {
- // transactionManager.begin();
- // cache.beginTransaction();
- // cache.addChildNodes(parentData, childNodes);
- // cache.commitTransaction();
- // transactionManager.commit();
- // }
- // }
- // catch (RollbackException e)
- // {
- // // Indicate that the transaction has been rolled back rather than committed.
- // throw new RepositoryException(e);
- // }
- // catch (Exception e)
- // {
- // try
- // {
- // cache.rollbackTransaction();
- // transactionManager.rollback();
- // }
- // catch (Exception e1)
- // {
- // LOG.error("Rollback error ", e1);
- // }
- //
- // throw new RepositoryException(e);
- // }
- }
- else
- {
cache.addChildNodes(parentData, childNodes);
}
}
@@ -742,48 +628,7 @@
if (parentData != null)
{
- if (isTxAware())
{
- new CachePropertiesInTransaction(parentData, childProperties).perform();
-
- // TODO
- // try
- // {
- // if (transactionManager.getStatus() == Status.STATUS_ACTIVE)
- // {
- // cache.addChildProperties(parentData, childProperties);
- // }
- // else
- // {
- // transactionManager.begin();
- // cache.beginTransaction();
- // cache.addChildProperties(parentData, childProperties);
- // cache.commitTransaction();
- // transactionManager.commit();
- // }
- // }
- // catch (RollbackException e)
- // {
- // // Indicate that the transaction has been rolled back rather than committed.
- // throw new RepositoryException(e);
- // }
- // catch (Exception e)
- // {
- // try
- // {
- // cache.rollbackTransaction();
- // transactionManager.rollback();
- // }
- // catch (Exception e1)
- // {
- // LOG.error("Rollback error ", e1);
- // }
- //
- // throw new RepositoryException(e);
- // }
- }
- else
- {
cache.addChildProperties(parentData, childProperties);
}
}
@@ -812,48 +657,7 @@
ItemData data = super.getItemData(parentData, name);
if (data != null && cache.isEnabled())
{
- if (isTxAware())
{
- new CacheItemInTransaction(data).perform();
-
- // TODO
- // try
- // {
- // if (transactionManager.getStatus() == Status.STATUS_ACTIVE)
- // {
- // cache.put(data);
- // }
- // else
- // {
- // transactionManager.begin();
- // cache.beginTransaction();
- // cache.put(data);
- // cache.commitTransaction();
- // transactionManager.commit();
- // }
- // }
- // catch (RollbackException e)
- // {
- // // Indicate that the transaction has been rolled back rather than committed.
- // throw new RepositoryException(e);
- // }
- // catch (Exception e)
- // {
- // try
- // {
- // cache.rollbackTransaction();
- // transactionManager.rollback();
- // }
- // catch (Exception e1)
- // {
- // LOG.error("Rollback error ", e1);
- // }
- //
- // throw new RepositoryException(e);
- // }
- }
- else
- {
cache.put(data);
}
}
@@ -872,48 +676,7 @@
ItemData data = super.getItemData(identifier);
if (data != null && cache.isEnabled())
{
- if (isTxAware())
{
- new CacheItemInTransaction(data).perform();
-
- // TODO
- // try
- // {
- // if (transactionManager.getStatus() == Status.STATUS_ACTIVE)
- // {
- // cache.put(data);
- // }
- // else
- // {
- // transactionManager.begin();
- // cache.beginTransaction();
- // cache.put(data);
- // cache.commitTransaction();
- // transactionManager.commit();
- // }
- // }
- // catch (RollbackException e)
- // {
- // // Indicate that the transaction has been rolled back rather than committed.
- // throw new RepositoryException(e);
- // }
- // catch (Exception e)
- // {
- // try
- // {
- // cache.rollbackTransaction();
- // transactionManager.rollback();
- // }
- // catch (Exception e1)
- // {
- // LOG.error("Rollback error ", e1);
- // }
- //
- // throw new RepositoryException(e);
- // }
- }
- else
- {
cache.put(data);
}
}
@@ -960,47 +723,7 @@
if (parentData != null)
{
- if (isTxAware())
{
- new CachePropertiesListInTransaction(parentData, propertiesList).perform();
-
- // if (transactionManager.getStatus() == Status.STATUS_ACTIVE)
- // {
- // cache.addChildPropertiesList(parentData, propertiesList);
- // }
- // else
- // {
- // try
- // {
- // transactionManager.begin();
- // cache.beginTransaction();
- // cache.addChildPropertiesList(parentData, propertiesList);
- // cache.commitTransaction();
- // transactionManager.commit();
- // }
- // catch (RollbackException e)
- // {
- // // Indicate that the transaction has been rolled back rather than committed.
- // throw new RepositoryException(e);
- // }
- // catch (Exception e)
- // {
- // try
- // {
- // cache.rollbackTransaction();
- // transactionManager.rollback();
- // }
- // catch (Exception e1)
- // {
- // LOG.error("Rollback error ", e1);
- // }
- //
- // throw new RepositoryException(e);
- // }
- // }
- }
- else
- {
cache.addChildPropertiesList(parentData, propertiesList);
}
}
@@ -1141,4 +864,4 @@
// conn.close();
// }
// }
-}
+}
\ No newline at end of file
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCache.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCache.java 2010-01-18 14:24:35 UTC (rev 1464)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCache.java 2010-01-18 14:40:17 UTC (rev 1465)
@@ -59,7 +59,7 @@
private final Cache<Serializable, Object> parentCache;
private final ThreadLocal<CompressedChangesBuffer> changesList = new ThreadLocal<CompressedChangesBuffer>();
-
+
private ThreadLocal<Boolean> local = new ThreadLocal<Boolean>();
protected static final Log LOG =
@@ -76,11 +76,21 @@
*/
public void beginTransaction()
{
+
changesList.set(new CompressedChangesBuffer());
local.set(false);
}
/**
+ *
+ * @return status of the cache transaction
+ */
+ public boolean isTransactionActive()
+ {
+ return changesList.get() != null;
+ }
+
+ /**
* Sort changes and commit data to the cache.
*/
public void commitTransaction()
@@ -134,9 +144,18 @@
*/
public void setLocal(boolean local)
{
+ //start local transaction
+ if (local && changesList.get() == null)
+ {
+ beginTransaction();
+ }
+ if (!local && this.local.get())
+ {
+
+ }
this.local.set(local);
}
-
+
/* (non-Javadoc)
* @see org.jboss.cache.Cache#addCacheListener(java.lang.Object)
*/
@@ -402,7 +421,8 @@
public void put(Fqn fqn, Map<? extends Serializable, ? extends Object> data)
{
CompressedChangesBuffer changesContainer = getChangesBufferSafe();
- changesContainer.add(new PutObjectContainer(fqn, data, parentCache, changesContainer.getHistoryIndex(), local.get()));
+ changesContainer.add(new PutObjectContainer(fqn, data, parentCache, changesContainer.getHistoryIndex(), local
+ .get()));
}
/* (non-Javadoc)
@@ -411,7 +431,8 @@
public Object put(Fqn fqn, Serializable key, Object value)
{
CompressedChangesBuffer changesContainer = getChangesBufferSafe();
- changesContainer.add(new PutKeyValueContainer(fqn, key, value, parentCache, changesContainer.getHistoryIndex(), local.get()));
+ changesContainer.add(new PutKeyValueContainer(fqn, key, value, parentCache, changesContainer.getHistoryIndex(),
+ local.get()));
return parentCache.get(fqn, key);
}
@@ -447,7 +468,8 @@
public Object remove(Fqn fqn, Serializable key)
{
CompressedChangesBuffer changesContainer = getChangesBufferSafe();
- changesContainer.add(new RemoveKeyContainer(fqn, key, parentCache, changesContainer.getHistoryIndex(), local.get()));
+ changesContainer.add(new RemoveKeyContainer(fqn, key, parentCache, changesContainer.getHistoryIndex(), local
+ .get()));
return parentCache.get(fqn, key);
}
@@ -557,7 +579,8 @@
public void addToList(Fqn fqn, String key, Object value)
{
CompressedChangesBuffer changesContainer = getChangesBufferSafe();
- changesContainer.add(new AddToListContainer(fqn, key, value, parentCache, changesContainer.getHistoryIndex(), local.get()));
+ changesContainer.add(new AddToListContainer(fqn, key, value, parentCache, changesContainer.getHistoryIndex(),
+ local.get()));
}
/**
@@ -570,8 +593,8 @@
public void removeFromList(Fqn fqn, String key, Object value)
{
CompressedChangesBuffer changesContainer = getChangesBufferSafe();
- changesContainer
- .add(new RemoveFromListContainer(fqn, key, value, parentCache, changesContainer.getHistoryIndex(), local.get()));
+ changesContainer.add(new RemoveFromListContainer(fqn, key, value, parentCache,
+ changesContainer.getHistoryIndex(), local.get()));
}
public static enum ChangesType {
@@ -593,7 +616,8 @@
protected final boolean localMode;
- public ChangesContainer(Fqn fqn, ChangesType changesType, Cache<Serializable, Object> cache, int historicalIndex, boolean localMode)
+ public ChangesContainer(Fqn fqn, ChangesType changesType, Cache<Serializable, Object> cache, int historicalIndex,
+ boolean localMode)
{
super();
this.fqn = fqn;
@@ -646,7 +670,7 @@
{
cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(localMode);
}
-
+
public abstract void apply();
}
@@ -787,7 +811,8 @@
{
private final Serializable key;
- public RemoveKeyContainer(Fqn fqn, Serializable key, Cache<Serializable, Object> cache, int historicalIndex, boolean local)
+ public RemoveKeyContainer(Fqn fqn, Serializable key, Cache<Serializable, Object> cache, int historicalIndex,
+ boolean local)
{
super(fqn, ChangesType.REMOVE_KEY, cache, historicalIndex, local);
this.key = key;
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java 2010-01-18 14:24:35 UTC (rev 1464)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java 2010-01-18 14:40:17 UTC (rev 1465)
@@ -352,8 +352,11 @@
*/
public void put(ItemData item)
{
+ boolean inTransaction = cache.isTransactionActive();
try
{
+ if (!inTransaction)
+ cache.beginTransaction();
cache.setLocal(true);
if (item.isNode())
{
@@ -367,6 +370,8 @@
finally
{
cache.setLocal(false);
+ if (!inTransaction)
+ cache.commitTransaction();
}
}
@@ -428,15 +433,18 @@
*/
public void addChildNodes(NodeData parent, List<NodeData> childs)
{
+ boolean inTransaction = cache.isTransactionActive();
try
{
+
+ if (!inTransaction)
+ cache.beginTransaction();
cache.setLocal(true);
// remove previous all (to be sure about consistency)
cache.removeNode(makeChildListFqn(childNodesList, parent.getIdentifier()));
if (childs.size() > 0)
{
- // add all new
Set<Object> set = new HashSet<Object>();
for (NodeData child : childs)
{
@@ -454,6 +462,8 @@
finally
{
cache.setLocal(false);
+ if (!inTransaction)
+ cache.commitTransaction();
}
}
@@ -462,8 +472,11 @@
*/
public void addChildProperties(NodeData parent, List<PropertyData> childs)
{
+ boolean inTransaction = cache.isTransactionActive();
try
{
+ if (!inTransaction)
+ cache.beginTransaction();
cache.setLocal(true);
// remove previous all (to be sure about consistency)
cache.removeNode(makeChildListFqn(childPropsList, parent.getIdentifier()));
@@ -477,6 +490,7 @@
set.add(child.getIdentifier());
}
cache.put(makeChildListFqn(childPropsList, parent.getIdentifier()), ITEM_LIST, set);
+
}
else
{
@@ -486,6 +500,8 @@
finally
{
cache.setLocal(false);
+ if (!inTransaction)
+ cache.commitTransaction();
}
}
@@ -494,15 +510,18 @@
*/
public void addChildPropertiesList(NodeData parent, List<PropertyData> childProperties)
{
- try
- {
- cache.setLocal(true);
- // TODO not implemented, will force read from DB
- }
- finally
- {
- cache.setLocal(false);
- }
+ // TODO not implemented, will force read from DB
+ // try
+ // {
+ // cache.beginTransaction();
+ // cache.setLocal(true);
+ //
+ // }
+ // finally
+ // {
+ // cache.setLocal(false);
+ // cache.commitTransaction();
+ // }
}
/**
16 years, 3 months
exo-jcr SVN: r1464 - jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock.
by do-not-reply@jboss.org
Author: areshetnyak
Date: 2010-01-18 09:24:35 -0500 (Mon, 18 Jan 2010)
New Revision: 1464
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/LockData.java
Log:
EXOJCR-411 : The calculation TimeToDeath in LockData was fixed.
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/LockData.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/LockData.java 2010-01-18 13:53:38 UTC (rev 1463)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/LockData.java 2010-01-18 14:24:35 UTC (rev 1464)
@@ -101,7 +101,7 @@
this.owner = owner;
this.timeOut = timeOut;
this.live = true;
- this.birthday = System.currentTimeMillis() / 1000;
+ this.birthday = System.currentTimeMillis();
}
/**
@@ -166,7 +166,7 @@
*/
public long getTimeToDeath()
{
- return birthday + timeOut - System.currentTimeMillis() / 1000;
+ return birthday + timeOut - System.currentTimeMillis();
}
/*
16 years, 3 months
exo-jcr SVN: r1463 - in jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock: jbosscache and 1 other directory.
by do-not-reply@jboss.org
Author: areshetnyak
Date: 2010-01-18 08:53:38 -0500 (Mon, 18 Jan 2010)
New Revision: 1463
Modified:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/LockData.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/LockData.java
Log:
EXOJCR-411 : The calculation TimeToDeath in LockData was fixed.
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/LockData.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/LockData.java 2010-01-18 13:11:08 UTC (rev 1462)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/LockData.java 2010-01-18 13:53:38 UTC (rev 1463)
@@ -101,7 +101,7 @@
this.owner = owner;
this.timeOut = timeOut;
this.live = true;
- this.birthday = System.currentTimeMillis() / 1000;
+ this.birthday = System.currentTimeMillis();
}
/**
@@ -166,7 +166,7 @@
*/
public long getTimeToDeath()
{
- return birthday + timeOut - System.currentTimeMillis() / 1000;
+ return birthday + timeOut - System.currentTimeMillis();
}
/*
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/LockData.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/LockData.java 2010-01-18 13:11:08 UTC (rev 1462)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/LockData.java 2010-01-18 13:53:38 UTC (rev 1463)
@@ -100,7 +100,7 @@
this.sessionScoped = sessionScoped;
this.owner = owner;
this.timeOut = timeOut;
- this.birthday = System.currentTimeMillis() / 1000;
+ this.birthday = System.currentTimeMillis();
}
/*
@@ -142,7 +142,7 @@
*/
public long getTimeToDeath()
{
- return birthday + timeOut - System.currentTimeMillis() / 1000;
+ return birthday + timeOut - System.currentTimeMillis();
}
public String getTokenHash()
16 years, 3 months
exo-jcr SVN: r1462 - jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache.
by do-not-reply@jboss.org
Author: nzamosenchuk
Date: 2010-01-18 08:11:08 -0500 (Mon, 18 Jan 2010)
New Revision: 1462
Modified:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java
Log:
EXOJCR-391: Add child lists with a single cache.put()
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java 2010-01-18 12:32:09 UTC (rev 1461)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java 2010-01-18 13:11:08 UTC (rev 1462)
@@ -53,7 +53,6 @@
import java.util.Set;
import javax.jcr.RepositoryException;
-import javax.transaction.RollbackException;
import javax.transaction.TransactionManager;
/**
@@ -438,10 +437,13 @@
if (childs.size() > 0)
{
// add all new
+ Set<Object> set = new HashSet<Object>();
for (NodeData child : childs)
{
- putNode(child, ModifyChildOption.FORCE_MODIFY);
+ putNode(child, ModifyChildOption.NOT_MODIFY);
+ set.add(child.getIdentifier());
}
+ cache.put(makeChildListFqn(childNodesList, parent.getIdentifier()), ITEM_LIST, set);
}
else
{
@@ -468,10 +470,13 @@
if (childs.size() > 0)
{
// add all new
+ Set<Object> set = new HashSet<Object>();
for (PropertyData child : childs)
{
- putProperty(child, ModifyChildOption.FORCE_MODIFY);
+ putProperty(child, ModifyChildOption.NOT_MODIFY);
+ set.add(child.getIdentifier());
}
+ cache.put(makeChildListFqn(childPropsList, parent.getIdentifier()), ITEM_LIST, set);
}
else
{
16 years, 3 months
exo-jcr SVN: r1461 - in jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src: main/java/org/exoplatform/services/jcr/impl/dataflow/session and 1 other directories.
by do-not-reply@jboss.org
Author: pnedonosko
Date: 2010-01-18 07:32:09 -0500 (Mon, 18 Jan 2010)
New Revision: 1461
Modified:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/XASessionImpl.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/session/TransactionableDataManager.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/session/TransactionableResourceManager.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/xa/TestUserTransaction.java
Log:
EXOJCR-405 XASession commit reworked to support one- and two-phase behaviours, for one-phase the fail will cause a rollback immediately. Heuristic rollback is possible.
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/XASessionImpl.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/XASessionImpl.java 2010-01-18 12:03:30 UTC (rev 1460)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/XASessionImpl.java 2010-01-18 12:32:09 UTC (rev 1461)
@@ -203,7 +203,7 @@
{
try
{
- txResourceManager.commit(this);
+ txResourceManager.commit(this, onePhase);
}
catch (TransactionException e)
{
@@ -213,7 +213,7 @@
LOG.debug("Commit Error. Xid:" + xid + ", session: " + getSessionInfo() + ", " + this, e);
}
- throw new XASessionException(e.toString(), XAException.XA_RBOTHER);
+ throw new XASessionException(e.toString(), e.getErrorCode());
}
if (LOG.isDebugEnabled())
@@ -225,14 +225,28 @@
/**
* {@inheritDoc}
*/
+ public void start(Xid xid, int flags) throws XAException
+ {
+ txResourceManager.start(this);
+ startFlags = flags;
+
+ if (LOG.isDebugEnabled())
+ {
+ LOG.debug("Start. Xid:" + xid + ", " + flags + ", session: " + getSessionInfo() + ", " + this);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public void end(Xid xid, int flags) throws XAException
{
+ startFlags = flags;
+
if (LOG.isDebugEnabled())
{
LOG.debug("End. Xid:" + xid + ", " + flags + ", session: " + getSessionInfo() + ", " + this);
}
-
- startFlags = flags;
}
/**
@@ -338,20 +352,6 @@
/**
* {@inheritDoc}
*/
- public void start(Xid xid, int flags) throws XAException
- {
- txResourceManager.start(this);
- startFlags = flags;
-
- if (LOG.isDebugEnabled())
- {
- LOG.debug("Start. Xid:" + xid + ", " + flags + ", session: " + getSessionInfo() + ", " + this);
- }
- }
-
- /**
- * {@inheritDoc}
- */
@Override
public void logout()
{
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/session/TransactionableDataManager.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/session/TransactionableDataManager.java 2010-01-18 12:03:30 UTC (rev 1460)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/session/TransactionableDataManager.java 2010-01-18 12:32:09 UTC (rev 1461)
@@ -298,8 +298,9 @@
try
{
- storageDataManager.save(transactionLog);
+ TransactionChangesLog tl = transactionLog;
transactionLog = null;
+ storageDataManager.save(tl);
}
catch (InvalidItemStateException e)
{
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/session/TransactionableResourceManager.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/session/TransactionableResourceManager.java 2010-01-18 12:03:30 UTC (rev 1460)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/session/TransactionableResourceManager.java 2010-01-18 12:32:09 UTC (rev 1461)
@@ -25,9 +25,13 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
+import java.util.Set;
+import javax.transaction.xa.XAException;
+
/**
* Created by The eXo Platform SAS.
* <p/>
@@ -142,20 +146,62 @@
* @throws TransactionException
* Transaction error
*/
- synchronized public void commit(XASessionImpl userSession) throws TransactionException
+ synchronized public void commit(XASessionImpl userSession, boolean onePhase) throws TransactionException
{
- List<SoftReference<XASessionImpl>> joinedList = txResources.remove(userSession.getUserID());
+ List<SoftReference<XASessionImpl>> joinedList;
+ if (onePhase)
+ {
+ joinedList = txResources.remove(userSession.getUserID());
+ }
+ else
+ {
+ // TODO keep session on commit to be able to rollback all via XASessions(XAResource) and TM lifecycle
+ joinedList = txResources.get(userSession.getUserID());
+ }
+
if (joinedList != null)
{
- for (SoftReference<XASessionImpl> sr : joinedList)
+ int i = 0;
+ try
{
- XASessionImpl xaSession = sr.get();
- if (xaSession != null && xaSession.isLive())
+ while (i < joinedList.size())
{
- TransactionableDataManager txManager = xaSession.getTransientNodesManager().getTransactManager();
- txManager.commit();
+ SoftReference<XASessionImpl> sr = joinedList.get(i++);
+ XASessionImpl xaSession = sr.get();
+ if (xaSession != null && xaSession.isLive())
+ {
+ xaSession.getTransientNodesManager().getTransactManager().commit();
+ }
}
}
+ catch (TransactionException e)
+ {
+ boolean mixedCommit = i > 0;
+ if (onePhase)
+ {
+ // rollback now
+ for (; i < joinedList.size(); i++)
+ {
+ SoftReference<XASessionImpl> sr = joinedList.get(i);
+ XASessionImpl xaSession = sr.get();
+ if (xaSession != null && xaSession.isLive())
+ {
+ xaSession.getTransientNodesManager().getTransactManager().rollback();
+ }
+ }
+ }
+
+ if (mixedCommit)
+ {
+ // somethings were commited already
+ throw new TransactionException(XAException.XA_HEURMIX, e);
+ }
+ else
+ {
+ // all things were rolled back
+ throw new TransactionException(XAException.XA_HEURRB, e);
+ }
+ }
}
}
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/xa/TestUserTransaction.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/xa/TestUserTransaction.java 2010-01-18 12:03:30 UTC (rev 1460)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/xa/TestUserTransaction.java 2010-01-18 12:32:09 UTC (rev 1461)
@@ -21,6 +21,7 @@
import org.exoplatform.services.jcr.JcrAPIBaseTest;
import org.exoplatform.services.jcr.core.XASession;
import org.exoplatform.services.jcr.impl.core.SessionImpl;
+import org.exoplatform.services.jcr.impl.core.XASessionImpl;
import org.exoplatform.services.transaction.TransactionService;
import java.util.ArrayList;
@@ -238,8 +239,14 @@
Session s1 =
repository.login(new SimpleCredentials("admin", "admin".toCharArray()), session.getWorkspace().getName());
+ Session s2 =
+ repository.login(new SimpleCredentials("admin", "admin".toCharArray()), session.getWorkspace().getName());
+
Node tx1 = s1.getRootNode().getNode("pretx").addNode("tx1");
s1.save();
+
+ Node tx2 = s2.getRootNode().getNode("pretx").addNode("tx2");
+ s2.save();
s0.save(); // save that parent of tx1 removed
16 years, 3 months
exo-jcr SVN: r1460 - kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/transaction.
by do-not-reply@jboss.org
Author: pnedonosko
Date: 2010-01-18 07:03:30 -0500 (Mon, 18 Jan 2010)
New Revision: 1460
Modified:
kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/transaction/TransactionException.java
Log:
EXOJCR-405 TransactionException with errcode param
Modified: kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/transaction/TransactionException.java
===================================================================
--- kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/transaction/TransactionException.java 2010-01-18 11:13:44 UTC (rev 1459)
+++ kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/transaction/TransactionException.java 2010-01-18 12:03:30 UTC (rev 1460)
@@ -18,6 +18,8 @@
*/
package org.exoplatform.services.transaction;
+import javax.transaction.xa.XAException;
+
/**
* Created by The eXo Platform SAS.
*
@@ -29,24 +31,46 @@
public class TransactionException extends Exception
{
+ private final int errcode;
+
public TransactionException()
{
super();
+ this.errcode = XAException.XA_RBOTHER;
}
public TransactionException(String arg0)
{
super(arg0);
+ this.errcode = XAException.XA_RBOTHER;
}
public TransactionException(String arg0, Throwable arg1)
{
super(arg0, arg1);
+ this.errcode = XAException.XA_RBOTHER;
}
public TransactionException(Throwable arg0)
{
super(arg0);
+ this.errcode = XAException.XA_RBOTHER;
}
+
+ public TransactionException(int errcode, String arg0)
+ {
+ super(arg0);
+ this.errcode = errcode;
+ }
+
+ public TransactionException(int errcode, Throwable arg0)
+ {
+ super(arg0);
+ this.errcode = errcode;
+ }
+ public int getErrorCode()
+ {
+ return errcode;
+ }
}
16 years, 3 months
exo-jcr SVN: r1459 - in jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock: jbosscache and 1 other directory.
by do-not-reply@jboss.org
Author: sergiykarpenko
Date: 2010-01-18 06:13:44 -0500 (Mon, 18 Jan 2010)
New Revision: 1459
Modified:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/AbstractLockManager.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/SessionLockManager.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/SessionLockManagerImpl.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManager.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableSessionLockManager.java
Log:
EXOJCR-332: code cleanup
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/AbstractLockManager.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/AbstractLockManager.java 2010-01-18 10:23:10 UTC (rev 1458)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/AbstractLockManager.java 2010-01-18 11:13:44 UTC (rev 1459)
@@ -26,5 +26,13 @@
*/
public abstract class AbstractLockManager implements LockManager
{
- //TODO remove this class
+ /**
+ * {@inheritDoc}
+ */
+ public abstract void removeExpired();
+
+ /**
+ * {@inheritDoc}
+ */
+ public abstract SessionLockManager getSessionLockManager(String sessionId);
}
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/SessionLockManager.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/SessionLockManager.java 2010-01-18 10:23:10 UTC (rev 1458)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/SessionLockManager.java 2010-01-18 11:13:44 UTC (rev 1459)
@@ -43,6 +43,17 @@
*/
void addLockToken(String lt);
+ /**
+ * Add lock for node.
+ *
+ * @param node - NodeImpl
+ * @param isDeep - lock is deep
+ * @param isSessionScoped - lock is session scoped
+ * @param timeOut - lock live time
+ * @return Lock
+ * @throws LockException
+ * @throws RepositoryException
+ */
Lock addLock(NodeImpl node, boolean isDeep, boolean isSessionScoped, long timeOut) throws LockException,
RepositoryException;
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/SessionLockManagerImpl.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/SessionLockManagerImpl.java 2010-01-18 10:23:10 UTC (rev 1458)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/SessionLockManagerImpl.java 2010-01-18 11:13:44 UTC (rev 1459)
@@ -39,53 +39,83 @@
private final LockManagerImpl lockManager;
+ /**
+ * Constructor
+ */
public SessionLockManagerImpl(String sessionId, LockManagerImpl lockManager)
{
this.sessionId = sessionId;
this.lockManager = lockManager;
}
+ /**
+ * {@inheritDoc}
+ */
public Lock addLock(NodeImpl node, boolean isDeep, boolean isSessionScoped, long timeOut) throws LockException,
RepositoryException
{
return lockManager.addPendingLock(node, isDeep, isSessionScoped, timeOut);
}
+ /**
+ * {@inheritDoc}
+ */
public void addLockToken(String lt)
{
lockManager.addLockToken(sessionId, lt);
}
+ /**
+ * {@inheritDoc}
+ */
public LockImpl getLock(NodeImpl node) throws LockException, RepositoryException
{
return lockManager.getLock(node);
}
+ /**
+ * {@inheritDoc}
+ */
public String[] getLockTokens()
{
return lockManager.getLockTokens(sessionId);
}
+ /**
+ * {@inheritDoc}
+ */
public boolean holdsLock(NodeData node) throws RepositoryException
{
return lockManager.holdsLock(node);
}
+ /**
+ * {@inheritDoc}
+ */
public boolean isLockHolder(NodeImpl node) throws RepositoryException
{
return lockManager.isLockHolder(node);
}
+ /**
+ * {@inheritDoc}
+ */
public boolean isLocked(NodeData node)
{
return lockManager.isLocked(node);
}
+ /**
+ * {@inheritDoc}
+ */
public void removeLockToken(String lt)
{
lockManager.removeLockToken(sessionId, lt);
}
+ /**
+ * {@inheritDoc}
+ */
public void onCloseSession(ExtendedSession session)
{
lockManager.onCloseSession(session);
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManager.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManager.java 2010-01-18 10:23:10 UTC (rev 1458)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManager.java 2010-01-18 11:13:44 UTC (rev 1459)
@@ -152,6 +152,8 @@
private Node<Serializable, Object> lockRoot;
+ private Map<String, CacheableSessionLockManager> sessionLockManagers;
+
/**
* Constructor for workspace without LockPersister
*
@@ -188,6 +190,7 @@
lockTimeOut = DEFAULT_LOCK_TIMEOUT;
pendingLocks = new HashMap<String, LockData>();
+ sessionLockManagers = new HashMap<String, CacheableSessionLockManager>();
dataManager.addItemPersistenceListener(this);
@@ -259,14 +262,21 @@
}
/**
- *
+ * Return new instance of session lock manager.
*/
public SessionLockManager getSessionLockManager(String sessionId)
{
CacheableSessionLockManager sessionManager = new CacheableSessionLockManager(sessionId, this);
+ sessionLockManagers.put(sessionId, sessionManager);
return sessionManager;
}
+ /**
+ * Check is LockManager contains lock. No matter it is in pending or persistent state.
+ *
+ * @param nodeId - locked node id
+ * @return
+ */
public boolean isLockLive(String nodeId)
{
if (pendingLocks.containsKey(nodeId) || lockRoot.hasChild(Fqn.fromString(nodeId)))
@@ -460,6 +470,7 @@
lockRemover.halt();
lockRemover.interrupt();
pendingLocks.clear();
+ sessionLockManagers.clear();
cache.stop();
}
@@ -533,7 +544,12 @@
if (lData != null)
{
lockRoot.removeChild(Fqn.fromString(nodeIdentifier));
- // TODO pair nodeId and lockData is not removed from CacheableSessionLockManager
+
+ CacheableSessionLockManager sessMgr = sessionLockManagers.get(sessionId);
+ if (sessMgr != null)
+ {
+ sessMgr.notifyLockRemoved(nodeIdentifier);
+ }
}
}
@@ -689,4 +705,14 @@
log.error("Error occur during removing lock" + e.getLocalizedMessage(), e);
}
}
+
+ /**
+ * Release all resources associated with CacheableSessionLockManager.
+ *
+ * @param sessionID - session identifier
+ */
+ protected void closeSession(String sessionID)
+ {
+ sessionLockManagers.remove(sessionID);
+ }
}
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableSessionLockManager.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableSessionLockManager.java 2010-01-18 10:23:10 UTC (rev 1458)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableSessionLockManager.java 2010-01-18 11:13:44 UTC (rev 1459)
@@ -51,17 +51,34 @@
*/
private final Log log = ExoLogger.getLogger("jcr.lock.SessionLockManager");
+ /**
+ * Session identifier.
+ */
private final String sessionID;
/**
+ * Lock tokens held by this session.
* [token name, tokens hash]
*/
private final Map<String, String> tokens;
+ /**
+ * Map of nodes locked in this session. Need to remove session scoped lock on session close.
+ * [node identifier, lock data]
+ */
private final Map<String, LockData> lockedNodes;
+ /**
+ * Workspace lock manager
+ */
private final CacheableLockManager lockManager;
+ /**
+ * Constructor.
+ *
+ * @param sessionID - session identifier
+ * @param lockManager - workspace lock manager
+ */
public CacheableSessionLockManager(String sessionID, CacheableLockManager lockManager)
{
this.sessionID = sessionID;
@@ -70,6 +87,9 @@
this.lockManager = lockManager;
}
+ /**
+ * {@inheritDoc}
+ */
public Lock addLock(NodeImpl node, boolean isDeep, boolean isSessionScoped, long timeOut) throws LockException,
RepositoryException
{
@@ -112,11 +132,17 @@
}
+ /**
+ * {@inheritDoc}
+ */
public void addLockToken(String lt)
{
tokens.put(lt, lockManager.getHash(lt));
}
+ /**
+ * {@inheritDoc}
+ */
public LockImpl getLock(NodeImpl node) throws LockException, RepositoryException
{
LockData lData =
@@ -130,6 +156,9 @@
return new CacheLockImpl(node.getSession(), lData, this);
}
+ /**
+ * {@inheritDoc}
+ */
public String[] getLockTokens()
{
String[] arr = new String[tokens.size()];
@@ -137,11 +166,17 @@
return arr;
}
+ /**
+ * {@inheritDoc}
+ */
public boolean holdsLock(NodeData node) throws RepositoryException
{
return lockManager.getLockData(node, CacheableLockManager.SEARCH_EXECMATCH) != null;
}
+ /**
+ * {@inheritDoc}
+ */
public boolean isLocked(NodeData node)
{
LockData lData =
@@ -155,6 +190,9 @@
return true;
}
+ /**
+ * {@inheritDoc}
+ */
public boolean isLockHolder(NodeImpl node) throws RepositoryException
{
LockData lData =
@@ -164,6 +202,9 @@
return lData != null && isLockHolder(lData);
}
+ /**
+ * {@inheritDoc}
+ */
public void onCloseSession(ExtendedSession session)
{
SessionImpl sessionImpl = (SessionImpl)session;
@@ -183,8 +224,6 @@
((NodeImpl)sessionImpl.getTransientNodesManager()
.getItemByIdentifier(lock.getNodeIdentifier(), false));
- // Node may be null, since cacheablelockManger.internalUnlock does not modify
- // SessionLockManager.lockedNodes map. So Node and Lock is removed, but exist in lockedNodes list.
if (node != null)
{
node.unlock();
@@ -226,8 +265,12 @@
}
}
}
+ lockManager.closeSession(sessionID);
}
+ /**
+ * {@inheritDoc}
+ */
public void removeLockToken(String lt)
{
tokens.remove(lt);
@@ -262,14 +305,36 @@
return null;
}
+ /**
+ * Check is lock alive. That means lock must exist in LockManager storage (cache or map, etc).
+ *
+ * @param nodeIdentifier - locked node id
+ * @return
+ */
protected boolean isLockLive(String nodeIdentifier)
{
return lockManager.isLockLive(nodeIdentifier);
}
+ /**
+ * Refresh lockData.
+ *
+ * @param newLockData
+ * @throws LockException
+ */
protected void refresh(LockData newLockData) throws LockException
{
lockManager.refresh(newLockData);
}
+ /**
+ * Notify SessionLockManager that node is unlocked.
+ *
+ * @param nodeIdentifier - unlocked node identifier
+ */
+ protected void notifyLockRemoved(String nodeIdentifier)
+ {
+ lockedNodes.remove(nodeIdentifier);
+ }
+
}
16 years, 3 months
exo-jcr SVN: r1458 - in jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src: main/java/org/exoplatform/services/jcr/impl/core and 2 other directories.
by do-not-reply@jboss.org
Author: pnedonosko
Date: 2010-01-18 05:23:10 -0500 (Mon, 18 Jan 2010)
New Revision: 1458
Added:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/XASessionException.java
Modified:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/core/XASession.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/XASessionImpl.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/session/TransactionableDataManager.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/xa/TestUserTransaction.java
Log:
EXOJCR-405 XASession can return last commit Exception; log.debug added; TransactionableDM commit execptions with messages
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/core/XASession.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/core/XASession.java 2010-01-18 08:56:04 UTC (rev 1457)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/core/XASession.java 2010-01-18 10:23:10 UTC (rev 1458)
@@ -18,6 +18,8 @@
*/
package org.exoplatform.services.jcr.core;
+import org.exoplatform.services.transaction.TransactionException;
+
import javax.jcr.Session;
import javax.transaction.xa.XAException;
import javax.transaction.xa.XAResource;
@@ -50,4 +52,11 @@
* @throws XAException
*/
void delistResource() throws XAException;
+
+ /**
+ * Returns TransactionException of a last commit XA intransaction context. Can be null. For information purpose.
+ *
+ * @return TransactionException commit exception
+ */
+ TransactionException getCommitException();
}
Added: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/XASessionException.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/XASessionException.java (rev 0)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/XASessionException.java 2010-01-18 10:23:10 UTC (rev 1458)
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2010 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.core;
+
+import javax.transaction.xa.XAException;
+
+/**
+ * Provides XAException functionality with constructor for errorcode and message.
+ *
+ * @author <a href="mailto:peter.nedonosko@exoplatform.com">Peter Nedonosko</a>
+ * @version $Id$
+ * */
+public class XASessionException extends XAException
+{
+
+ /**
+ * serialVersionUID.
+ */
+ private static final long serialVersionUID = -1853702973389878895L;
+
+ public XASessionException()
+ {
+ super();
+ }
+
+ public XASessionException(int errcode)
+ {
+ super(errcode);
+ }
+
+ public XASessionException(String s)
+ {
+ super(s);
+ }
+
+ public XASessionException(String s, int errorCode)
+ {
+ super(s);
+ this.errorCode = errorCode;
+ }
+}
Property changes on: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/XASessionException.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/XASessionImpl.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/XASessionImpl.java 2010-01-18 08:56:04 UTC (rev 1457)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/XASessionImpl.java 2010-01-18 10:23:10 UTC (rev 1458)
@@ -75,6 +75,11 @@
private Object payload;
/**
+ * TransactionException of a last commit in context of a transaction. Can be set on commit and will be restet on enlist/delist resource or rollback.
+ */
+ private TransactionException commitException = null;
+
+ /**
* XASessionImpl constructor.
*
* @param workspaceName
@@ -130,16 +135,27 @@
LOG.debug("Delist session: " + getSessionInfo() + ", " + this);
}
+ commitException = null;
txResourceManager.remove(this);
tService.delistResource(this);
}
catch (RollbackException e)
{
- throw new XAException(e.getMessage());
+ if (LOG.isDebugEnabled())
+ {
+ LOG.debug("Delist error, session: " + getSessionInfo() + ", " + this, e);
+ }
+
+ throw new XASessionException("Cannot delist resource XASession " + getSessionInfo() + ". " + e);
}
catch (SystemException e)
{
- throw new XAException(e.getMessage());
+ if (LOG.isDebugEnabled())
+ {
+ LOG.debug("Delist error, session: " + getSessionInfo() + ", " + this, e);
+ }
+
+ throw new XASessionException("Cannot delist resource XASession " + getSessionInfo() + ". " + e);
}
}
@@ -156,16 +172,27 @@
LOG.debug("Enlist session: " + getSessionInfo() + ", " + this);
}
+ commitException = null;
txResourceManager.add(this);
tService.enlistResource(this);
}
catch (RollbackException e)
{
- throw new XAException(e.getMessage());
+ if (LOG.isDebugEnabled())
+ {
+ LOG.debug("Enlist error, session: " + getSessionInfo() + ", " + this, e);
+ }
+
+ throw new XASessionException("Cannot enlist resource XASession " + getSessionInfo() + ". " + e);
}
catch (SystemException e)
{
- throw new XAException(e.getMessage());
+ if (LOG.isDebugEnabled())
+ {
+ LOG.debug("Enlist error, session: " + getSessionInfo() + ", " + this, e);
+ }
+
+ throw new XASessionException("Cannot enlist resource XASession " + getSessionInfo() + ". " + e);
}
}
@@ -180,7 +207,13 @@
}
catch (TransactionException e)
{
- throw new XAException(XAException.XA_RBOTHER);
+ commitException = e;
+ if (LOG.isDebugEnabled())
+ {
+ LOG.debug("Commit Error. Xid:" + xid + ", session: " + getSessionInfo() + ", " + this, e);
+ }
+
+ throw new XASessionException(e.toString(), XAException.XA_RBOTHER);
}
if (LOG.isDebugEnabled())
@@ -207,6 +240,13 @@
*/
public void forget(Xid xid) throws XAException
{
+ // TODO forget = rollback?
+ //txResourceManager.rollback(this);
+
+ //if (LOG.isDebugEnabled())
+ //{
+ // LOG.debug("Forget. Xid:" + xid + ", session: " + getSessionInfo() + ", " + this);
+ //}
}
/**
@@ -231,6 +271,7 @@
LOG.debug("isSameRM: " + getSessionInfo() + " -- " + session.getSessionInfo() + " : " + isSame + ", "
+ this + " -- " + session + ", Flags:" + startFlags);
}
+
return isSame;
}
return false;
@@ -263,6 +304,7 @@
public void rollback(Xid xid) throws XAException
{
txResourceManager.rollback(this);
+ commitException = null;
if (LOG.isDebugEnabled())
{
@@ -281,7 +323,13 @@
}
catch (SystemException e)
{
- throw new XAException(e.getMessage());
+ if (LOG.isDebugEnabled())
+ {
+ LOG.debug("Cannot set transaction timeout " + seconds + "sec via XASession " + getSessionInfo() + ". ", e);
+ }
+
+ throw new XASessionException("Cannot set transaction timeout " + seconds + "sec via XASession "
+ + getSessionInfo() + ". " + e);
}
this.txTimeout = seconds;
return true;
@@ -330,7 +378,7 @@
}
catch (XAException e)
{
- LOG.error("Logut error " + e, e);
+ LOG.error("Logout error " + e, e);
}
}
}
@@ -345,13 +393,27 @@
return getUserID() + "@" + workspaceName;
}
+ /**
+ * {@inheritDoc}
+ */
public Object getPayload()
{
return payload;
}
+ /**
+ * {@inheritDoc}
+ */
public void setPayload(Object payload)
{
this.payload = payload;
}
+
+ /**
+ * {@inheritDoc}
+ */
+ public TransactionException getCommitException()
+ {
+ return commitException;
+ }
}
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/session/TransactionableDataManager.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/session/TransactionableDataManager.java 2010-01-18 08:56:04 UTC (rev 1457)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/session/TransactionableDataManager.java 2010-01-18 10:23:10 UTC (rev 1458)
@@ -303,11 +303,11 @@
}
catch (InvalidItemStateException e)
{
- throw new TransactionException(e);
+ throw new TransactionException(e.getMessage(), e);
}
catch (RepositoryException e)
{
- throw new TransactionException(e);
+ throw new TransactionException(e.getMessage(), e);
}
}
}
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/xa/TestUserTransaction.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/xa/TestUserTransaction.java 2010-01-18 08:56:04 UTC (rev 1457)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/xa/TestUserTransaction.java 2010-01-18 10:23:10 UTC (rev 1458)
@@ -31,8 +31,8 @@
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;
import javax.naming.InitialContext;
+import javax.transaction.RollbackException;
import javax.transaction.UserTransaction;
-import javax.transaction.xa.XAException;
/**
* Created by The eXo Platform SAS. <br>
@@ -112,7 +112,7 @@
return someSessions;
}
- public void testCommit() throws Exception
+ public void _testCommit() throws Exception
{
assertNotNull(txService);
List<Session> someSessions = openSomeSessions();
@@ -143,7 +143,7 @@
someSessions.clear();
}
- public void testRollback() throws Exception
+ public void _testRollback() throws Exception
{
assertNotNull(txService);
UserTransaction ut = txService.getUserTransaction();
@@ -168,17 +168,15 @@
}
}
- public void testUserTransactionFromJndi() throws Exception
+ public void _testUserTransactionFromJndi() throws Exception
{
assertNotNull(txService);
// TODO in JNDI only JOTM today
- //InitialContext ctx = new InitialContext();
- //Object obj = ctx.lookup("UserTransaction");
- //UserTransaction ut = (UserTransaction)obj;
+ InitialContext ctx = new InitialContext();
+ Object obj = ctx.lookup("UserTransaction");
+ UserTransaction ut = (UserTransaction)obj;
- UserTransaction ut = txService.getUserTransaction();
-
ut.begin();
Session s1 =
repository.login(new SimpleCredentials("admin", "admin".toCharArray()), session.getWorkspace().getName());
@@ -186,10 +184,9 @@
s1.save();
ut.commit();
assertNotNull(session.getItem("/txcommit1"));
-
}
- public void testReuseUT() throws Exception
+ public void _testReuseUT() throws Exception
{
assertNotNull(txService);
// TODO in JNDI only JOTM today
@@ -230,7 +227,7 @@
UserTransaction ut = txService.getUserTransaction();
Session s0 =
- repository.login(new SimpleCredentials("admin", "admin".toCharArray()), session.getWorkspace().getName());
+ repository.login(new SimpleCredentials("root", "exo".toCharArray()), session.getWorkspace().getName());
Node pretx = s0.getRootNode().addNode("pretx");
s0.save();
@@ -250,17 +247,19 @@
{
ut.commit();
// internally XAException should be thrown
- fail("XAException with InvalidItemState should occurs");
+ fail("Exception should occurs");
}
- catch (Throwable e)
+ catch (Exception e)
{
// ok
- e.printStackTrace();
- System.out.println(e);
+ assertNotNull(((XASession) s1).getCommitException());
}
- assertNotNull(session.getItem("/pretx/tx1"));
-
+ try {
+ session.getItem("/pretx/tx1");
+ fail("PathNotFoundException should be thrown");
+ } catch(PathNotFoundException e) {
+ // ok
+ }
}
-
}
16 years, 3 months
exo-jcr SVN: r1457 - jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache.
by do-not-reply@jboss.org
Author: nzamosenchuk
Date: 2010-01-18 03:56:04 -0500 (Mon, 18 Jan 2010)
New Revision: 1457
Modified:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java
Log:
EXOJCR-409: SetLocalMode enclosed in try{} finally {}. This is needed to set Local mode to false state even if exception took place.
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java 2010-01-18 08:53:57 UTC (rev 1456)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java 2010-01-18 08:56:04 UTC (rev 1457)
@@ -353,16 +353,22 @@
*/
public void put(ItemData item)
{
- cache.setLocal(true);
- if (item.isNode())
+ try
{
- putNode((NodeData)item, ModifyChildOption.NOT_MODIFY);
+ cache.setLocal(true);
+ if (item.isNode())
+ {
+ putNode((NodeData)item, ModifyChildOption.NOT_MODIFY);
+ }
+ else
+ {
+ putProperty((PropertyData)item, ModifyChildOption.NOT_MODIFY);
+ }
}
- else
+ finally
{
- putProperty((PropertyData)item, ModifyChildOption.NOT_MODIFY);
+ cache.setLocal(false);
}
- cache.setLocal(false);
}
/**
@@ -423,24 +429,30 @@
*/
public void addChildNodes(NodeData parent, List<NodeData> childs)
{
- cache.setLocal(true);
- // remove previous all (to be sure about consistency)
- cache.removeNode(makeChildListFqn(childNodesList, parent.getIdentifier()));
+ try
+ {
+ cache.setLocal(true);
+ // remove previous all (to be sure about consistency)
+ cache.removeNode(makeChildListFqn(childNodesList, parent.getIdentifier()));
- if (childs.size() > 0)
- {
- // add all new
- for (NodeData child : childs)
+ if (childs.size() > 0)
{
- putNode(child, ModifyChildOption.FORCE_MODIFY);
+ // add all new
+ for (NodeData child : childs)
+ {
+ putNode(child, ModifyChildOption.FORCE_MODIFY);
+ }
}
+ else
+ {
+ // cache fact of empty childs list
+ cache.put(makeChildListFqn(childNodesList, parent.getIdentifier()), ITEM_LIST, new HashSet<Object>());
+ }
}
- else
+ finally
{
- // cache fact of empty childs list
- cache.put(makeChildListFqn(childNodesList, parent.getIdentifier()), ITEM_LIST, new HashSet<Object>());
+ cache.setLocal(false);
}
- cache.setLocal(false);
}
/**
@@ -448,22 +460,28 @@
*/
public void addChildProperties(NodeData parent, List<PropertyData> childs)
{
- cache.setLocal(true);
- // remove previous all (to be sure about consistency)
- cache.removeNode(makeChildListFqn(childPropsList, parent.getIdentifier()));
- if (childs.size() > 0)
+ try
{
- // add all new
- for (PropertyData child : childs)
+ cache.setLocal(true);
+ // remove previous all (to be sure about consistency)
+ cache.removeNode(makeChildListFqn(childPropsList, parent.getIdentifier()));
+ if (childs.size() > 0)
{
- putProperty(child, ModifyChildOption.FORCE_MODIFY);
+ // add all new
+ for (PropertyData child : childs)
+ {
+ putProperty(child, ModifyChildOption.FORCE_MODIFY);
+ }
}
+ else
+ {
+ LOG.warn("Empty properties list cached " + (parent != null ? parent.getQPath().getAsString() : parent));
+ }
}
- else
+ finally
{
- LOG.warn("Empty properties list cached " + (parent != null ? parent.getQPath().getAsString() : parent));
+ cache.setLocal(false);
}
- cache.setLocal(false);
}
/**
@@ -471,9 +489,15 @@
*/
public void addChildPropertiesList(NodeData parent, List<PropertyData> childProperties)
{
- cache.setLocal(true);
- // TODO not implemented, will force read from DB
- cache.setLocal(false);
+ try
+ {
+ cache.setLocal(true);
+ // TODO not implemented, will force read from DB
+ }
+ finally
+ {
+ cache.setLocal(false);
+ }
}
/**
16 years, 3 months
exo-jcr SVN: r1456 - in jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core: lock and 1 other directories.
by do-not-reply@jboss.org
Author: sergiykarpenko
Date: 2010-01-18 03:53:57 -0500 (Mon, 18 Jan 2010)
New Revision: 1456
Added:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/SessionLockManager.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/SessionLockManagerImpl.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableSessionLockManager.java
Modified:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/NodeImpl.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SessionImpl.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/AbstractLockManager.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/LockManager.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/LockManagerImpl.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheLockImpl.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManager.java
Log:
EXOJCR-332: per-session lock manager implemented
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/NodeImpl.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/NodeImpl.java 2010-01-18 08:39:04 UTC (rev 1455)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/NodeImpl.java 2010-01-18 08:53:57 UTC (rev 1456)
@@ -1596,7 +1596,7 @@
if (dataManager.hasPendingChanges(getInternalPath()))
throw new InvalidItemStateException("Node has pending unsaved changes " + getPath());
- Lock newLock = session.getLockManager().addPendingLock(this, isDeep, isSessionScoped, -1);
+ Lock newLock = session.getLockManager().addLock(this, isDeep, isSessionScoped, -1);
PlainChangesLog changesLog =
new PlainChangesLogImpl(new ArrayList<ItemState>(), session.getId(), ExtendedEvent.LOCK);
@@ -1632,7 +1632,7 @@
if (dataManager.hasPendingChanges(getInternalPath()))
throw new InvalidItemStateException("Node has pending unsaved changes " + getPath());
- Lock newLock = session.getLockManager().addPendingLock(this, isDeep, false, timeOut);
+ Lock newLock = session.getLockManager().addLock(this, isDeep, false, timeOut);
PlainChangesLog changesLog =
new PlainChangesLogImpl(new ArrayList<ItemState>(), session.getId(), ExtendedEvent.LOCK);
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SessionImpl.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SessionImpl.java 2010-01-18 08:39:04 UTC (rev 1455)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SessionImpl.java 2010-01-18 08:53:57 UTC (rev 1456)
@@ -32,6 +32,7 @@
import org.exoplatform.services.jcr.datamodel.QPathEntry;
import org.exoplatform.services.jcr.impl.Constants;
import org.exoplatform.services.jcr.impl.core.lock.AbstractLockManager;
+import org.exoplatform.services.jcr.impl.core.lock.SessionLockManager;
import org.exoplatform.services.jcr.impl.core.nodetype.NodeTypeImpl;
import org.exoplatform.services.jcr.impl.core.observation.ObservationManagerImpl;
import org.exoplatform.services.jcr.impl.core.observation.ObservationManagerRegistry;
@@ -120,7 +121,7 @@
private final LocationFactory systemLocationFactory;
- private final AbstractLockManager lockManager;
+ private final SessionLockManager lockManager;
protected final String workspaceName;
@@ -145,7 +146,6 @@
public SessionImpl(String workspaceName, ConversationState userState, ExoContainer container)
throws RepositoryException
{
-
this.workspaceName = workspaceName;
this.container = container;
this.live = true;
@@ -156,7 +156,9 @@
this.systemLocationFactory = (LocationFactory)container.getComponentInstanceOfType(LocationFactory.class);
this.accessManager = (AccessManager)container.getComponentInstanceOfType(AccessManager.class);
- this.lockManager = (AbstractLockManager)container.getComponentInstanceOfType(AbstractLockManager.class);
+ this.lockManager =
+ ((AbstractLockManager)container.getComponentInstanceOfType(AbstractLockManager.class))
+ .getSessionLockManager(id);
WorkspaceEntry wsConfig = (WorkspaceEntry)container.getComponentInstanceOfType(WorkspaceEntry.class);
this.lazyReadThreshold =
@@ -205,7 +207,7 @@
*/
public void addLockToken(String lt)
{
- getLockManager().addLockToken(getId(), lt);
+ getLockManager().addLockToken(lt);
}
/**
@@ -551,7 +553,7 @@
return locationFactory;
}
- public AbstractLockManager getLockManager()
+ public SessionLockManager getLockManager()
{
return lockManager;
}
@@ -561,7 +563,7 @@
*/
public String[] getLockTokens()
{
- return getLockManager().getLockTokens(getId());
+ return getLockManager().getLockTokens();
}
/**
@@ -919,7 +921,7 @@
*/
public void removeLockToken(String lt)
{
- getLockManager().removeLockToken(getId(), lt);
+ getLockManager().removeLockToken(lt);
}
/**
@@ -969,7 +971,7 @@
{
return this.userState;
}
-
+
int getLazyReadThreshold()
{
return lazyReadThreshold;
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/AbstractLockManager.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/AbstractLockManager.java 2010-01-18 08:39:04 UTC (rev 1455)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/AbstractLockManager.java 2010-01-18 08:53:57 UTC (rev 1456)
@@ -16,15 +16,6 @@
*/
package org.exoplatform.services.jcr.impl.core.lock;
-import javax.jcr.RepositoryException;
-import javax.jcr.lock.Lock;
-import javax.jcr.lock.LockException;
-
-import org.exoplatform.services.jcr.core.ExtendedSession;
-import org.exoplatform.services.jcr.core.SessionLifecycleListener;
-import org.exoplatform.services.jcr.datamodel.NodeData;
-import org.exoplatform.services.jcr.impl.core.NodeImpl;
-
/**
* Created by The eXo Platform SAS.
*
@@ -33,58 +24,7 @@
* @author <a href="mailto:alex.reshetnyak@exoplatform.com.ua">Alex Reshetnyak</a>
* @version $Id$
*/
-public abstract class AbstractLockManager implements SessionLifecycleListener, LockManager
+public abstract class AbstractLockManager implements LockManager
{
-
- /**
- * {@inheritDoc}
- */
- public abstract void onCloseSession(ExtendedSession session);
-
- /**
- * {@inheritDoc}
- */
- public abstract void addLockToken(String sessionId, String lt);
-
- /**
- * {@inheritDoc}
- */
- public abstract Lock addPendingLock(NodeImpl node, boolean isDeep, boolean isSessionScoped, long timeOut)
- throws LockException, RepositoryException;
-
- /**
- * {@inheritDoc}
- */
- public abstract LockImpl getLock(NodeImpl node) throws LockException, RepositoryException;
-
- /**
- * {@inheritDoc}
- */
- public abstract String[] getLockTokens(String sessionID);
-
- /**
- * {@inheritDoc}
- */
- public abstract boolean holdsLock(NodeData node) throws RepositoryException;
-
- /**
- * {@inheritDoc}
- */
- public abstract boolean isLockHolder(NodeImpl node) throws RepositoryException;
-
- /**
- * {@inheritDoc}
- */
- public abstract boolean isLocked(NodeData node);
-
- /**
- * {@inheritDoc}
- */
- public abstract void removeExpired();
-
- /**
- * {@inheritDoc}
- */
- public abstract void removeLockToken(String sessionId, String lt);
-
+ //TODO remove this class
}
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/LockManager.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/LockManager.java 2010-01-18 08:39:04 UTC (rev 1455)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/LockManager.java 2010-01-18 08:53:57 UTC (rev 1456)
@@ -18,13 +18,6 @@
*/
package org.exoplatform.services.jcr.impl.core.lock;
-import org.exoplatform.services.jcr.datamodel.NodeData;
-import org.exoplatform.services.jcr.impl.core.NodeImpl;
-
-import javax.jcr.RepositoryException;
-import javax.jcr.lock.Lock;
-import javax.jcr.lock.LockException;
-
/**
* @author <a href="mailto:Sergey.Kabashnyuk@gmail.com">Sergey Kabashnyuk</a>
* @version $Id: LockManager.java 11907 2008-03-13 15:36:21Z ksm $
@@ -32,85 +25,15 @@
public interface LockManager
{
/**
- * Invoked by a session to inform that a lock token has been added.
- *
- * @param session
- * session that has a added lock token
- * @param lt
- * added lock token
+ * Remove expired locks. Called by LockRemover timer.
*/
- public void addLockToken(String sessionId, String lt);
+ void removeExpired();
- public Lock addPendingLock(NodeImpl node, boolean isDeep, boolean isSessionScoped, long timeOut)
- throws LockException, RepositoryException;
-
/**
- * Returns the Lock object that applies to a node. This may be either a lock on this node itself
- * or a deep lock on a node above this node.
+ * Returns session lock manager that interact with this LockManager.
*
- * @param node
- * node
- * @return lock object
- * @throws LockException
- * if this node is not locked
- * @see javax.jcr.Node#getLock
+ * @param sessionId - sessionId
+ * @return
*/
- public LockImpl getLock(NodeImpl node) throws LockException, RepositoryException;
-
- /**
- * Return lock tokens enshrined by session
- *
- * @param sessionID
- * - Id of session.
- * @return array of lock tokens.
- */
- public String[] getLockTokens(String sessionID);
-
- /**
- * Returns <code>true</code> if the node given holds a lock; otherwise returns <code>false</code>.
- *
- * @param node
- * node
- * @return <code>true</code> if the node given holds a lock; otherwise returns <code>false</code>
- * @see javax.jcr.Node#holdsLock
- */
- public boolean holdsLock(NodeData node) throws RepositoryException;
-
- /**
- * Returns <code>true</code> if this node is locked either as a result of a lock held by this node
- * or by a deep lock on a node above this node; otherwise returns <code>false</code>
- *
- * @param node
- * node
- * @return <code>true</code> if this node is locked either as a result of a lock held by this node
- * or by a deep lock on a node above this node; otherwise returns <code>false</code>
- * @see javax.jcr.Node#isLocked
- */
- public boolean isLocked(NodeData node);
-
- /**
- * Returns <code>true</code> if the specified session holds a lock on the given node; otherwise
- * returns <code>false</code>. <p/> Note that <code>isLockHolder(session, node)==true</code>
- * implies <code>holdsLock(node)==true</code>.
- *
- * @param session
- * session
- * @param node
- * node
- * @return if the specified session holds a lock on the given node; otherwise returns
- * <code>false</code>
- */
- public boolean isLockHolder(NodeImpl node) throws RepositoryException;
-
- /**
- * Invoked by a session to inform that a lock token has been removed.
- *
- * @param session
- * session that has a removed lock token
- * @param lt
- * removed lock token
- */
- public void removeLockToken(String sessionId, String lt);
-
- public void removeExpired();
+ SessionLockManager getSessionLockManager(String sessionId);
}
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/LockManagerImpl.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/LockManagerImpl.java 2010-01-18 08:39:04 UTC (rev 1455)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/LockManagerImpl.java 2010-01-18 08:53:57 UTC (rev 1456)
@@ -18,21 +18,6 @@
*/
package org.exoplatform.services.jcr.impl.core.lock;
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import javax.jcr.AccessDeniedException;
-import javax.jcr.RepositoryException;
-import javax.jcr.UnsupportedRepositoryOperationException;
-import javax.jcr.lock.Lock;
-import javax.jcr.lock.LockException;
-
import org.exoplatform.management.annotations.Managed;
import org.exoplatform.management.annotations.ManagedDescription;
import org.exoplatform.management.jmx.annotations.NameTemplate;
@@ -66,6 +51,21 @@
import org.exoplatform.services.log.Log;
import org.picocontainer.Startable;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.jcr.AccessDeniedException;
+import javax.jcr.RepositoryException;
+import javax.jcr.UnsupportedRepositoryOperationException;
+import javax.jcr.lock.Lock;
+import javax.jcr.lock.LockException;
+
/**
* Created by The eXo Platform SAS.
*
@@ -793,4 +793,9 @@
{
return true;
}
+
+ public SessionLockManager getSessionLockManager(String sessionId)
+ {
+ return new SessionLockManagerImpl(sessionId, this);
+ }
}
Added: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/SessionLockManager.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/SessionLockManager.java (rev 0)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/SessionLockManager.java 2010-01-18 08:53:57 UTC (rev 1456)
@@ -0,0 +1,117 @@
+/*
+ * Copyright (C) 2003-2010 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.services.jcr.impl.core.lock;
+
+import org.exoplatform.services.jcr.core.SessionLifecycleListener;
+import org.exoplatform.services.jcr.datamodel.NodeData;
+import org.exoplatform.services.jcr.impl.core.NodeImpl;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.lock.Lock;
+import javax.jcr.lock.LockException;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * <br/>Date:
+ *
+ * @author <a href="karpenko.sergiy(a)gmail.com">Karpenko Sergiy</a>
+ * @version $Id: SessionLockManager.java 111 2008-11-11 11:11:11Z serg $
+ */
+public interface SessionLockManager extends SessionLifecycleListener
+{
+
+ /**
+ * Invoked by a session to inform that a lock token has been added.
+ *
+ * @param lt
+ * added lock token
+ */
+ void addLockToken(String lt);
+
+ Lock addLock(NodeImpl node, boolean isDeep, boolean isSessionScoped, long timeOut) throws LockException,
+ RepositoryException;
+
+ /**
+ * Returns the Lock object that applies to a node. This may be either a lock on this node itself
+ * or a deep lock on a node above this node.
+ *
+ * @param node
+ * node
+ * @return lock object
+ * @throws LockException
+ * if this node is not locked
+ * @see javax.jcr.Node#getLock
+ */
+ LockImpl getLock(NodeImpl node) throws LockException, RepositoryException;
+
+ /**
+ * Return lock tokens enshrined by session
+ *
+ * @param sessionID
+ * - Id of session.
+ * @return array of lock tokens.
+ */
+ String[] getLockTokens();
+
+ /**
+ * Returns <code>true</code> if the node given holds a lock; otherwise returns <code>false</code>.
+ *
+ * @param node
+ * node
+ * @return <code>true</code> if the node given holds a lock; otherwise returns <code>false</code>
+ * @see javax.jcr.Node#holdsLock
+ */
+ boolean holdsLock(NodeData node) throws RepositoryException;
+
+ /**
+ * Returns <code>true</code> if this node is locked either as a result of a lock held by this node
+ * or by a deep lock on a node above this node; otherwise returns <code>false</code>
+ *
+ * @param node
+ * node
+ * @return <code>true</code> if this node is locked either as a result of a lock held by this node
+ * or by a deep lock on a node above this node; otherwise returns <code>false</code>
+ * @see javax.jcr.Node#isLocked
+ */
+ boolean isLocked(NodeData node);
+
+ /**
+ * Returns <code>true</code> if the specified session holds a lock on the given node; otherwise
+ * returns <code>false</code>. <p/> Note that <code>isLockHolder(session, node)==true</code>
+ * implies <code>holdsLock(node)==true</code>.
+ *
+ * @param session
+ * session
+ * @param node
+ * node
+ * @return if the specified session holds a lock on the given node; otherwise returns
+ * <code>false</code>
+ */
+ boolean isLockHolder(NodeImpl node) throws RepositoryException;
+
+ /**
+ * Invoked by a session to inform that a lock token has been removed.
+ *
+ * @param session
+ * session that has a removed lock token
+ * @param lt
+ * removed lock token
+ */
+ void removeLockToken(String lt);
+
+}
Added: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/SessionLockManagerImpl.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/SessionLockManagerImpl.java (rev 0)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/SessionLockManagerImpl.java 2010-01-18 08:53:57 UTC (rev 1456)
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2003-2010 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.services.jcr.impl.core.lock;
+
+import org.exoplatform.services.jcr.core.ExtendedSession;
+import org.exoplatform.services.jcr.datamodel.NodeData;
+import org.exoplatform.services.jcr.impl.core.NodeImpl;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.lock.Lock;
+import javax.jcr.lock.LockException;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * <br/>Date:
+ *
+ * @author <a href="karpenko.sergiy(a)gmail.com">Karpenko Sergiy</a>
+ * @version $Id: SessionLockManagerImpl.java 111 2008-11-11 11:11:11Z serg $
+ */
+public class SessionLockManagerImpl implements SessionLockManager
+{
+
+ private final String sessionId;
+
+ private final LockManagerImpl lockManager;
+
+ public SessionLockManagerImpl(String sessionId, LockManagerImpl lockManager)
+ {
+ this.sessionId = sessionId;
+ this.lockManager = lockManager;
+ }
+
+ public Lock addLock(NodeImpl node, boolean isDeep, boolean isSessionScoped, long timeOut) throws LockException,
+ RepositoryException
+ {
+ return lockManager.addPendingLock(node, isDeep, isSessionScoped, timeOut);
+ }
+
+ public void addLockToken(String lt)
+ {
+ lockManager.addLockToken(sessionId, lt);
+ }
+
+ public LockImpl getLock(NodeImpl node) throws LockException, RepositoryException
+ {
+ return lockManager.getLock(node);
+ }
+
+ public String[] getLockTokens()
+ {
+ return lockManager.getLockTokens(sessionId);
+ }
+
+ public boolean holdsLock(NodeData node) throws RepositoryException
+ {
+ return lockManager.holdsLock(node);
+ }
+
+ public boolean isLockHolder(NodeImpl node) throws RepositoryException
+ {
+ return lockManager.isLockHolder(node);
+ }
+
+ public boolean isLocked(NodeData node)
+ {
+ return lockManager.isLocked(node);
+ }
+
+ public void removeLockToken(String lt)
+ {
+ lockManager.removeLockToken(sessionId, lt);
+ }
+
+ public void onCloseSession(ExtendedSession session)
+ {
+ lockManager.onCloseSession(session);
+ }
+
+}
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheLockImpl.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheLockImpl.java 2010-01-18 08:39:04 UTC (rev 1455)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheLockImpl.java 2010-01-18 08:53:57 UTC (rev 1456)
@@ -39,7 +39,7 @@
private SessionImpl session;
- private CacheableLockManager lockManager;
+ private CacheableSessionLockManager lockManager;
/**
* Constructor.
@@ -48,7 +48,7 @@
* @param lockData - LockData
* @param lockManager - CacheableLockManager
*/
- public CacheLockImpl(SessionImpl session, LockData lockData, CacheableLockManager lockManager)
+ public CacheLockImpl(SessionImpl session, LockData lockData, CacheableSessionLockManager lockManager)
{
this.lockData = lockData;
this.session = session;
@@ -69,7 +69,7 @@
*/
public String getLockToken()
{
- return lockManager.getLockToken(session.getId(), lockData.getTokenHash());
+ return lockManager.getLockToken(lockData.getTokenHash());
}
/**
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManager.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManager.java 2010-01-18 08:39:04 UTC (rev 1455)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManager.java 2010-01-18 08:53:57 UTC (rev 1456)
@@ -24,7 +24,6 @@
import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
import org.exoplatform.services.jcr.config.SimpleParameterEntry;
import org.exoplatform.services.jcr.config.WorkspaceEntry;
-import org.exoplatform.services.jcr.core.ExtendedSession;
import org.exoplatform.services.jcr.dataflow.ChangesLogIterator;
import org.exoplatform.services.jcr.dataflow.CompositeChangesLog;
import org.exoplatform.services.jcr.dataflow.DataManager;
@@ -40,16 +39,14 @@
import org.exoplatform.services.jcr.datamodel.QPathEntry;
import org.exoplatform.services.jcr.impl.Constants;
import org.exoplatform.services.jcr.impl.core.NodeImpl;
-import org.exoplatform.services.jcr.impl.core.SessionImpl;
import org.exoplatform.services.jcr.impl.core.lock.AbstractLockManager;
-import org.exoplatform.services.jcr.impl.core.lock.LockImpl;
import org.exoplatform.services.jcr.impl.core.lock.LockPersister;
import org.exoplatform.services.jcr.impl.core.lock.LockRemover;
+import org.exoplatform.services.jcr.impl.core.lock.SessionLockManager;
import org.exoplatform.services.jcr.impl.dataflow.TransientItemData;
import org.exoplatform.services.jcr.impl.dataflow.TransientPropertyData;
import org.exoplatform.services.jcr.impl.dataflow.persistent.WorkspacePersistentDataManager;
import org.exoplatform.services.jcr.observation.ExtendedEvent;
-import org.exoplatform.services.jcr.util.IdGenerator;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
import org.jboss.cache.Cache;
@@ -70,10 +67,7 @@
import java.util.Map;
import java.util.Set;
-import javax.jcr.AccessDeniedException;
import javax.jcr.RepositoryException;
-import javax.jcr.UnsupportedRepositoryOperationException;
-import javax.jcr.lock.Lock;
import javax.jcr.lock.LockException;
/**
@@ -107,17 +101,17 @@
/**
* The exact lock token.
*/
- private static final int SEARCH_EXECMATCH = 1;
+ protected static final int SEARCH_EXECMATCH = 1;
/**
* Lock token of closed parent
*/
- private static final int SEARCH_CLOSEDPARENT = 2;
+ protected static final int SEARCH_CLOSEDPARENT = 2;
/**
* Lock token of closed child
*/
- private static final int SEARCH_CLOSEDCHILD = 4;
+ protected static final int SEARCH_CLOSEDCHILD = 4;
/**
* Name of lock root in jboss-cache.
@@ -145,11 +139,6 @@
private final Map<String, LockData> pendingLocks;
/**
- * [session id , [lock token hash, lock tokens id]]
- */
- private final Map<String, Map<String, String>> lockTokenHolders;
-
- /**
* Run time lock time out.
*/
private long lockTimeOut;
@@ -198,7 +187,6 @@
else
lockTimeOut = DEFAULT_LOCK_TIMEOUT;
- lockTokenHolders = new HashMap<String, Map<String, String>>();
pendingLocks = new HashMap<String, LockData>();
dataManager.addItemPersistenceListener(this);
@@ -225,53 +213,12 @@
/*
* (non-Javadoc)
* @see
- * org.exoplatform.services.jcr.impl.core.lock.LockManager#lockTokenAdded(org.exoplatform.services
- * .jcr.impl.core.SessionImpl, java.lang.String)
- */
- public synchronized void addLockToken(String sessionId, String lt)
- {
- holdLockToken(sessionId, getHash(lt), lt);
- }
-
- /*
- * (non-Javadoc)
- * @see
* org.exoplatform.services.jcr.impl.core.lock.LockManager#addPendingLock(org.exoplatform.services
* .jcr.impl.core.NodeImpl, boolean, boolean, long)
*/
- public synchronized Lock addPendingLock(NodeImpl node, boolean isDeep, boolean isSessionScoped, long timeOut)
- throws LockException
+ public synchronized void addPendingLock(String nodeIdentifier, LockData lData)
{
- LockData lData = getLockData((NodeData)node.getData(), SEARCH_EXECMATCH | SEARCH_CLOSEDPARENT);
- if (lData != null)
- {
- if (lData.getNodeIdentifier().equals(node.getInternalIdentifier()))
- {
- throw new LockException("Node already locked: " + node.getData().getQPath());
- }
- else if (lData.isDeep())
- {
- throw new LockException("Parent node has deep lock.");
- }
- }
-
- if (isDeep && getLockData((NodeData)node.getData(), SEARCH_CLOSEDCHILD) != null)
- {
- throw new LockException("Some child node is locked.");
- }
-
- String lockToken = IdGenerator.generate();
- String lockTokenHash = getHash(lockToken);
-
- lData =
- new LockData(node.getInternalIdentifier(), lockTokenHash, isDeep, isSessionScoped, node.getSession()
- .getUserID(), timeOut > 0 ? timeOut : lockTimeOut);
-
- holdLockToken(node.getSession().getId(), lockTokenHash, lockToken);
- pendingLocks.put(node.getInternalIdentifier(), lData);
-
- LockImpl lock = new CacheLockImpl(node.getSession(), lData, this);
- return lock;
+ pendingLocks.put(nodeIdentifier, lData);
}
@Managed
@@ -281,13 +228,18 @@
removeExpired();
}
+ public long getDefaultLockTimeOut()
+ {
+ return lockTimeOut;
+ }
+
/*
* (non-Javadoc)
* @see
* org.exoplatform.services.jcr.impl.core.lock.LockManager#getLock(org.exoplatform.services.jcr
* .impl.core.NodeImpl)
*/
- public LockImpl getLock(NodeImpl node) throws LockException, RepositoryException
+ public LockData getLockData(NodeImpl node) throws LockException, RepositoryException
{
LockData lData = getLockData((NodeData)node.getData(), SEARCH_EXECMATCH | SEARCH_CLOSEDPARENT);
@@ -296,29 +248,9 @@
{
throw new LockException("Node not locked: " + node.getData().getQPath());
}
- return new CacheLockImpl(node.getSession(), lData, this);
+ return lData;
}
- /*
- * (non-Javadoc)
- * @see org.exoplatform.services.jcr.impl.core.lock.LockManager#getLockTokens(java.lang.String)
- */
- public synchronized String[] getLockTokens(String sessionID)
- {
- Map<String, String> lockTokens = lockTokenHolders.get(sessionID);
-
- if (lockTokens != null)
- {
- String[] arr = new String[lockTokens.size()];
- lockTokens.values().toArray(arr);
- return arr;
- }
- else
- {
- return new String[0];
- }
- }
-
@Managed
@ManagedDescription("The number of active locks")
public int getNumLocks()
@@ -326,44 +258,23 @@
return lockRoot.getChildrenNames().size();
}
- /*
- * (non-Javadoc)
- * @see
- * org.exoplatform.services.jcr.impl.core.lock.LockManager#holdsLock(org.exoplatform.services.
- * jcr.impl.core.NodeImpl)
+ /**
+ *
*/
- public boolean holdsLock(NodeData node) throws RepositoryException
+ public SessionLockManager getSessionLockManager(String sessionId)
{
- return getLockData(node, SEARCH_EXECMATCH) != null;
+ CacheableSessionLockManager sessionManager = new CacheableSessionLockManager(sessionId, this);
+ return sessionManager;
}
- /*
- * (non-Javadoc)
- * @see
- * org.exoplatform.services.jcr.impl.core.lock.LockManager#isLocked(org.exoplatform.services.jcr
- * .datamodel.NodeData)
- */
- public boolean isLocked(NodeData node)
+ public boolean isLockLive(String nodeId)
{
- LockData lData = getLockData(node, SEARCH_EXECMATCH | SEARCH_CLOSEDPARENT);
-
- if (lData == null || (!node.getIdentifier().equals(lData.getNodeIdentifier()) && !lData.isDeep()))
+ if (pendingLocks.containsKey(nodeId) || lockRoot.hasChild(Fqn.fromString(nodeId)))
{
- return false;
+ return true;
}
- return true;
- }
- /*
- * (non-Javadoc)
- * @see
- * org.exoplatform.services.jcr.impl.core.lock.LockManager#isLockHolder(org.exoplatform.services
- * .jcr.impl.core.NodeImpl)
- */
- public boolean isLockHolder(NodeImpl node) throws RepositoryException
- {
- LockData lData = getLockData((NodeData)node.getData(), SEARCH_EXECMATCH | SEARCH_CLOSEDPARENT);
- return lData != null && isLockHolder(node.getSession().getId(), lData.getTokenHash());
+ return false;
}
/**
@@ -376,56 +287,6 @@
/*
* (non-Javadoc)
- * @see
- * org.exoplatform.services.jcr.core.SessionLifecycleListener#onCloseSession(org.exoplatform.services
- * .jcr.core.ExtendedSession)
- */
- public synchronized void onCloseSession(ExtendedSession session)
- {
- SessionImpl sessionImpl = (SessionImpl)session;
-
- for (LockData lockData : getLockList())
- {
- // check is lock holder
- if (lockTokenHolders.containsKey(session.getId())
- && lockTokenHolders.get(session.getId()).containsKey(lockData.getTokenHash()))
- {
- if (lockData.isSessionScoped())
- {
- // if no session currently holds lock except this
- try
- {
- ((NodeImpl)sessionImpl.getTransientNodesManager().getItemByIdentifier(lockData.getNodeIdentifier(),
- false)).unlock();
- }
- catch (UnsupportedRepositoryOperationException e)
- {
- log.error(e.getLocalizedMessage());
- }
- catch (LockException e)
- {
- log.error(e.getLocalizedMessage());
- }
- catch (AccessDeniedException e)
- {
- log.error(e.getLocalizedMessage());
- }
- catch (RepositoryException e)
- {
- log.error(e.getLocalizedMessage());
- }
-
- }
- else
- {
- removeLockTokenByHash(session.getId(), lockData.getTokenHash());
- }
- }
- }
- }
-
- /*
- * (non-Javadoc)
* @seeorg.exoplatform.services.jcr.dataflow.persistent.ItemsPersistenceListener#onSaveItems(org.
* exoplatform.services.jcr.dataflow.ItemStateChangesLog)
*/
@@ -573,36 +434,11 @@
}
}
- /*
- * (non-Javadoc)
- * @see
- * org.exoplatform.services.jcr.impl.core.lock.LockManager#lockTokenRemoved(org.exoplatform.services
- * .jcr.impl.core.SessionImpl, java.lang.String)
- */
- public synchronized void removeLockToken(String sessionId, String lt)
+ public void removePendingLock(String nodeId)
{
- if (lockTokenHolders.containsKey(sessionId) && lockTokenHolders.get(sessionId).containsValue(lt))
- {
- lockTokenHolders.get(sessionId).remove(getHash(lt));
- if (lockTokenHolders.get(sessionId).size() == 0)
- {
- lockTokenHolders.remove(sessionId);
- }
- }
+ pendingLocks.remove(nodeId);
}
- public synchronized void removeLockTokenByHash(String sessionId, String ltHash)
- {
- if (lockTokenHolders.containsKey(sessionId) && lockTokenHolders.get(sessionId).containsKey(ltHash))
- {
- lockTokenHolders.get(sessionId).remove(ltHash);
- if (lockTokenHolders.get(sessionId).size() == 0)
- {
- lockTokenHolders.remove(sessionId);
- }
- }
- }
-
/*
* (non-Javadoc)
* @see org.picocontainer.Startable#start()
@@ -610,7 +446,6 @@
public void start()
{
cache.start();
- //tokenRoot = cache.getRoot().addChild(Fqn.fromString(TOKENS));
lockRoot = cache.getRoot().addChild(Fqn.fromString(LOCKS));
lockRoot.setResident(true);
lockRemover = new LockRemover(this);
@@ -625,14 +460,6 @@
lockRemover.halt();
lockRemover.interrupt();
pendingLocks.clear();
-
- // clear lockTokenHolders
- for (String sessionId : lockTokenHolders.keySet())
- {
- lockTokenHolders.get(sessionId).clear();
- }
- lockTokenHolders.clear();
-
cache.stop();
}
@@ -658,12 +485,70 @@
}
/**
+ * Internal lock
+ *
+ * @param nodeIdentifier
+ * @throws LockException
+ */
+ private synchronized void internalLock(String nodeIdentifier) throws LockException
+ {
+ LockData lockData = pendingLocks.get(nodeIdentifier);
+ if (lockData != null)
+ {
+ Fqn<String> lockPath = Fqn.fromString(lockData.getNodeIdentifier());
+
+ // addChild will add if absent or return old if present
+ Node<Serializable, Object> node = lockRoot.addChild(lockPath);
+
+ // this will prevent from deleting by eviction.
+ node.setResident(true);
+
+ // this will return null if success. And old data if something exists...
+ LockData oldLockData = (LockData)node.putIfAbsent(LOCK_DATA, lockData);
+
+ if (oldLockData != null)
+ {
+ throw new LockException("Unable to write LockData. Node [" + lockData.getNodeIdentifier()
+ + "] already has LockData!");
+ }
+ pendingLocks.remove(nodeIdentifier);
+ }
+ else
+ {
+ throw new LockException("No lock in pending locks");
+ }
+ }
+
+ /**
+ * Internal unlock.
+ *
+ * @param sessionId
+ * @param nodeIdentifier
+ * @throws LockException
+ */
+ private synchronized void internalUnLock(String sessionId, String nodeIdentifier) throws LockException
+ {
+ LockData lData = getLockDataById(nodeIdentifier);
+
+ if (lData != null)
+ {
+ lockRoot.removeChild(Fqn.fromString(nodeIdentifier));
+ // TODO pair nodeId and lockData is not removed from CacheableSessionLockManager
+ }
+ }
+
+ private boolean lockExist(String nodeId)
+ {
+ return lockRoot.hasChild(Fqn.fromString(nodeId));
+ }
+
+ /**
* Calculates md5 hash of string.
*
* @param token
* @return
*/
- private String getHash(String token)
+ protected String getHash(String token)
{
String hash = "";
try
@@ -686,7 +571,7 @@
* @param searchType
* @return
*/
- private LockData getLockData(NodeData data, int searchType)
+ protected LockData getLockData(NodeData data, int searchType)
{
if (data == null)
return null;
@@ -741,122 +626,6 @@
return retval;
}
- private void holdLockToken(String sessionId, String ltHash, String lt)
- {
- if (lockTokenHolders.get(sessionId) == null)
- {
- lockTokenHolders.put(sessionId, new HashMap<String, String>());
- }
- // put token hash and token
- lockTokenHolders.get(sessionId).put(ltHash, lt);
- }
-
- /**
- * Internal lock
- *
- * @param nodeIdentifier
- * @throws LockException
- */
- private synchronized void internalLock(String nodeIdentifier) throws LockException
- {
- LockData lockData = pendingLocks.get(nodeIdentifier);
- if (lockData != null)
- {
- Fqn<String> lockPath = Fqn.fromString(lockData.getNodeIdentifier());
-
- // addChild will add if absent or return old if present
- Node<Serializable, Object> node = lockRoot.addChild(lockPath);
-
- // this will prevent from deleting by eviction.
- node.setResident(true);
-
- // this will return null if success. And old data if something exists...
- LockData oldLockData = (LockData)node.putIfAbsent(LOCK_DATA, lockData);
-
- if (oldLockData != null)
- {
- throw new LockException("Unable to write LockData. Node [" + lockData.getNodeIdentifier()
- + "] already has LockData!");
- }
- pendingLocks.remove(nodeIdentifier);
- }
- else
- {
- throw new LockException("No lock in pending locks");
- }
- }
-
- /**
- * For locks comes from remote JCRs (replication usecase)
- *
- * @param sessionId
- * String
- * @param nodeIdentifier
- * String
- * @param lockToken
- * String
- * @param isDeep
- * boolean
- * @param sessionScoped
- * boolean
- * @param owner
- * String
- * @return LockData
- */
- // private synchronized LockData createRemoteLock(String sessionId, String nodeIdentifier, String lockToken,
- // boolean isDeep, boolean sessionScoped, String owner)
- // {
- // LockData lData = new LockData(nodeIdentifier, lockToken, isDeep, sessionScoped, owner, lockTimeOut);
- // lData.addLockHolder(sessionId);
- // locks.put(nodeIdentifier, lData);
- // tokensMap.put(lockToken, lData);
- //
- // return lData;
- // }
-
- /**
- * Internal unlock.
- *
- * @param sessionId
- * @param nodeIdentifier
- * @throws LockException
- */
- private synchronized void internalUnLock(String sessionId, String nodeIdentifier) throws LockException
- {
- LockData lData = getLockDataById(nodeIdentifier);
-
- if (lData != null)
- {
- //tokenRoot.removeChild(Fqn.fromString(lData.getToken()));
- lockRoot.removeChild(Fqn.fromString(nodeIdentifier));
-
- // remove session holder
- if (lockTokenHolders.containsKey(sessionId))
- {
- lockTokenHolders.get(sessionId).remove(lData.getTokenHash());
- if (lockTokenHolders.get(sessionId).size() == 0)
- {
- lockTokenHolders.remove(sessionId);
- }
- }
- }
- }
-
- private boolean isLockHolder(String sessionId, String lockTokenHash)
- {
- Map<String, String> lockTokens = lockTokenHolders.get(sessionId);
- if (lockTokens != null)
- {
- return lockTokens.containsKey(lockTokenHash);
- }
- return false;
- }
-
- private boolean lockExist(String nodeId)
- {
- return lockRoot.hasChild(Fqn.fromString(nodeId));
- }
-
protected LockData getLockDataById(String nodeId)
{
LockData lockData = null;
@@ -920,26 +689,4 @@
log.error("Error occur during removing lock" + e.getLocalizedMessage(), e);
}
}
-
- public String getLockToken(String sessionId, String tokenHash)
- {
- if (lockTokenHolders.containsKey(sessionId))
- {
- return lockTokenHolders.get(sessionId).get(tokenHash);
- }
- else
- {
- return null;
- }
- }
-
- public boolean isLockLive(String nodeId)
- {
- if (pendingLocks.containsKey(nodeId) || lockRoot.hasChild(Fqn.fromString(nodeId)))
- {
- return true;
- }
-
- return false;
- }
}
Added: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableSessionLockManager.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableSessionLockManager.java (rev 0)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableSessionLockManager.java 2010-01-18 08:53:57 UTC (rev 1456)
@@ -0,0 +1,275 @@
+/*
+ * Copyright (C) 2003-2010 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.services.jcr.impl.core.lock.jbosscache;
+
+import org.exoplatform.services.jcr.access.SystemIdentity;
+import org.exoplatform.services.jcr.core.ExtendedSession;
+import org.exoplatform.services.jcr.datamodel.NodeData;
+import org.exoplatform.services.jcr.impl.core.NodeImpl;
+import org.exoplatform.services.jcr.impl.core.SessionImpl;
+import org.exoplatform.services.jcr.impl.core.lock.LockImpl;
+import org.exoplatform.services.jcr.impl.core.lock.SessionLockManager;
+import org.exoplatform.services.jcr.util.IdGenerator;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.jcr.AccessDeniedException;
+import javax.jcr.RepositoryException;
+import javax.jcr.UnsupportedRepositoryOperationException;
+import javax.jcr.lock.Lock;
+import javax.jcr.lock.LockException;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * <br/>Date:
+ *
+ * @author <a href="karpenko.sergiy(a)gmail.com">Karpenko Sergiy</a>
+ * @version $Id: SessionLockManager.java 111 2008-11-11 11:11:11Z serg $
+ */
+public class CacheableSessionLockManager implements SessionLockManager
+{
+ /**
+ * Logger
+ */
+ private final Log log = ExoLogger.getLogger("jcr.lock.SessionLockManager");
+
+ private final String sessionID;
+
+ /**
+ * [token name, tokens hash]
+ */
+ private final Map<String, String> tokens;
+
+ private final Map<String, LockData> lockedNodes;
+
+ private final CacheableLockManager lockManager;
+
+ public CacheableSessionLockManager(String sessionID, CacheableLockManager lockManager)
+ {
+ this.sessionID = sessionID;
+ this.tokens = new HashMap<String, String>();
+ this.lockedNodes = new HashMap<String, LockData>();
+ this.lockManager = lockManager;
+ }
+
+ public Lock addLock(NodeImpl node, boolean isDeep, boolean isSessionScoped, long timeOut) throws LockException,
+ RepositoryException
+ {
+
+ String nodeIdentifier = node.getInternalIdentifier();
+ LockData lData =
+ lockManager.getLockData((NodeData)node.getData(), CacheableLockManager.SEARCH_EXECMATCH
+ | CacheableLockManager.SEARCH_CLOSEDPARENT);
+ if (lData != null)
+ {
+ if (lData.getNodeIdentifier().equals(node.getInternalIdentifier()))
+ {
+ throw new LockException("Node already locked: " + node.getData().getQPath());
+ }
+ else if (lData.isDeep())
+ {
+ throw new LockException("Parent node has deep lock.");
+ }
+ }
+
+ if (isDeep && lockManager.getLockData((NodeData)node.getData(), CacheableLockManager.SEARCH_CLOSEDCHILD) != null)
+ {
+ throw new LockException("Some child node is locked.");
+ }
+
+ String lockToken = IdGenerator.generate();
+ String lockTokenHash = lockManager.getHash(lockToken);
+
+ lData =
+ new LockData(nodeIdentifier, lockTokenHash, isDeep, isSessionScoped, node.getSession().getUserID(),
+ timeOut > 0 ? timeOut : lockManager.getDefaultLockTimeOut());
+
+ lockedNodes.put(node.getInternalIdentifier(), lData);
+ lockManager.addPendingLock(nodeIdentifier, lData);
+ tokens.put(lockToken, lockTokenHash);
+
+ LockImpl lock = new CacheLockImpl(node.getSession(), lData, this);
+
+ return lock;
+
+ }
+
+ public void addLockToken(String lt)
+ {
+ tokens.put(lt, lockManager.getHash(lt));
+ }
+
+ public LockImpl getLock(NodeImpl node) throws LockException, RepositoryException
+ {
+ LockData lData =
+ lockManager.getLockData((NodeData)node.getData(), CacheableLockManager.SEARCH_EXECMATCH
+ | CacheableLockManager.SEARCH_CLOSEDPARENT);
+
+ if (lData == null || (!node.getInternalIdentifier().equals(lData.getNodeIdentifier()) && !lData.isDeep()))
+ {
+ throw new LockException("Node not locked: " + node.getData().getQPath());
+ }
+ return new CacheLockImpl(node.getSession(), lData, this);
+ }
+
+ public String[] getLockTokens()
+ {
+ String[] arr = new String[tokens.size()];
+ tokens.keySet().toArray(arr);
+ return arr;
+ }
+
+ public boolean holdsLock(NodeData node) throws RepositoryException
+ {
+ return lockManager.getLockData(node, CacheableLockManager.SEARCH_EXECMATCH) != null;
+ }
+
+ public boolean isLocked(NodeData node)
+ {
+ LockData lData =
+ lockManager
+ .getLockData(node, CacheableLockManager.SEARCH_EXECMATCH | CacheableLockManager.SEARCH_CLOSEDPARENT);
+
+ if (lData == null || (!node.getIdentifier().equals(lData.getNodeIdentifier()) && !lData.isDeep()))
+ {
+ return false;
+ }
+ return true;
+ }
+
+ public boolean isLockHolder(NodeImpl node) throws RepositoryException
+ {
+ LockData lData =
+ lockManager.getLockData((NodeData)node.getData(), CacheableLockManager.SEARCH_EXECMATCH
+ | CacheableLockManager.SEARCH_CLOSEDPARENT);
+
+ return lData != null && isLockHolder(lData);
+ }
+
+ public void onCloseSession(ExtendedSession session)
+ {
+ SessionImpl sessionImpl = (SessionImpl)session;
+
+ String[] nodeIds = new String[lockedNodes.size()];
+ lockedNodes.keySet().toArray(nodeIds);
+
+ for (String nodeId : nodeIds)
+ {
+ LockData lock = lockedNodes.remove(nodeId);
+
+ if (lock.isSessionScoped())
+ {
+ try
+ {
+ NodeImpl node =
+ ((NodeImpl)sessionImpl.getTransientNodesManager()
+ .getItemByIdentifier(lock.getNodeIdentifier(), false));
+
+ // Node may be null, since cacheablelockManger.internalUnlock does not modify
+ // SessionLockManager.lockedNodes map. So Node and Lock is removed, but exist in lockedNodes list.
+ if (node != null)
+ {
+ node.unlock();
+ }
+
+ }
+ catch (UnsupportedRepositoryOperationException e)
+ {
+ log.error(e.getLocalizedMessage());
+ }
+ catch (LockException e)
+ {
+ log.error(e.getLocalizedMessage());
+ }
+ catch (AccessDeniedException e)
+ {
+ log.error(e.getLocalizedMessage());
+ }
+ catch (RepositoryException e)
+ {
+ log.error(e.getLocalizedMessage());
+ }
+ }
+ else
+ {
+ lockManager.removePendingLock(nodeId);
+
+ lockedNodes.remove(nodeId);
+
+ //remove token
+ String hash = lock.getTokenHash();
+ for (String token : tokens.keySet())
+ {
+ if (tokens.get(token).equals(hash))
+ {
+ tokens.remove(token);
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ public void removeLockToken(String lt)
+ {
+ tokens.remove(lt);
+ }
+
+ /**
+ * Checks if session has token to this lock data or session is System.
+ *
+ * @param lockData
+ * @return
+ */
+ private boolean isLockHolder(LockData lockData)
+ {
+ return (SystemIdentity.SYSTEM.equals(sessionID) || tokens.containsValue(lockData.getTokenHash()));
+ }
+
+ /**
+ * Returns real token, if session has it
+ *
+ * @param lockData
+ * @return
+ */
+ protected String getLockToken(String tokenHash)
+ {
+ for (String token : tokens.keySet())
+ {
+ if (tokens.get(token).equals(tokenHash))
+ {
+ return token;
+ }
+ }
+ return null;
+ }
+
+ protected boolean isLockLive(String nodeIdentifier)
+ {
+ return lockManager.isLockLive(nodeIdentifier);
+ }
+
+ protected void refresh(LockData newLockData) throws LockException
+ {
+ lockManager.refresh(newLockData);
+ }
+
+}
16 years, 3 months