exo-jcr SVN: r1405 - 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-15 07:48:11 -0500 (Fri, 15 Jan 2010)
New Revision: 1405
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/JBossCacheWorkspaceStorageCache.java
Log:
EXOJCR-391: Initial impl of code, managing list of child-items as serialized sets.
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-15 12:06:43 UTC (rev 1404)
+++ 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-15 12:48:11 UTC (rev 1405)
@@ -18,6 +18,8 @@
*/
package org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
import org.jboss.cache.Cache;
import org.jboss.cache.CacheException;
import org.jboss.cache.CacheSPI;
@@ -32,7 +34,9 @@
import org.jgroups.Address;
import java.io.Serializable;
+import java.util.ArrayList;
import java.util.Collections;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -58,6 +62,9 @@
private ThreadLocal<CompressedChangesList> changesList = new ThreadLocal<CompressedChangesList>();
+ protected static final Log LOG =
+ ExoLogger.getLogger("org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache.BufferedJBossCache");
+
public BufferedJBossCache(Cache<Serializable, Object> parentCache)
{
super();
@@ -532,8 +539,43 @@
return ((CacheSPI<Serializable, Object>)parentCache).getTransactionManager();
}
+ /**
+ * Gets object by key. If it is List<Object> adds new value to it.
+ *
+ * @param fqn
+ * @param key
+ * @param value
+ */
+ public void addToList(Fqn fqn, String key, Object value)
+ {
+ CompressedChangesList changesContainer = changesList.get();
+ if (changesContainer == null)
+ {
+ throw new IllegalStateException("changesContainer should not be empty");
+ }
+ changesContainer.add(new AddToListContainer(fqn, key, value, parentCache, changesContainer.getHistoryIndex()));
+ }
+
+ /**
+ * Gets object by key. If it is List<Object> removes value from it.
+ *
+ * @param fqn
+ * @param key
+ * @param value
+ */
+ public void removeFromList(Fqn fqn, String key, Object value)
+ {
+ CompressedChangesList changesContainer = changesList.get();
+ if (changesContainer == null)
+ {
+ throw new IllegalStateException("changesContainer should not be empty");
+ }
+ changesContainer
+ .add(new RemoveFromListContainer(fqn, key, value, parentCache, changesContainer.getHistoryIndex()));
+ }
+
public static enum ChangesType {
- REMOVE, REMOVE_KEY, PUT, PUT_KEY;
+ REMOVE, REMOVE_KEY, PUT, PUT_KEY, PUT_TO_LIST;
}
/**
@@ -647,6 +689,86 @@
}
/**
+ * Put to list container.
+ * It tries to get list by given key. If it is list adds new value and puts list.
+ */
+ public static class AddToListContainer extends ChangesContainer
+ {
+ private final Serializable key;
+
+ private final Object value;
+
+ public AddToListContainer(Fqn fqn, Serializable key, Object value, Cache<Serializable, Object> cache,
+ int historicalIndex)
+ {
+ super(fqn, ChangesType.PUT_KEY, cache, historicalIndex);
+ this.key = key;
+ this.value = value;
+ }
+
+ @Override
+ public void apply()
+ {
+ // force writeLock on next read
+ cache.getInvocationContext().getOptionOverrides().setForceWriteLock(true);
+ // object found by FQN and key;
+ Object existingObject = cache.get(getFqn(), key);
+ Set<Object> newSet = new HashSet<Object>();
+ // if set found of null, perform add
+ if (existingObject instanceof Set || existingObject == null)
+ {
+ // set found
+ if (existingObject instanceof Set)
+ {
+ newSet.addAll((Set<Object>)existingObject);
+ }
+ newSet.add(value);
+ cache.put(fqn, key, newSet);
+ }
+ else
+ {
+ LOG.error("Unexpected value found by FQN:" + getFqn() + " and key:" + key + ". Expected list, found:"
+ + existingObject.getClass().getName());
+ }
+ }
+ }
+
+ /**
+ * Removes from list container.
+ * It tries to get list by given key. If it is list removes value and puts list.
+ */
+ public static class RemoveFromListContainer extends ChangesContainer
+ {
+ private final Serializable key;
+
+ private final Object value;
+
+ public RemoveFromListContainer(Fqn fqn, Serializable key, Object value, Cache<Serializable, Object> cache,
+ int historicalIndex)
+ {
+ super(fqn, ChangesType.REMOVE_KEY, cache, historicalIndex);
+ this.key = key;
+ this.value = value;
+ }
+
+ @Override
+ public void apply()
+ {
+ // force writeLock on next read
+ cache.getInvocationContext().getOptionOverrides().setForceWriteLock(true);
+ // object found by FQN and key;
+ Object existingObject = cache.get(getFqn(), key);
+ // if found value is really set! add to it.
+ if (existingObject instanceof Set)
+ {
+ Set<Object> newSet = new HashSet<Object>((Set<Object>)existingObject);
+ newSet.remove(value);
+ cache.put(fqn, key, newSet);
+ }
+ }
+ }
+
+ /**
* Remove container.
*/
public static class RemoveKeyContainer extends ChangesContainer
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-15 12:06:43 UTC (rev 1404)
+++ 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-15 12:48:11 UTC (rev 1405)
@@ -45,6 +45,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -112,6 +113,8 @@
public static final String ITEM_ID = "$id".intern();
+ public static final String ITEM_LIST = "$lists".intern();
+
/**
* Empty cache node data for CHILD_x_LIST.
*/
@@ -471,7 +474,8 @@
else
{
// cache fact of empty childs list
- cache.put(makeChildListFqn(childNodesList, parent.getIdentifier()), NULL_DATA);
+ cache.put(makeChildListFqn(childNodesList, parent.getIdentifier()), ITEM_LIST, new HashSet<Object>());
+ //cache.put(makeChildListFqn(childNodesList, parent.getIdentifier()), NULL_DATA);
}
}
@@ -551,11 +555,12 @@
public List<NodeData> getChildNodes(final NodeData parent)
{
final List<NodeData> childs = new ArrayList<NodeData>();
- final Node<Serializable, Object> parentNode =
- cache.getNode(makeChildListFqn(childNodesList, parent.getIdentifier()));
- if (parentNode != null)
+ //final Node<Serializable, Object> parentNode =
+ // cache.getNode(makeChildListFqn(childNodesList, parent.getIdentifier()));
+ final Set<Object> set = (Set<Object>)cache.get(makeChildListFqn(childNodesList, parent.getIdentifier()), ITEM_LIST);
+ if (set != null)
{
- for (Object child : parentNode.getChildrenNames())
+ for (Object child : set)
{
NodeData node = (NodeData)cache.get(makeItemFqn((String)child), ITEM_DATA);
if (node == null)
@@ -603,10 +608,11 @@
protected List<PropertyData> getChildProps(String parentId, boolean withValue)
{
final List<PropertyData> childs = new ArrayList<PropertyData>();
- final Node<Serializable, Object> parentNode = cache.getNode(makeChildListFqn(childPropsList, parentId));
- if (parentNode != null)
+ //final Node<Serializable, Object> parentNode = cache.getNode(makeChildListFqn(childPropsList, parentId));
+ final Set<Object> list = (Set<Object>)cache.get(makeChildListFqn(childPropsList, parentId), ITEM_LIST);
+ if (list != null)
{
- for (Object child : parentNode.getChildrenNames())
+ for (Object child : list)
{
PropertyData node = (PropertyData)cache.get(makeItemFqn((String)child), ITEM_DATA);
if (node == null)
@@ -747,7 +753,8 @@
if (cache.getNode(makeChildListFqn(childNodesList, node.getParentIdentifier())) != null
|| modifyListsOfChild == ModifyChildOption.FORCE_MODIFY)
{
- cache.put(makeChildListFqn(childNodesList, node.getParentIdentifier(), node.getIdentifier()), NULL_DATA);
+ //cache.put(makeChildListFqn(childNodesList, node.getParentIdentifier(), node.getIdentifier()), NULL_DATA);
+ cache.addToList(makeChildListFqn(childNodesList, node.getParentIdentifier()), ITEM_LIST, node.getIdentifier());
}
}
}
@@ -781,7 +788,8 @@
if (cache.getNode(makeChildListFqn(childPropsList, prop.getParentIdentifier())) != null
|| modifyListsOfChild == ModifyChildOption.FORCE_MODIFY)
{
- cache.put(makeChildListFqn(childPropsList, prop.getParentIdentifier(), prop.getIdentifier()), NULL_DATA);
+ //cache.put(makeChildListFqn(childPropsList, prop.getParentIdentifier(), prop.getIdentifier()), NULL_DATA);
+ cache.addToList(makeChildListFqn(childPropsList, prop.getParentIdentifier()), ITEM_LIST, prop.getIdentifier());
}
}
@@ -808,7 +816,8 @@
.getQPath().getEntries().length - 1]));
// remove from CHILD_NODES_LIST of parent
- cache.removeNode(makeChildListFqn(childNodesList, item.getParentIdentifier(), item.getIdentifier()));
+ //cache.removeNode(makeChildListFqn(childNodesList, item.getParentIdentifier(), item.getIdentifier()));
+ cache.removeFromList(makeChildListFqn(childNodesList, item.getParentIdentifier()), ITEM_LIST, item.getIdentifier());
// remove from CHILD_NODES as parent
cache.removeNode(makeChildListFqn(childNodes, item.getIdentifier()));
@@ -830,7 +839,8 @@
.getQPath().getEntries().length - 1]));
// remove from CHILD_PROPS_LIST
- cache.removeNode(makeChildListFqn(childPropsList, item.getParentIdentifier(), item.getIdentifier()));
+ //cache.removeNode(makeChildListFqn(childPropsList, item.getParentIdentifier(), item.getIdentifier()));
+ cache.removeFromList(makeChildListFqn(childPropsList, item.getParentIdentifier()), ITEM_LIST, item.getIdentifier());
// TODO REFERENCEs hadnling
//if (prop.getType() == PropertyType.REFERENCE)
16 years, 4 months
exo-jcr SVN: r1404 - jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/cache.
by do-not-reply@jboss.org
Author: sergiykarpenko
Date: 2010-01-15 07:06:43 -0500 (Fri, 15 Jan 2010)
New Revision: 1404
Modified:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/cache/CacheLockImpl.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/cache/CacheableLockManager.java
Log:
EXOJCR-332: CacheableLockManager remove and get lock token fixed
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/cache/CacheLockImpl.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/cache/CacheLockImpl.java 2010-01-15 10:55:25 UTC (rev 1403)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/cache/CacheLockImpl.java 2010-01-15 12:06:43 UTC (rev 1404)
@@ -56,8 +56,7 @@
public String getLockToken()
{
- // TODO
- return lockData.getToken();
+ return lockManager.getLockToken(session.getId(), lockData);
}
public boolean isLive()
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/cache/CacheableLockManager.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/cache/CacheableLockManager.java 2010-01-15 10:55:25 UTC (rev 1403)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/cache/CacheableLockManager.java 2010-01-15 12:06:43 UTC (rev 1404)
@@ -289,6 +289,17 @@
}
}
+ /**
+ * Returns real token, if session has it
+ *
+ * @param lockData
+ * @return
+ */
+ // public String getLockToken(LockData lockData)
+ // {
+ // return tokenHash.get(lockData.getTokenHash());
+ // }
+
@Managed
@ManagedDescription("The number of active locks")
public int getNumLocks()
@@ -564,6 +575,10 @@
if (lockTokenHolders.containsKey(sessionId) && lockTokenHolders.get(sessionId).contains(lt))
{
lockTokenHolders.get(sessionId).remove(lt);
+ if (lockTokenHolders.get(sessionId).size() == 0)
+ {
+ lockTokenHolders.remove(sessionId);
+ }
}
}
@@ -899,4 +914,15 @@
}
}
+ public String getLockToken(String sessionId, LockData lockData)
+ {
+ if (lockTokenHolders.containsKey(sessionId) && lockTokenHolders.get(sessionId).contains(lockData.getToken()))
+ {
+ return lockData.getToken();
+ }
+ else
+ {
+ return null;
+ }
+ }
}
16 years, 4 months
exo-jcr SVN: r1403 - jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/cache.
by do-not-reply@jboss.org
Author: sergiykarpenko
Date: 2010-01-15 05:55:25 -0500 (Fri, 15 Jan 2010)
New Revision: 1403
Modified:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/cache/CacheableLockManager.java
Log:
EXOJCR-332: CacheableLockManager remake
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/cache/CacheableLockManager.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/cache/CacheableLockManager.java 2010-01-15 10:17:28 UTC (rev 1402)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/cache/CacheableLockManager.java 2010-01-15 10:55:25 UTC (rev 1403)
@@ -58,6 +58,9 @@
import org.jboss.cache.Node;
import java.io.Serializable;
+import java.math.BigInteger;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
@@ -111,10 +114,6 @@
public static final String LOCK_DATA = "$LOCK_DATA";
- public static final String LOCKED_NODE_ID = "$NODE_ID";
-
- public static final String TOKENS = "$TOKENS";
-
public static final String LOCKS = "$LOCKS";
/**
@@ -123,11 +122,6 @@
private final Log log = ExoLogger.getLogger("jcr.lock.LockManager");
/**
- * Map NodeIdentifier -- lockData
- */
- //private final Map<String, LockData> locks;
-
- /**
* Data manager.
*/
private final DataManager dataManager;
@@ -138,21 +132,11 @@
private final Map<String, LockData> pendingLocks;
/**
- * Map lockToken --lockData
+ * [session id , [lock tokens id..]]
*/
- //private final Map<String, LockData> tokensMap;
-
- /**
- * [session id , [lock tokens ids..]]
- */
private final Map<String, Set<String>> lockTokenHolders;
/**
- * Pending token maps. [lock tokens, node id]
- */
- private final Map<String, String> pendingLockTokens;
-
- /**
* Run time lock time out.
*/
private long lockTimeOut;
@@ -162,17 +146,10 @@
*/
private LockRemover lockRemover;
- /**
- * Lock persister instance.
- */
- //private final LockPersister persister;
-
private BufferedJBossCache cache;
private Node<Serializable, Object> lockRoot;
- private Node<Serializable, Object> tokenRoot;
-
/**
* Constructor for workspace without LockPersister
*
@@ -190,7 +167,6 @@
{
super(dataManager, config, null);
this.dataManager = dataManager;
- //this.persister = persister;
if (config.getLockManager() != null)
{
lockTimeOut =
@@ -200,24 +176,17 @@
lockTimeOut = DEFAULT_LOCK_TIMEOUT;
lockTokenHolders = new HashMap<String, Set<String>>();
- pendingLockTokens = new HashMap<String, String>();
pendingLocks = new HashMap<String, LockData>();
- //locks = new HashMap<String, LockData>();
- //tokensMap = new HashMap<String, LockData>();
+ // dataManager.addItemPersistenceListener(this);
- dataManager.addItemPersistenceListener(this);
-
- CacheFactory<Serializable, Object> factory = new DefaultCacheFactory<Serializable, Object>();
- cache = new BufferedJBossCache(factory.createCache(readJBCConfig(config), false));
- cache.create();
- }
-
- protected static String readJBCConfig(final WorkspaceEntry wsConfig) throws RepositoryConfigurationException
- {
- if (wsConfig.getLockManager() != null)
+ // make cache
+ if (config.getLockManager() != null && config.getLockManager().getCacheConfig() != null)
{
- return wsConfig.getLockManager().getCacheConfig();
+ String pathToConfig = config.getLockManager().getCacheConfig();
+ CacheFactory<Serializable, Object> factory = new DefaultCacheFactory<Serializable, Object>();
+ cache = new BufferedJBossCache(factory.createCache(pathToConfig, false));
+ cache.create();
}
else
{
@@ -233,22 +202,9 @@
*/
public synchronized void addLockToken(String sessionId, String lt)
{
- //LockData currLock = tokensMap.get(lt);
- if (pendingLockTokens.get(lt) != null || tokenRoot.hasChild(Fqn.fromString(lt)))
- {
- holdLockToken(sessionId, lt);
- }
+ holdLockToken(sessionId, lt);
}
- private void holdLockToken(String sessionId, String lt)
- {
- if (lockTokenHolders.get(sessionId) == null)
- {
- lockTokenHolders.put(sessionId, new HashSet<String>());
- }
- lockTokenHolders.get(sessionId).add(lt);
- }
-
/*
* (non-Javadoc)
* @see
@@ -281,18 +237,20 @@
new LockData(node.getInternalIdentifier(), lockToken, isDeep, isSessionScoped, node.getSession().getUserID(),
timeOut > 0 ? timeOut : lockTimeOut);
- //lData.addLockHolder(node.getSession().getId());
-
holdLockToken(node.getSession().getId(), lockToken);
-
pendingLocks.put(node.getInternalIdentifier(), lData);
- pendingLockTokens.put(lockToken, node.getInternalIdentifier());
- //tokensMap.put(lockToken, lData);
LockImpl lock = new CacheLockImpl(node.getSession(), lData, this);
return lock;
}
+ @Managed
+ @ManagedDescription("Remove the expired locks")
+ public void cleanExpiredLocks()
+ {
+ removeExpired();
+ }
+
/*
* (non-Javadoc)
* @see
@@ -331,6 +289,13 @@
}
}
+ @Managed
+ @ManagedDescription("The number of active locks")
+ public int getNumLocks()
+ {
+ return lockRoot.getChildrenNames().size();
+ }
+
/*
* (non-Javadoc)
* @see
@@ -371,14 +336,12 @@
return lData != null && isLockHolder(node.getSession().getId(), lData.getToken());
}
- private boolean isLockHolder(String sessionId, String lockToken)
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isTXAware()
{
- Set<String> lockTokens = lockTokenHolders.get(sessionId);
- if (lockTokens != null)
- {
- return lockTokens.contains(lockToken);
- }
- return false;
+ return true;
}
/*
@@ -389,67 +352,56 @@
*/
public synchronized void onCloseSession(ExtendedSession session)
{
- // List<String> deadLocksList = new ArrayList<String>();
SessionImpl sessionImpl = (SessionImpl)session;
- if (lockTokenHolders.containsKey(session.getId()))
+ for (LockData lockData : getLockList())
{
- Set<String> lockTokens = lockTokenHolders.get(session.getId());
-
- for (String token : lockTokens)
+ //TODO check is live or remove it
+ //if (lockData.isLive())
+ //{
+ // check is lock holder
+ if (lockTokenHolders.containsKey(session.getId())
+ && lockTokenHolders.get(session.getId()).contains(lockData.getToken()))
{
- String nodeId = null;
- if (pendingLockTokens.containsKey(token))
+ if (lockData.isSessionScoped())
{
- nodeId = pendingLockTokens.get(token);
- }
- if (tokenRoot.hasChild(Fqn.fromString(token)))
- {
- nodeId = (String)tokenRoot.getData().get(LOCKED_NODE_ID);
- }
-
- if (nodeId != null)
- {
- LockData lockData = this.getLockDataById(nodeId);
-
- if (lockData.isSessionScoped())
+ // if no session currently holds lock except this
+ try
{
- // unlock node
- try
- {
- // TODO it's possible to have next error
- // java.lang.NullPointerException
- // at
- // org.exoplatform.services.jcr.impl.core.lock.LockManagerImpl.onCloseSession(LockManagerImpl.java:312)
- // at org.exoplatform.services.jcr.impl.core.SessionImpl.logout(SessionImpl.java:794)
- // at
- // org.exoplatform.services.jcr.impl.core.XASessionImpl.logout(XASessionImpl.java:254)
- // at
- // org.exoplatform.services.jcr.impl.core.SessionRegistry$SessionCleaner.callPeriodically(SessionRegistry.java:165)
- // at
- // org.exoplatform.services.jcr.impl.proccess.WorkerThread.run(WorkerThread.java:46)
- ((NodeImpl)sessionImpl.getTransientNodesManager().getItemByIdentifier(nodeId, 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());
- }
+ ((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
+ {
+ this.removeLockToken(session.getId(), lockData.getToken());
+ }
}
+ //TODO
+ // }
+ // else
+ // {
+ // entries.remove();
+ // }
}
+
}
/*
@@ -504,27 +456,6 @@
else
{
throw new LockException("Lock must exist in pending locks.");
-
- // log.warn("No lock in pendingLocks for identifier " + nodeIdentifier
- // + " Probably lock come from replication.");
- //
- // String lockToken = IdGenerator.generate();
- // ItemState ownerState = getItemState(currChangesLog, Constants.JCR_LOCKOWNER);
- // ItemState isDeepState = getItemState(currChangesLog, Constants.JCR_LOCKISDEEP);
- // if (ownerState != null && isDeepState != null)
- // {
- //
- // String owner =
- // new String(((((TransientPropertyData)(ownerState.getData())).getValues()).get(0))
- // .getAsByteArray(), Constants.DEFAULT_ENCODING);
- //
- // boolean isDeep =
- // Boolean.valueOf(
- // new String(((((TransientPropertyData)(isDeepState.getData())).getValues()).get(0))
- // .getAsByteArray(), Constants.DEFAULT_ENCODING)).booleanValue();
- //
- // createRemoteLock(currChangesLog.getSessionId(), nodeIdentifier, lockToken, isDeep, false, owner);
- // }
}
break;
case ExtendedEvent.UNLOCK :
@@ -567,71 +498,38 @@
{
log.error(e.getLocalizedMessage(), e);
}
- // catch (UnsupportedEncodingException e)
- // {
- // log.error(e.getLocalizedMessage(), e);
- // }
catch (IllegalStateException e)
{
log.error(e.getLocalizedMessage(), e);
}
- // catch (IOException e)
- // {
- // log.error(e.getLocalizedMessage(), e);
- // }
}
}
- private boolean lockExist(String nodeId)
- {
- return lockRoot.hasChild(Fqn.fromString(nodeId));
- }
-
- /*
- * (non-Javadoc)
- * @see
- * org.exoplatform.services.jcr.impl.core.lock.LockManager#lockTokenRemoved(org.exoplatform.services
- * .jcr.impl.core.SessionImpl, java.lang.String)
+ /**
+ * Refreshed lock data in cache
+ *
+ * @param newLockData
*/
- public synchronized void removeLockToken(String sessionId, String lt)
+ public void refresh(LockData newLockData) throws LockException
{
- if (lockTokenHolders.containsKey(sessionId) && lockTokenHolders.get(sessionId).contains(lt))
+ //first look pending locks
+ if (pendingLocks.containsKey(newLockData.getNodeIdentifier()))
{
- lockTokenHolders.get(sessionId).remove(lt);
+ pendingLocks.put(newLockData.getNodeIdentifier(), newLockData);
}
- }
-
- /*
- * (non-Javadoc)
- * @see org.picocontainer.Startable#start()
- */
- public void start()
- {
- cache.start();
- tokenRoot = cache.getRoot().addChild(Fqn.fromString(TOKENS));
- lockRoot = cache.getRoot().addChild(Fqn.fromString(LOCKS));
- lockRemover = new LockRemover(this);
- }
-
- // Quick method. We need to reconstruct
- // TODO was synchronized
- protected List<LockData> getLockList()
- {
- Set<Node<Serializable, Object>> lockSet = lockRoot.getChildren();
-
- List<LockData> locksData = new ArrayList<LockData>();
- for (Node<Serializable, Object> node : lockSet)
+ else
{
- if (node != null)
+ Fqn<String> id = Fqn.fromString(newLockData.getNodeIdentifier());
+ if (lockRoot.hasChild(id))
{
- LockData lockData = (LockData)node.get(LOCK_DATA);
- if (lockData != null)
- {
- locksData.add(lockData);
- }
+ lockRoot.addChild(id);
}
+ else
+ {
+ throw new LockException("Can't refresh lock for node " + newLockData.getNodeIdentifier()
+ + " since lock is not exist");
+ }
}
- return locksData;
}
/**
@@ -657,17 +555,41 @@
/*
* (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)
+ {
+ if (lockTokenHolders.containsKey(sessionId) && lockTokenHolders.get(sessionId).contains(lt))
+ {
+ lockTokenHolders.get(sessionId).remove(lt);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.picocontainer.Startable#start()
+ */
+ public void start()
+ {
+ cache.start();
+ //tokenRoot = cache.getRoot().addChild(Fqn.fromString(TOKENS));
+ lockRoot = cache.getRoot().addChild(Fqn.fromString(LOCKS));
+ lockRemover = new LockRemover(this);
+ }
+
+ /*
+ * (non-Javadoc)
* @see org.picocontainer.Startable#stop()
*/
public void stop()
{
-
lockRemover.halt();
lockRemover.interrupt();
- //locks.clear();
+
pendingLocks.clear();
- pendingLockTokens.clear();
- //tokensMap.clear();
+
cache.stop();
}
@@ -694,6 +616,28 @@
}
/**
+ * Calculates md5 hash of string.
+ *
+ * @param token
+ * @return
+ */
+ private String getHash(String token)
+ {
+ String hash = "";
+ try
+ {
+ MessageDigest m = MessageDigest.getInstance("MD5");
+ m.update(token.getBytes(), 0, token.length());
+ hash = new BigInteger(1, m.digest()).toString(16);
+ }
+ catch (NoSuchAlgorithmException e)
+ {
+ log.error("Can't get instanse of MD5 MessageDigest!", e);
+ }
+ return hash;
+ }
+
+ /**
* Search item with name <code>itemName<code> in changesLog
*
* @param changesLog
@@ -774,15 +718,13 @@
return retval;
}
- protected LockData getLockDataById(String nodeId)
+ private void holdLockToken(String sessionId, String lt)
{
- LockData lockData = null;
- Node<Serializable, Object> node = lockRoot.getChild(Fqn.fromString(nodeId));
- if (node != null)
+ if (lockTokenHolders.get(sessionId) == null)
{
- lockData = (LockData)node.get(LOCK_DATA);
+ lockTokenHolders.put(sessionId, new HashSet<String>());
}
- return lockData;
+ lockTokenHolders.get(sessionId).add(lt);
}
/**
@@ -793,89 +735,31 @@
*/
private synchronized void internalLock(String nodeIdentifier) throws LockException
{
- // LockData ldata = pendingLocks.get(nodeIdentifier);
- // if (ldata != null)
- // {
- // locks.put(nodeIdentifier, ldata);
- //
- // if (persister != null)
- // {
- // persister.add(ldata);
- // }
- // pendingLocks.remove(nodeIdentifier);
- // }
- // else
- // {
- // throw new LockException("No lock in pending locks");
- // }
-
LockData lockData = pendingLocks.get(nodeIdentifier);
-
- if (lockData == null)
+ if (lockData != null)
{
- //TODO remove me
- throw new LockException("Lock data to write can't be null!");
- }
- // addChild will add if absent or return old if present
- Node<Serializable, Object> node = lockRoot.addChild(Fqn.fromString(lockData.getNodeIdentifier()));
-
- // 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 is present (not null):
- // 1. this is Lock.refresh(): oldLockData and lockData will have the same tokens
- // 2. this node is already locked: data-s will have different tokens
-
- if (oldLockData != null)
- {
- // if LockData already present with different lock token, then node has already been locked!
- if (!oldLockData.getToken().equals(lockData.getToken()))
+ Fqn<String> lockPath = Fqn.fromString(lockData.getNodeIdentifier());
+ if (lockRoot.hasChild(lockPath))
{
throw new LockException("Unable to write LockData. Node [" + lockData.getNodeIdentifier()
+ "] already has LockData!");
}
- else
- {
- // token is the same, then Lock is just refreshed. Putting new LockData.
- if (!node.replace(LOCK_DATA, oldLockData, lockData))
- {
- throw new LockException("Unable to re-write LockData. Possibly LockData for the Node["
- + lockData.getNodeIdentifier() + "] has just been changed!");
- }
- }
- }
- }
- /**
- * Internal unlock.
- *
- * @param sessionId
- * @param nodeIdentifier
- * @throws LockException
- */
- private synchronized void internalUnLock(String sessionId, String nodeIdentifier) throws LockException
- {
- LockData lData = getLockDataById(nodeIdentifier);
+ // addChild will add if absent or return old if present
+ Node<Serializable, Object> node = lockRoot.addChild(lockPath);
- if (lData != null)
- {
- //tokensMap.remove(lData.getLockToken(sessionId));
+ // this will prevent from deleting by eviction.
+ node.setResident(true);
- tokenRoot.removeChild(Fqn.fromString(lData.getToken()));
- lockRoot.removeChild(Fqn.fromString(nodeIdentifier));
+ // this will return null if success. And old data if something exists...
+ node.putIfAbsent(LOCK_DATA, lockData);
- // remove session holder
- if (lockTokenHolders.containsKey(sessionId))
- {
- lockTokenHolders.get(sessionId).remove(lData.getToken());
- if (lockTokenHolders.get(sessionId).size() == 0)
- {
- lockTokenHolders.remove(sessionId);
- }
- }
+ pendingLocks.remove(nodeIdentifier);
}
+ else
+ {
+ throw new LockException("No lock in pending locks");
+ }
}
/**
@@ -907,6 +791,81 @@
// }
/**
+ * 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.getToken());
+ if (lockTokenHolders.get(sessionId).size() == 0)
+ {
+ lockTokenHolders.remove(sessionId);
+ }
+ }
+ }
+ }
+
+ private boolean isLockHolder(String sessionId, String lockToken)
+ {
+ Set<String> lockTokens = lockTokenHolders.get(sessionId);
+ if (lockTokens != null)
+ {
+ return lockTokens.contains(lockToken);
+ }
+ return false;
+ }
+
+ private boolean lockExist(String nodeId)
+ {
+ return lockRoot.hasChild(Fqn.fromString(nodeId));
+ }
+
+ protected LockData getLockDataById(String nodeId)
+ {
+ LockData lockData = null;
+ Node<Serializable, Object> node = lockRoot.getChild(Fqn.fromString(nodeId));
+ if (node != null)
+ {
+ lockData = (LockData)node.get(LOCK_DATA);
+ }
+ return lockData;
+ }
+
+ // Quick method. We need to reconstruct
+ // TODO was synchronized
+ protected List<LockData> getLockList()
+ {
+ Set<Node<Serializable, Object>> lockSet = lockRoot.getChildren();
+
+ List<LockData> locksData = new ArrayList<LockData>();
+ for (Node<Serializable, Object> node : lockSet)
+ {
+ if (node != null)
+ {
+ LockData lockData = (LockData)node.get(LOCK_DATA);
+ if (lockData != null)
+ {
+ locksData.add(lockData);
+ }
+ }
+ }
+ return locksData;
+ }
+
+ /**
* Remove lock, used by Lock remover.
*
* @param nodeIdentifier String
@@ -940,52 +899,4 @@
}
}
- @Managed
- @ManagedDescription("The number of active locks")
- public int getNumLocks()
- {
- return lockRoot.getChildrenNames().size();
- }
-
- @Managed
- @ManagedDescription("Remove the expired locks")
- public void cleanExpiredLocks()
- {
- removeExpired();
- }
-
- /**
- * {@inheritDoc}
- */
- public boolean isTXAware()
- {
- return true;
- }
-
- /**
- * Refreshed lock data in cache
- *
- * @param newLockData
- */
- public void refresh(LockData newLockData) throws LockException
- {
- //first look pending locks
- if (pendingLocks.containsKey(newLockData.getNodeIdentifier()))
- {
- pendingLocks.put(newLockData.getNodeIdentifier(), newLockData);
- }
- else
- {
- Fqn<String> id = Fqn.fromString(newLockData.getNodeIdentifier());
- if (lockRoot.hasChild(id))
- {
- lockRoot.addChild(id);
- }
- else
- {
- throw new LockException("Can't refresh lock for node " + newLockData.getNodeIdentifier()
- + " since lock is not exist");
- }
- }
- }
}
16 years, 4 months
exo-jcr SVN: r1402 - jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.webdav/src/test/resources/conf/standalone.
by do-not-reply@jboss.org
Author: dkatayev
Date: 2010-01-15 05:17:28 -0500 (Fri, 15 Jan 2010)
New Revision: 1402
Modified:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.webdav/src/test/resources/conf/standalone/test-configuration.xml
Log:
EXOJCR-401 Transaction service changed to arjuna
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.webdav/src/test/resources/conf/standalone/test-configuration.xml
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.webdav/src/test/resources/conf/standalone/test-configuration.xml 2010-01-15 09:39:48 UTC (rev 1401)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.webdav/src/test/resources/conf/standalone/test-configuration.xml 2010-01-15 10:17:28 UTC (rev 1402)
@@ -1,24 +1,13 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
-<!--
+ <!--
- Copyright (C) 2009 eXo Platform SAS.
-
- This is free software; you can redistribute it and/or modify it
- under the terms of the GNU Lesser General Public License as
- published by the Free Software Foundation; either version 2.1 of
- the License, or (at your option) any later version.
-
- This software is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with this software; if not, write to the Free
- Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-
--->
+ Copyright (C) 2009 eXo Platform SAS. This is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This software is
+ distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with
+ this software; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF site:
+ http://www.fsf.org.
+ -->
<configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.exoplaform.org/xml/ns/kernel_1_0.xsd http://www.exoplaform.org/xml/ns/kernel_1_0.xsd"
xmlns="http://www.exoplaform.org/xml/ns/kernel_1_0.xsd">
<component>
@@ -131,13 +120,29 @@
<type>org.exoplatform.services.jcr.impl.ext.action.SessionActionCatalog</type>
</component>
+ <!-- <component>-->
+ <!-- <key>org.exoplatform.services.transaction.TransactionService</key>-->
+ <!-- <type>org.exoplatform.services.transaction.impl.jotm.TransactionServiceJotmImpl</type>-->
+ <!-- <init-params>-->
+ <!-- <value-param>-->
+ <!-- <name>timeout</name>-->
+ <!-- <value>5</value>-->
+ <!-- </value-param>-->
+ <!-- </init-params>-->
+ <!-- </component>-->
+
<component>
+ <key>org.jboss.cache.transaction.TransactionManagerLookup</key>
+ <type>org.jboss.cache.transaction.JBossStandaloneJTAManagerLookup</type>
+ </component>
+
+ <component>
<key>org.exoplatform.services.transaction.TransactionService</key>
- <type>org.exoplatform.services.transaction.impl.jotm.TransactionServiceJotmImpl</type>
+ <type>org.exoplatform.services.transaction.jbosscache.ArjunaTransactionService</type>
<init-params>
<value-param>
<name>timeout</name>
- <value>5</value>
+ <value>20</value>
</value-param>
</init-params>
</component>
@@ -183,12 +188,12 @@
<name>update-policy</name>
<value>create-version</value>
</value-param>
-
+
<value-param>
<name>cache-control</name>
<value>text/xml,text/html:max-age=1800;text/*:max-age=777;image/png,image/jpg:max-age=3600;*/*:no-cache;image/*:max-age=555</value>
- </value-param>
-
+ </value-param>
+
</init-params>
</component>
16 years, 4 months
exo-jcr SVN: r1401 - jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/cache.
by do-not-reply@jboss.org
Author: sergiykarpenko
Date: 2010-01-15 04:39:48 -0500 (Fri, 15 Jan 2010)
New Revision: 1401
Modified:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/cache/CacheableLockManager.java
Log:
EXOJCR-332: CacheableLockManager fixes
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/cache/CacheableLockManager.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/cache/CacheableLockManager.java 2010-01-15 09:14:28 UTC (rev 1400)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/cache/CacheableLockManager.java 2010-01-15 09:39:48 UTC (rev 1401)
@@ -399,10 +399,10 @@
for (String token : lockTokens)
{
String nodeId = null;
- // if (pendingLockTokens.containsKey(token))
- // {
- // nodeId = pendingLockTokens.get(token);
- // }
+ if (pendingLockTokens.containsKey(token))
+ {
+ nodeId = pendingLockTokens.get(token);
+ }
if (tokenRoot.hasChild(Fqn.fromString(token)))
{
nodeId = (String)tokenRoot.getData().get(LOCKED_NODE_ID);
16 years, 4 months
exo-jcr SVN: r1400 - jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/cache.
by do-not-reply@jboss.org
Author: areshetnyak
Date: 2010-01-15 04:14:28 -0500 (Fri, 15 Jan 2010)
New Revision: 1400
Modified:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/cache/CacheLockImpl.java
Log:
EXOJCR-332 : The CacheLockImpl was changed.
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/cache/CacheLockImpl.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/cache/CacheLockImpl.java 2010-01-14 20:14:36 UTC (rev 1399)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/cache/CacheLockImpl.java 2010-01-15 09:14:28 UTC (rev 1400)
@@ -46,6 +46,7 @@
this.lockData = lockData;
this.session = session;
this.lockManager = lockManager;
+ this.live = true;
}
public String getLockOwner()
16 years, 4 months
exo-jcr SVN: r1399 - jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/transaction/jbosscache.
by do-not-reply@jboss.org
Author: nfilotto
Date: 2010-01-14 15:14:36 -0500 (Thu, 14 Jan 2010)
New Revision: 1399
Modified:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/transaction/jbosscache/GenericTransactionService.java
Log:
EXOJCR-334: Avoid to set the default timeout to the TM, if the value doesn't come from the configuration. We assume that the value of the timeout is managed directly by the AS
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/transaction/jbosscache/GenericTransactionService.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/transaction/jbosscache/GenericTransactionService.java 2010-01-14 17:11:58 UTC (rev 1398)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/transaction/jbosscache/GenericTransactionService.java 2010-01-14 20:14:36 UTC (rev 1399)
@@ -60,6 +60,11 @@
protected final int defaultTimeout;
/**
+ * Indicates if the timeout has to be enforced
+ */
+ protected final boolean forceTimeout;
+
+ /**
* The current Transaction Manager
*/
private volatile TransactionManager tm;
@@ -80,10 +85,12 @@
if (params != null && params.getValueParam("timeout") != null)
{
this.defaultTimeout = Integer.parseInt(params.getValueParam("timeout").getValue());
+ this.forceTimeout = true;
}
else
{
this.defaultTimeout = DEFAULT_TIME_OUT;
+ this.forceTimeout = false;
}
}
@@ -108,7 +115,7 @@
}
else
{
- delistResource(tm, exores);
+ delistResourceOnTxMissing(tm, exores);
}
}
@@ -156,15 +163,21 @@
catch (Exception e)
{
throw new RuntimeException("Transaction manager not found", e);
- }
- try
+ }
+ if (forceTimeout)
{
- tm.setTransactionTimeout(defaultTimeout);
+ // Only set the timeout when a timeout has been given into the
+ // configuration otherwise we assume that the value will be
+ // set at the AS level
+ try
+ {
+ tm.setTransactionTimeout(defaultTimeout);
+ }
+ catch (Exception e)
+ {
+ log.warn("Cannot set the transaction timeout", e);
+ }
}
- catch (Exception e)
- {
- log.warn("Cannot set the transaction timeout", e);
- }
this.tm = tm;
}
}
@@ -201,7 +214,7 @@
* Allows to execute an action when we try to delist a resource when there is no active
* transaction
*/
- protected void delistResource(TransactionManager tm, ExoResource exores) throws RollbackException, SystemException
+ protected void delistResourceOnTxMissing(TransactionManager tm, ExoResource exores) throws RollbackException, SystemException
{
}
}
16 years, 4 months
exo-jcr SVN: r1398 - jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/cache.
by do-not-reply@jboss.org
Author: sergiykarpenko
Date: 2010-01-14 12:11:58 -0500 (Thu, 14 Jan 2010)
New Revision: 1398
Modified:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/cache/CacheLockImpl.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/cache/CacheableLockManager.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/cache/LockData.java
Log:
EXOJCR-332: CacheableLockManager fixes
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/cache/CacheLockImpl.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/cache/CacheLockImpl.java 2010-01-14 17:07:20 UTC (rev 1397)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/cache/CacheLockImpl.java 2010-01-14 17:11:58 UTC (rev 1398)
@@ -16,19 +16,13 @@
*/
package org.exoplatform.services.jcr.impl.core.lock.cache;
-import java.util.ArrayList;
+import org.exoplatform.services.jcr.impl.core.SessionImpl;
+import org.exoplatform.services.jcr.impl.core.lock.LockImpl;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.lock.LockException;
-import org.exoplatform.services.jcr.dataflow.ItemState;
-import org.exoplatform.services.jcr.dataflow.PlainChangesLogImpl;
-import org.exoplatform.services.jcr.dataflow.TransactionChangesLog;
-import org.exoplatform.services.jcr.impl.core.SessionImpl;
-import org.exoplatform.services.jcr.impl.core.lock.LockImpl;
-import org.exoplatform.services.jcr.observation.ExtendedEvent;
-
/**
* Created by The eXo Platform SAS.
*
@@ -40,11 +34,11 @@
public class CacheLockImpl extends LockImpl
{
private boolean live;
-
+
private LockData lockData;
private SessionImpl session;
-
+
private CacheableLockManager lockManager;
public CacheLockImpl(SessionImpl session, LockData lockData, CacheableLockManager lockManager)
@@ -61,9 +55,8 @@
public String getLockToken()
{
- //TODO
- //return lockData.getLockToken(session.getId());
- return null;
+ // TODO
+ return lockData.getToken();
}
public boolean isLive()
@@ -94,12 +87,12 @@
if (!isLive())
throw new LockException("Lock is not live");
- LockData newLockData = new LockData(lockData.getNodeIdentifier(), lockData.getToken(), lockData.isDeep(), lockData
- .isSessionScoped(), lockData.getOwner(), lockData.getTimeOut());
-
+ LockData newLockData =
+ new LockData(lockData.getNodeIdentifier(), lockData.getToken(), lockData.isDeep(), lockData.isSessionScoped(),
+ lockData.getOwner(), lockData.getTimeOut());
+
lockManager.refresh(newLockData);
-
- this.lockData = newLockData;
+ lockData = newLockData;
}
public Node getNode()
@@ -133,8 +126,17 @@
protected void setTimeOut(long timeOut)
{
- // TODO make same as refresh
- //lockData.setTimeOut(timeOut);
+ lockData.setTimeOut(timeOut);
+ //reset lock data
+ try
+ {
+ lockManager.refresh(lockData);
+ }
+ catch (LockException e)
+ {
+ // TODO remove or change this
+ e.printStackTrace();
+ }
}
}
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/cache/CacheableLockManager.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/cache/CacheableLockManager.java 2010-01-14 17:07:20 UTC (rev 1397)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/cache/CacheableLockManager.java 2010-01-14 17:11:58 UTC (rev 1398)
@@ -867,10 +867,13 @@
lockRoot.removeChild(Fqn.fromString(nodeIdentifier));
// remove session holder
- lockTokenHolders.get(sessionId).remove(lData.getToken());
- if (lockTokenHolders.get(sessionId).size() == 0)
+ if (lockTokenHolders.containsKey(sessionId))
{
- lockTokenHolders.remove(sessionId);
+ lockTokenHolders.get(sessionId).remove(lData.getToken());
+ if (lockTokenHolders.get(sessionId).size() == 0)
+ {
+ lockTokenHolders.remove(sessionId);
+ }
}
}
}
@@ -933,7 +936,7 @@
}
catch (RepositoryException e)
{
- log.error("Error occur during removing lock" + e.getLocalizedMessage());
+ log.error("Error occur during removing lock" + e.getLocalizedMessage(), e);
}
}
@@ -964,8 +967,25 @@
*
* @param newLockData
*/
- public void refresh(LockData newLockData)
+ public void refresh(LockData newLockData) throws LockException
{
- lockRoot.addChild(Fqn.fromString(newLockData.getNodeIdentifier()));
+ //first look pending locks
+ if (pendingLocks.containsKey(newLockData.getNodeIdentifier()))
+ {
+ pendingLocks.put(newLockData.getNodeIdentifier(), newLockData);
+ }
+ else
+ {
+ Fqn<String> id = Fqn.fromString(newLockData.getNodeIdentifier());
+ if (lockRoot.hasChild(id))
+ {
+ lockRoot.addChild(id);
+ }
+ else
+ {
+ throw new LockException("Can't refresh lock for node " + newLockData.getNodeIdentifier()
+ + " since lock is not exist");
+ }
+ }
}
}
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/cache/LockData.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/cache/LockData.java 2010-01-14 17:07:20 UTC (rev 1397)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/cache/LockData.java 2010-01-14 17:11:58 UTC (rev 1398)
@@ -235,4 +235,9 @@
return timeOut;
}
+ public void setTimeOut(long timeOut)
+ {
+ this.timeOut = timeOut;
+ }
+
}
16 years, 4 months
exo-jcr SVN: r1397 - jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/resources/conf/standalone.
by do-not-reply@jboss.org
Author: areshetnyak
Date: 2010-01-14 12:07:20 -0500 (Thu, 14 Jan 2010)
New Revision: 1397
Modified:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/resources/conf/standalone/test-jbosscache-lockconfig.xml
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/resources/conf/standalone/test-jcr-config.xml
Log:
EXOJCR-332 : The configuration was changed to CacheableLockManager.
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/resources/conf/standalone/test-jbosscache-lockconfig.xml
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/resources/conf/standalone/test-jbosscache-lockconfig.xml 2010-01-14 17:03:13 UTC (rev 1396)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/resources/conf/standalone/test-jbosscache-lockconfig.xml 2010-01-14 17:07:20 UTC (rev 1397)
@@ -9,16 +9,4 @@
<!-- Enable batching -->
<invocationBatching enabled="true" />
- <!-- Eviction configuration -->
- <eviction wakeUpInterval="5000">
- <default algorithmClass="org.jboss.cache.eviction.LRUAlgorithm">
- <property name="maxNodes" value="5000" />
- <property name="timeToLiveSeconds" value="120" />
- </default>
- <region name="/" algorithmClass="org.jboss.cache.eviction.LRUAlgorithm" actionPolicyClass="org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache.ChildListEvictionActionPolicy" eventQueueSize="1000000">
- <property name="maxNodes" value="5000" />
- <property name="timeToLiveSeconds" value="120" />
- </region>
- </eviction>
-
</jbosscache>
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/resources/conf/standalone/test-jcr-config.xml
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/resources/conf/standalone/test-jcr-config.xml 2010-01-14 17:03:13 UTC (rev 1396)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/resources/conf/standalone/test-jcr-config.xml 2010-01-14 17:07:20 UTC (rev 1397)
@@ -81,11 +81,7 @@
</query-handler>
<lock-manager>
<time-out>15m</time-out>
- <persister class="org.exoplatform.services.jcr.impl.core.lock.FileSystemLockPersister">
- <properties>
- <property name="path" value="target/temp/lock" />
- </properties>
- </persister>
+ <cache-config>conf/standalone/test-jbosscache-lockconfig.xml</cache-config>
</lock-manager>
</workspace>
@@ -126,6 +122,10 @@
<property name="spellchecker-class" value="org.exoplatform.services.jcr.impl.core.query.lucene.spell.LuceneSpellChecker$FiveSecondsRefreshInterval" />
</properties>
</query-handler>
+ <lock-manager>
+ <time-out>15m</time-out>
+ <cache-config>conf/standalone/test-jbosscache-lockconfig.xml</cache-config>
+ </lock-manager>
</workspace>
<workspace name="ws2" lazy-read-threshold="1">
@@ -165,6 +165,10 @@
<property name="spellchecker-class" value="org.exoplatform.services.jcr.impl.core.query.lucene.spell.LuceneSpellChecker$FiveSecondsRefreshInterval" />
</properties>
</query-handler>
+ <lock-manager>
+ <time-out>15m</time-out>
+ <cache-config>conf/standalone/test-jbosscache-lockconfig.xml</cache-config>
+ </lock-manager>
</workspace>
<workspace name="ws3">
@@ -236,6 +240,10 @@
value="org.exoplatform.services.jcr.impl.core.query.lucene.spell.LuceneSpellChecker$FiveSecondsRefreshInterval" />
</properties>
</query-handler>
+ <lock-manager>
+ <time-out>15m</time-out>
+ <cache-config>conf/standalone/test-jbosscache-lockconfig.xml</cache-config>
+ </lock-manager>
</workspace>
</workspaces>
</repository>
@@ -294,11 +302,7 @@
</query-handler>
<lock-manager>
<time-out>15m</time-out>
- <persister class="org.exoplatform.services.jcr.impl.core.lock.FileSystemLockPersister">
- <properties>
- <property name="path" value="target/temp/locktck" />
- </properties>
- </persister>
+ <cache-config>conf/standalone/test-jbosscache-lockconfig.xml</cache-config>
</lock-manager>
</workspace>
@@ -345,6 +349,10 @@
<property name="spellchecker-class" value="org.exoplatform.services.jcr.impl.core.query.lucene.spell.LuceneSpellChecker$FiveSecondsRefreshInterval" />
</properties>
</query-handler>
+ <lock-manager>
+ <time-out>15m</time-out>
+ <cache-config>conf/standalone/test-jbosscache-lockconfig.xml</cache-config>
+ </lock-manager>
</workspace>
<workspace name="ws2">
@@ -393,6 +401,10 @@
<property name="extractorTimeout" value="10"/>
</properties>
</query-handler>
+ <lock-manager>
+ <time-out>15m</time-out>
+ <cache-config>conf/standalone/test-jbosscache-lockconfig.xml</cache-config>
+ </lock-manager>
</workspace>
</workspaces>
</repository>
16 years, 4 months
exo-jcr SVN: r1396 - in jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow: persistent and 1 other directory.
by do-not-reply@jboss.org
Author: areshetnyak
Date: 2010-01-14 12:03:13 -0500 (Thu, 14 Jan 2010)
New Revision: 1396
Modified:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/AbstractPersistedValueData.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CleanableFilePersistedValueData.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/FilePersistedValueData.java
Log:
EXOJCR-404 : Add serializatio to AbstractPersistedValueData, FilePersistentValueData, CleanableFilePersistedValuData.
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/AbstractPersistedValueData.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/AbstractPersistedValueData.java 2010-01-14 16:26:03 UTC (rev 1395)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/AbstractPersistedValueData.java 2010-01-14 17:03:13 UTC (rev 1396)
@@ -18,6 +18,11 @@
*/
package org.exoplatform.services.jcr.impl.dataflow;
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+
import org.exoplatform.services.jcr.datamodel.ValueData;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
@@ -28,7 +33,7 @@
* @author <a href="mailto:peter.nedonosko@exoplatform.com">Peter Nedonosko</a>
* @version $Id$
*/
-public abstract class AbstractPersistedValueData implements ValueData
+public abstract class AbstractPersistedValueData implements ValueData, Externalizable
{
protected final static Log LOG = ExoLogger.getLogger("jcr.PersistedValueData");
@@ -39,6 +44,13 @@
{
this.orderNumber = orderNumber;
}
+
+ /**
+ * Empty constructor to serialization.
+ */
+ protected AbstractPersistedValueData()
+ {
+ }
/**
* {@inheritDoc}
@@ -69,4 +81,14 @@
* @throws RepositoryException if error ocurs
*/
public abstract TransientValueData createTransientCopy() throws RepositoryException;
+
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
+ {
+ orderNumber = in.readInt();
+ }
+
+ public void writeExternal(ObjectOutput out) throws IOException
+ {
+ out.writeInt(orderNumber);
+ }
}
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CleanableFilePersistedValueData.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CleanableFilePersistedValueData.java 2010-01-14 16:26:03 UTC (rev 1395)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CleanableFilePersistedValueData.java 2010-01-14 17:03:13 UTC (rev 1396)
@@ -41,7 +41,14 @@
protected final static Log LOG = ExoLogger.getLogger("jcr.CleanableFileStreamValueData");
- protected final FileCleaner cleaner;
+ protected FileCleaner cleaner;
+
+ /**
+ * Empty constructor to serialization.
+ */
+ public CleanableFilePersistedValueData()
+ {
+ }
/**
* CleanableFilePersistedValueData constructor.
@@ -74,12 +81,16 @@
if (!file.delete())
{
- cleaner.addFile(file);
-
- if (LOG.isDebugEnabled())
+ //TODO FileCleaner maybe null.
+ if (cleaner != null)
{
- LOG.debug("Could not remove temporary file on finalize: inUse=" + (((SwapFile)file).inUse()) + ", "
- + file.getAbsolutePath());
+ cleaner.addFile(file);
+
+ if (LOG.isDebugEnabled())
+ {
+ LOG.debug("Could not remove temporary file on finalize: inUse=" + (((SwapFile)file).inUse()) + ", "
+ + file.getAbsolutePath());
+ }
}
}
}
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/FilePersistedValueData.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/FilePersistedValueData.java 2010-01-14 16:26:03 UTC (rev 1395)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/FilePersistedValueData.java 2010-01-14 17:03:13 UTC (rev 1396)
@@ -22,11 +22,14 @@
import org.exoplatform.services.jcr.impl.dataflow.AbstractPersistedValueData;
import org.exoplatform.services.jcr.impl.dataflow.TransientValueData;
+import java.io.Externalizable;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.nio.MappedByteBuffer;
@@ -46,11 +49,20 @@
public class FilePersistedValueData extends AbstractPersistedValueData
{
+ private static final long serialVersionUID = -8183328056670315388L;
+
protected File file;
protected FileChannel channel;
/**
+ * Empty constructor to serialization.
+ */
+ public FilePersistedValueData()
+ {
+ }
+
+ /**
* FilePersistedValueData constructor.
* @param orderNumber int
* @param file File
@@ -214,4 +226,24 @@
fch.close();
}
}
+
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
+ {
+ super.readExternal(in);
+
+ // read canonical file path
+ byte[] buf = new byte[in.readInt()];
+
+ file = new File(new String(buf, "UTF-8"));
+ }
+
+ public void writeExternal(ObjectOutput out) throws IOException
+ {
+ super.writeExternal(out);
+
+ // write canonical file path
+ byte[] buf = file.getCanonicalPath().getBytes("UTF-8");
+ out.writeInt(buf.length);
+ out.write(buf);
+ }
}
16 years, 4 months