exo-jcr SVN: r2227 - in jcr/trunk/exo.jcr.component.core/src: test/java/org/exoplatform/services/jcr/api/writing and 1 other directory.
by do-not-reply@jboss.org
Author: sergiykarpenko
Date: 2010-04-08 07:10:25 -0400 (Thu, 08 Apr 2010)
New Revision: 2227
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCache.java
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/writing/TestOrderBefore.java
Log:
EXOJCR-618: BufferedJBossCache.getObjectFromChangesContainer optimized.
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCache.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCache.java 2010-04-08 10:52:32 UTC (rev 2226)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCache.java 2010-04-08 11:10:25 UTC (rev 2227)
@@ -18,20 +18,8 @@
*/
package org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache;
-import java.io.Serializable;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import javax.transaction.TransactionManager;
-
-import org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache.ChangesContainerFactory.AddToListContainer;
import org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache.ChangesContainerFactory.ChangesContainer;
import org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache.ChangesContainerFactory.PutKeyValueContainer;
-import org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache.ChangesContainerFactory.PutObjectContainer;
-import org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache.ChangesContainerFactory.RemoveFromListContainer;
-import org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache.ChangesContainerFactory.RemoveKeyContainer;
-import org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache.ChangesContainerFactory.RemoveNodeContainer;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
import org.jboss.cache.Cache;
@@ -47,6 +35,16 @@
import org.jboss.cache.interceptors.base.CommandInterceptor;
import org.jgroups.Address;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.transaction.TransactionManager;
+
/**
* Decorator over the JBossCache that stores changes in buffer, then sorts and applies to JBossCache.
*
@@ -61,11 +59,25 @@
* Parent cache.
*/
private final Cache<Serializable, Object> parentCache;
-
+
private final ChangesContainerFactory changesContatinerFactory;
private final ThreadLocal<CompressedChangesBuffer> changesList = new ThreadLocal<CompressedChangesBuffer>();
+ /**
+ * This comparator sorts CahangesContainer collection in descending mode.
+ */
+ private final Comparator<ChangesContainer> changesComparator = new Comparator<ChangesContainer>()
+ {
+
+ public int compare(ChangesContainer o1, ChangesContainer o2)
+ {
+ int result = o1.getFqn().compareTo(o2.getFqn());
+ return result == 0 ? o2.getHistoricalIndex() - o1.getHistoricalIndex() : result;
+ }
+
+ };
+
private ThreadLocal<Boolean> local = new ThreadLocal<Boolean>();
protected static final Log LOG =
@@ -457,8 +469,8 @@
public void put(Fqn fqn, Map<? extends Serializable, ? extends Object> data)
{
CompressedChangesBuffer changesContainer = getChangesBufferSafe();
- changesContainer.add(changesContatinerFactory.createPutObjectContainer(fqn, data, parentCache, changesContainer.getHistoryIndex(), local
- .get()));
+ changesContainer.add(changesContatinerFactory.createPutObjectContainer(fqn, data, parentCache, changesContainer
+ .getHistoryIndex(), local.get()));
}
/* (non-Javadoc)
@@ -467,8 +479,8 @@
public Object put(Fqn fqn, Serializable key, Object value)
{
CompressedChangesBuffer changesContainer = getChangesBufferSafe();
- changesContainer.add(changesContatinerFactory.createPutKeyValueContainer(fqn, key, value, parentCache, changesContainer.getHistoryIndex(),
- local.get()));
+ changesContainer.add(changesContatinerFactory.createPutKeyValueContainer(fqn, key, value, parentCache,
+ changesContainer.getHistoryIndex(), local.get()));
return parentCache.get(fqn, key);
}
@@ -480,8 +492,8 @@
// take Object from buffer for first
Object prevObject = getObjectFromChangesContainer(changesContainer, fqn, key);
- changesContainer.add(changesContatinerFactory.createPutKeyValueContainer(fqn, key, value, parentCache, changesContainer.getHistoryIndex(),
- local.get()));
+ changesContainer.add(changesContatinerFactory.createPutKeyValueContainer(fqn, key, value, parentCache,
+ changesContainer.getHistoryIndex(), local.get()));
if (prevObject != null)
{
@@ -495,16 +507,50 @@
private Object getObjectFromChangesContainer(CompressedChangesBuffer changesContainer, Fqn fqn, Serializable key)
{
- List<ChangesContainer> changes = changesContainer.getSortedList();
+ // List<ChangesContainer> changes = changesContainer.getSortedList();
+ // Object object = null;
+ // for (ChangesContainer change : changes)
+ // {
+ // if (change.getChangesType().equals(ChangesType.PUT_KEY) && change.getFqn().equals(fqn))
+ // {
+ // PutKeyValueContainer cont = ((PutKeyValueContainer)change);
+ // if (cont.getKey().equals(key))
+ // {
+ // object = ((PutKeyValueContainer)change).getValue();
+ // }
+ // }
+ // }
+ //
+ // return object;
+
+ List<ChangesContainer> changesContainers = new ArrayList<ChangesContainer>();
+ String parentCacheNode = (String)fqn.get(0);
+ if (JBossCacheWorkspaceStorageCache.CHILD_NODES.equals(parentCacheNode) && fqn.size() > 1)
+ {
+ changesContainers.addAll(changesContainer.childNodesMap.get(fqn.get(1)));
+ }
+ else if (JBossCacheWorkspaceStorageCache.CHILD_PROPS.equals(parentCacheNode) && fqn.size() > 1)
+ {
+ changesContainers.addAll(changesContainer.childPropertyMap.get(fqn.get(1)));
+ }
+ else
+ {
+ changesContainers.addAll(changesContainer.changes);
+ }
+
+ // sort changes in descending mode
+ Collections.sort(changesContainers, changesComparator);
+
Object object = null;
- for (ChangesContainer change : changes)
+ for (ChangesContainer change : changesContainers)
{
if (change.getChangesType().equals(ChangesType.PUT_KEY) && change.getFqn().equals(fqn))
{
PutKeyValueContainer cont = ((PutKeyValueContainer)change);
- if (cont.getKey().equals(key))
+ if (cont.key.equals(key))
{
- object = ((PutKeyValueContainer)change).getValue();
+ object = ((PutKeyValueContainer)change).value;
+ break;
}
}
}
@@ -543,8 +589,8 @@
public Object remove(Fqn fqn, Serializable key)
{
CompressedChangesBuffer changesContainer = getChangesBufferSafe();
- changesContainer.add(changesContatinerFactory.createRemoveKeyContainer(fqn, key, parentCache, changesContainer.getHistoryIndex(), local
- .get()));
+ changesContainer.add(changesContatinerFactory.createRemoveKeyContainer(fqn, key, parentCache, changesContainer
+ .getHistoryIndex(), local.get()));
return parentCache.get(fqn, key);
}
@@ -586,7 +632,8 @@
public boolean removeNode(Fqn fqn)
{
CompressedChangesBuffer changesContainer = getChangesBufferSafe();
- changesContainer.add(changesContatinerFactory.createRemoveNodeContainer(fqn, parentCache, changesContainer.getHistoryIndex(), local.get()));
+ changesContainer.add(changesContatinerFactory.createRemoveNodeContainer(fqn, parentCache, changesContainer
+ .getHistoryIndex(), local.get()));
return true;
}
@@ -654,8 +701,8 @@
public void addToList(Fqn fqn, String key, Object value)
{
CompressedChangesBuffer changesContainer = getChangesBufferSafe();
- changesContainer.add(changesContatinerFactory.createAddToListContainer(fqn, key, value, parentCache, changesContainer.getHistoryIndex(),
- local.get()));
+ changesContainer.add(changesContatinerFactory.createAddToListContainer(fqn, key, value, parentCache,
+ changesContainer.getHistoryIndex(), local.get()));
}
/**
Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/writing/TestOrderBefore.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/writing/TestOrderBefore.java 2010-04-08 10:52:32 UTC (rev 2226)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/writing/TestOrderBefore.java 2010-04-08 11:10:25 UTC (rev 2227)
@@ -19,6 +19,7 @@
package org.exoplatform.services.jcr.api.writing;
import org.exoplatform.services.jcr.JcrAPIBaseTest;
+import org.exoplatform.services.jcr.impl.core.NodeImpl;
import org.exoplatform.services.jcr.impl.util.EntityCollection;
import java.util.ArrayList;
@@ -975,10 +976,14 @@
session = repository.login(credentials, "ws");
Node a = session.getRootNode().getNode("a"); // We suppose it already exist
- a.addNode("n");
- a.addNode("n");
- a.addNode("n");
- a.addNode("n");
+ NodeImpl n1 = (NodeImpl)a.addNode("n");
+ NodeImpl n2 = (NodeImpl)a.addNode("n");
+ NodeImpl n3 = (NodeImpl)a.addNode("n");
+ NodeImpl n4 = (NodeImpl)a.addNode("n");
+ NodeImpl n5 = (NodeImpl)a.addNode("n");
+ NodeImpl n6 = (NodeImpl)a.addNode("n");
+ NodeImpl n7 = (NodeImpl)a.addNode("n");
+
session.save();
session.logout();
@@ -988,14 +993,30 @@
i.nextNode().remove();
i.nextNode().remove();
i.nextNode().remove();
+ i.nextNode().remove();
+ i.nextNode().remove();
+ i.nextNode().remove();
session.save();
session.logout();
session = repository.login(credentials, "ws");
+
+ NodeImpl n = (NodeImpl)a.getNode("n");
+ assertEquals(n7.getData().getIdentifier(), n.getData().getIdentifier());
+
+ n = (NodeImpl)a.getNode("n[1]");
+ assertEquals(n7.getData().getIdentifier(), n.getData().getIdentifier());
+
a = session.getRootNode().getNode("a");
- a.addNode("n");
+ NodeImpl nOrd = (NodeImpl)a.addNode("n");
a.orderBefore("n", null); // NPE happens here
session.save();
+
+ n = (NodeImpl)a.getNode("n[1]");
+ assertEquals(n7.getData().getIdentifier(), n.getData().getIdentifier());
+
+ n = (NodeImpl)a.getNode("n[2]");
+ assertEquals(nOrd.getData().getIdentifier(), n.getData().getIdentifier());
}
public void testDeleteOrderBefore_SNS() throws Exception
16 years, 3 months
exo-jcr SVN: r2226 - jcr/trunk/exo.jcr.component.core/src/test/resources/conf/standalone/cluster.
by do-not-reply@jboss.org
Author: areshetnyak
Date: 2010-04-08 06:52:32 -0400 (Thu, 08 Apr 2010)
New Revision: 2226
Modified:
jcr/trunk/exo.jcr.component.core/src/test/resources/conf/standalone/cluster/test-jbosscache-data.xml
Log:
EXOJCR-545 : change config
Modified: jcr/trunk/exo.jcr.component.core/src/test/resources/conf/standalone/cluster/test-jbosscache-data.xml
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/resources/conf/standalone/cluster/test-jbosscache-data.xml 2010-04-08 10:46:53 UTC (rev 2225)
+++ jcr/trunk/exo.jcr.component.core/src/test/resources/conf/standalone/cluster/test-jbosscache-data.xml 2010-04-08 10:52:32 UTC (rev 2226)
@@ -12,11 +12,11 @@
<!-- Eviction configuration -->
<eviction wakeUpInterval="5000">
- <default algorithmClass="org.jboss.cache.eviction.LRUAlgorithm"
+ <default algorithmClass="org.jboss.cache.eviction.ExpirationAlgorithm"
actionPolicyClass="org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache.ParentNodeEvictionActionPolicy"
eventQueueSize="1000000">
<property name="maxNodes" value="1000000" />
- <property name="timeToLive" value="120000" />
+ <property name="warnNoExpirationKey" value="false" />
</default>
</eviction>
</jbosscache>
\ No newline at end of file
16 years, 3 months
exo-jcr SVN: r2225 - jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache.
by do-not-reply@jboss.org
Author: areshetnyak
Date: 2010-04-08 06:46:53 -0400 (Thu, 08 Apr 2010)
New Revision: 2225
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/ChangesContainerExpirationFactory.java
Log:
EXOJCR-545 : The ChangesContainerFactory was changed.
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/ChangesContainerExpirationFactory.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/ChangesContainerExpirationFactory.java 2010-04-08 10:14:12 UTC (rev 2224)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/ChangesContainerExpirationFactory.java 2010-04-08 10:46:53 UTC (rev 2225)
@@ -42,7 +42,7 @@
/**
* The expiration timeout.
*/
- public static long expirationTimeOut;
+ public final long expirationTimeOut;
public ChangesContainerExpirationFactory(long expirationTimeOut)
{
@@ -54,11 +54,13 @@
*/
public static class PutObjectContainerExpiration extends PutObjectContainer
{
+ private final long timeOut;
public PutObjectContainerExpiration(Fqn fqn, Map<? extends Serializable, ? extends Object> data,
- Cache<Serializable, Object> cache, int historicalIndex, boolean local)
+ Cache<Serializable, Object> cache, int historicalIndex, boolean local, long timeOut)
{
super(fqn, data, cache, historicalIndex, local);
+ this.timeOut = timeOut;
}
@Override
@@ -68,7 +70,7 @@
cache.put(fqn, data);
setCacheLocalMode();
- cache.put(fqn, ExpirationAlgorithmConfig.EXPIRATION_KEY, new Long(System.currentTimeMillis() + expirationTimeOut));
+ cache.put(fqn, ExpirationAlgorithmConfig.EXPIRATION_KEY, new Long(System.currentTimeMillis() + timeOut));
}
}
@@ -77,18 +79,20 @@
*/
public static class PutKeyValueContainerExpiration extends PutKeyValueContainer
{
+ private final long timeOut;
public PutKeyValueContainerExpiration(Fqn fqn, Serializable key, Object value, Cache<Serializable, Object> cache,
- int historicalIndex, boolean local)
+ int historicalIndex, boolean local, long timeOut)
{
super(fqn, key, value, cache, historicalIndex, local);
+ this.timeOut = timeOut;
}
@Override
public void apply()
{
setCacheLocalMode();
- cache.put(fqn, ExpirationAlgorithmConfig.EXPIRATION_KEY, new Long(System.currentTimeMillis() + expirationTimeOut));
+ cache.put(fqn, ExpirationAlgorithmConfig.EXPIRATION_KEY, new Long(System.currentTimeMillis() + timeOut));
setCacheLocalMode();
cache.put(fqn, key, value);
@@ -114,11 +118,13 @@
*/
public static class AddToListContainerExpiration extends AddToListContainer
{
+ private final long timeOut;
public AddToListContainerExpiration(Fqn fqn, Serializable key, Object value, Cache<Serializable, Object> cache,
- int historicalIndex, boolean local)
+ int historicalIndex, boolean local, long timeOut)
{
super(fqn, key, value, cache, historicalIndex, local);
+ this.timeOut = timeOut;
}
@Override
@@ -140,7 +146,7 @@
newSet.add(value);
setCacheLocalMode();
- cache.put(fqn, ExpirationAlgorithmConfig.EXPIRATION_KEY, new Long(System.currentTimeMillis() + expirationTimeOut));
+ cache.put(fqn, ExpirationAlgorithmConfig.EXPIRATION_KEY, new Long(System.currentTimeMillis() + timeOut));
setCacheLocalMode();
cache.put(fqn, key, newSet);
@@ -158,11 +164,13 @@
*/
public static class RemoveFromListContainerExpiration extends RemoveFromListContainer
{
+ private final long timeOut;
public RemoveFromListContainerExpiration(Fqn fqn, Serializable key, Object value, Cache<Serializable, Object> cache,
- int historicalIndex, boolean local)
+ int historicalIndex, boolean local, long timeOut)
{
super(fqn, key, value, cache, historicalIndex, local);
+ this.timeOut = timeOut;
}
@Override
@@ -180,40 +188,48 @@
newSet.remove(value);
setCacheLocalMode();
- cache.put(fqn, ExpirationAlgorithmConfig.EXPIRATION_KEY, new Long(System.currentTimeMillis() + expirationTimeOut));
+ cache.put(fqn, ExpirationAlgorithmConfig.EXPIRATION_KEY, new Long(System.currentTimeMillis() + timeOut));
setCacheLocalMode();
cache.put(fqn, key, newSet);
}
}
}
-
- @Override
+
+ /**
+ * {@inheritDoc}
+ */
public ChangesContainer createPutObjectContainer(Fqn fqn, Map<? extends Serializable, ? extends Object> data,
Cache<Serializable, Object> cache, int historicalIndex, boolean local)
{
- return new PutObjectContainerExpiration(fqn, data, cache, historicalIndex, local);
+ return new PutObjectContainerExpiration(fqn, data, cache, historicalIndex, local, expirationTimeOut);
}
- @Override
+ /**
+ * {@inheritDoc}
+ */
public ChangesContainer createPutKeyValueContainer(Fqn fqn, Serializable key, Object value, Cache<Serializable, Object> cache,
int historicalIndex, boolean local)
{
- return new PutKeyValueContainerExpiration(fqn, key, value, cache, historicalIndex, local);
+ return new PutKeyValueContainerExpiration(fqn, key, value, cache, historicalIndex, local, expirationTimeOut);
}
- @Override
+ /**
+ * {@inheritDoc}
+ */
public ChangesContainer createAddToListContainer(Fqn fqn, Serializable key, Object value, Cache<Serializable, Object> cache,
int historicalIndex, boolean local)
{
- return new AddToListContainerExpiration(fqn, key, value, cache, historicalIndex, local);
+ return new AddToListContainerExpiration(fqn, key, value, cache, historicalIndex, local, expirationTimeOut);
}
- @Override
+ /**
+ * {@inheritDoc}
+ */
public ChangesContainer createRemoveFromListContainer(Fqn fqn, Serializable key, Object value, Cache<Serializable, Object> cache,
int historicalIndex, boolean local)
{
- return new RemoveFromListContainerExpiration(fqn, key, value, cache, historicalIndex, local);
+ return new RemoveFromListContainerExpiration(fqn, key, value, cache, historicalIndex, local, expirationTimeOut);
}
}
16 years, 3 months
exo-jcr SVN: r2224 - jcr/trunk/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-04-08 06:14:12 -0400 (Thu, 08 Apr 2010)
New Revision: 2224
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/ChangesContainerExpirationFactory.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java
Log:
EXOJCR-545: Added usage of expiration factory
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/ChangesContainerExpirationFactory.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/ChangesContainerExpirationFactory.java 2010-04-08 10:03:00 UTC (rev 2223)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/ChangesContainerExpirationFactory.java 2010-04-08 10:14:12 UTC (rev 2224)
@@ -16,46 +16,39 @@
*/
package org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache;
+import org.jboss.cache.Cache;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.eviction.ExpirationAlgorithmConfig;
+
import java.io.Serializable;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
-import org.jboss.cache.Cache;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.eviction.ExpirationAlgorithmConfig;
-
/**
* Created by The eXo Platform SAS.
*
- * ChahgesContainerExpirationFactory this special factory to ExpirationAlgorithm
+ * ChahgesContainerExpirationFactory this special factory to ExpirationAlgorithm
*
* <br/>Date: 2010
*
- * @author <a href="mailto:alex.reshetnyak@exoplatform.com.ua">Alex Reshetnyak</a>
+ * @author <a href="mailto:alex.reshetnyak@exoplatform.com.ua">Alex Reshetnyak</a>
* @version $Id$
*/
public class ChangesContainerExpirationFactory
- extends ChangesContainerFactory
+extends ChangesContainerFactory
{
-
- /**
- * The expiration timeout.
- */
- public final static long DEFAULT_EXPIRATION_TIMEOUT = 900000; // 15 minutes.
+ /**
+ * The expiration timeout.
+ */
public static long expirationTimeOut;
public ChangesContainerExpirationFactory(long expirationTimeOut)
{
this.expirationTimeOut = expirationTimeOut;
}
-
- public ChangesContainerExpirationFactory()
- {
- this.expirationTimeOut = DEFAULT_EXPIRATION_TIMEOUT;
- }
-
+
/**
* Put object container;
*/
@@ -96,21 +89,23 @@
{
setCacheLocalMode();
cache.put(fqn, ExpirationAlgorithmConfig.EXPIRATION_KEY, new Long(System.currentTimeMillis() + expirationTimeOut));
-
+
setCacheLocalMode();
cache.put(fqn, key, value);
}
+ @Override
public Serializable getKey()
{
return key;
}
+ @Override
public Object getValue()
{
return value;
}
-
+
}
/**
@@ -143,10 +138,10 @@
newSet.addAll((Set<Object>)existingObject);
}
newSet.add(value);
-
+
setCacheLocalMode();
cache.put(fqn, ExpirationAlgorithmConfig.EXPIRATION_KEY, new Long(System.currentTimeMillis() + expirationTimeOut));
-
+
setCacheLocalMode();
cache.put(fqn, key, newSet);
}
@@ -183,38 +178,42 @@
{
Set<Object> newSet = new HashSet<Object>((Set<Object>)existingObject);
newSet.remove(value);
-
+
setCacheLocalMode();
cache.put(fqn, ExpirationAlgorithmConfig.EXPIRATION_KEY, new Long(System.currentTimeMillis() + expirationTimeOut));
-
+
setCacheLocalMode();
cache.put(fqn, key, newSet);
}
}
}
-
+
+ @Override
public ChangesContainer createPutObjectContainer(Fqn fqn, Map<? extends Serializable, ? extends Object> data,
- Cache<Serializable, Object> cache, int historicalIndex, boolean local)
+ Cache<Serializable, Object> cache, int historicalIndex, boolean local)
{
- return new PutObjectContainerExpiration(fqn, data, cache, historicalIndex, local);
+ return new PutObjectContainerExpiration(fqn, data, cache, historicalIndex, local);
}
-
+
+ @Override
public ChangesContainer createPutKeyValueContainer(Fqn fqn, Serializable key, Object value, Cache<Serializable, Object> cache,
- int historicalIndex, boolean local)
+ int historicalIndex, boolean local)
{
- return new PutKeyValueContainerExpiration(fqn, key, value, cache, historicalIndex, local);
+ return new PutKeyValueContainerExpiration(fqn, key, value, cache, historicalIndex, local);
}
-
+
+ @Override
public ChangesContainer createAddToListContainer(Fqn fqn, Serializable key, Object value, Cache<Serializable, Object> cache,
- int historicalIndex, boolean local)
+ int historicalIndex, boolean local)
{
- return new AddToListContainerExpiration(fqn, key, value, cache, historicalIndex, local);
+ return new AddToListContainerExpiration(fqn, key, value, cache, historicalIndex, local);
}
-
+
+ @Override
public ChangesContainer createRemoveFromListContainer(Fqn fqn, Serializable key, Object value, Cache<Serializable, Object> cache,
- int historicalIndex, boolean local)
+ int historicalIndex, boolean local)
{
- return new RemoveFromListContainerExpiration(fqn, key, value, cache, historicalIndex, local);
+ return new RemoveFromListContainerExpiration(fqn, key, value, cache, historicalIndex, local);
}
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java 2010-04-08 10:03:00 UTC (rev 2223)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java 2010-04-08 10:14:12 UTC (rev 2224)
@@ -96,6 +96,10 @@
public static final String JBOSSCACHE_CONFIG = "jbosscache-configuration";
+ public static final String JBOSSCACHE_EXPIRATION = "jbosscache-expiration-time";
+
+ public static final int JBOSSCACHE_EXPIRATION_DEFAULT = 900000; // 15 minutes
+
public static final String ITEMS = "$ITEMS".intern();
public static final String CHILD_NODES = "$CHILD_NODES".intern();
@@ -306,8 +310,11 @@
LOG.info("Using BufferedJBossCache compatible with Expiration algorithm.");
}
- // TODO: create appropriate cache with useExpiration set or not.
- this.cache = new BufferedJBossCache(factory.createCache(wsConfig.getCache()), new ChangesContainerExpirationFactory());
+ // if expiration is used, set appropriate factory with with timeout set via configuration (or default one 15minutes)
+ this.cache =
+ new BufferedJBossCache(factory.createCache(wsConfig.getCache()), useExpiration
+ ? new ChangesContainerExpirationFactory(wsConfig.getCache().getParameterInteger(JBOSSCACHE_EXPIRATION,
+ JBOSSCACHE_EXPIRATION_DEFAULT)) : new ChangesContainerFactory());
this.itemsRoot = Fqn.fromElements(ITEMS);
this.childNodes = Fqn.fromElements(CHILD_NODES);
16 years, 3 months
exo-jcr SVN: r2223 - in jcr/trunk/exo.jcr.component.core/src: test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache and 1 other directories.
by do-not-reply@jboss.org
Author: areshetnyak
Date: 2010-04-08 06:03:00 -0400 (Thu, 08 Apr 2010)
New Revision: 2223
Added:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/ChangesContainerExpirationFactory.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/ChangesContainerFactory.java
Removed:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCacheExp.java
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCache.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/CompressedChangesBuffer.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/TestCompressedChangesBuffer.java
jcr/trunk/exo.jcr.component.core/src/test/resources/conf/standalone/test-jbosscache-config.xml
Log:
EXOJCR-545 : Add implementation use the ExpitationAlgorithm
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCache.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCache.java 2010-04-08 10:02:57 UTC (rev 2222)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCache.java 2010-04-08 10:03:00 UTC (rev 2223)
@@ -18,6 +18,20 @@
*/
package org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache;
+import java.io.Serializable;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.transaction.TransactionManager;
+
+import org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache.ChangesContainerFactory.AddToListContainer;
+import org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache.ChangesContainerFactory.ChangesContainer;
+import org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache.ChangesContainerFactory.PutKeyValueContainer;
+import org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache.ChangesContainerFactory.PutObjectContainer;
+import org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache.ChangesContainerFactory.RemoveFromListContainer;
+import org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache.ChangesContainerFactory.RemoveKeyContainer;
+import org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache.ChangesContainerFactory.RemoveNodeContainer;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
import org.jboss.cache.Cache;
@@ -30,18 +44,9 @@
import org.jboss.cache.NodeNotExistsException;
import org.jboss.cache.Region;
import org.jboss.cache.config.Configuration;
-import org.jboss.cache.eviction.ExpirationAlgorithmConfig;
import org.jboss.cache.interceptors.base.CommandInterceptor;
import org.jgroups.Address;
-import java.io.Serializable;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import javax.transaction.TransactionManager;
-
/**
* Decorator over the JBossCache that stores changes in buffer, then sorts and applies to JBossCache.
*
@@ -52,12 +57,12 @@
@SuppressWarnings("unchecked")
public class BufferedJBossCache implements Cache<Serializable, Object>
{
- // private final Log log = ExoLogger.getLogger("exo.jcr.component.core.BufferedJbossCache");
-
/**
* Parent cache.
*/
private final Cache<Serializable, Object> parentCache;
+
+ private final ChangesContainerFactory changesContatinerFactory;
private final ThreadLocal<CompressedChangesBuffer> changesList = new ThreadLocal<CompressedChangesBuffer>();
@@ -66,10 +71,11 @@
protected static final Log LOG =
ExoLogger.getLogger("org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache.BufferedJBossCache");
- public BufferedJBossCache(Cache<Serializable, Object> parentCache)
+ public BufferedJBossCache(Cache<Serializable, Object> parentCache, ChangesContainerFactory changesContatinerFactory)
{
super();
this.parentCache = parentCache;
+ this.changesContatinerFactory = changesContatinerFactory;
}
/**
@@ -451,8 +457,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(changesContatinerFactory.createPutObjectContainer(fqn, data, parentCache, changesContainer.getHistoryIndex(), local
+ .get()));
}
/* (non-Javadoc)
@@ -461,8 +467,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(changesContatinerFactory.createPutKeyValueContainer(fqn, key, value, parentCache, changesContainer.getHistoryIndex(),
+ local.get()));
return parentCache.get(fqn, key);
}
@@ -474,7 +480,7 @@
// take Object from buffer for first
Object prevObject = getObjectFromChangesContainer(changesContainer, fqn, key);
- changesContainer.add(new PutKeyValueContainer(fqn, key, value, parentCache, changesContainer.getHistoryIndex(),
+ changesContainer.add(changesContatinerFactory.createPutKeyValueContainer(fqn, key, value, parentCache, changesContainer.getHistoryIndex(),
local.get()));
if (prevObject != null)
@@ -496,9 +502,9 @@
if (change.getChangesType().equals(ChangesType.PUT_KEY) && change.getFqn().equals(fqn))
{
PutKeyValueContainer cont = ((PutKeyValueContainer)change);
- if (cont.key.equals(key))
+ if (cont.getKey().equals(key))
{
- object = ((PutKeyValueContainer)change).value;
+ object = ((PutKeyValueContainer)change).getValue();
}
}
}
@@ -537,7 +543,7 @@
public Object remove(Fqn fqn, Serializable key)
{
CompressedChangesBuffer changesContainer = getChangesBufferSafe();
- changesContainer.add(new RemoveKeyContainer(fqn, key, parentCache, changesContainer.getHistoryIndex(), local
+ changesContainer.add(changesContatinerFactory.createRemoveKeyContainer(fqn, key, parentCache, changesContainer.getHistoryIndex(), local
.get()));
return parentCache.get(fqn, key);
}
@@ -580,7 +586,7 @@
public boolean removeNode(Fqn fqn)
{
CompressedChangesBuffer changesContainer = getChangesBufferSafe();
- changesContainer.add(new RemoveNodeContainer(fqn, parentCache, changesContainer.getHistoryIndex(), local.get()));
+ changesContainer.add(changesContatinerFactory.createRemoveNodeContainer(fqn, parentCache, changesContainer.getHistoryIndex(), local.get()));
return true;
}
@@ -648,7 +654,7 @@
public void addToList(Fqn fqn, String key, Object value)
{
CompressedChangesBuffer changesContainer = getChangesBufferSafe();
- changesContainer.add(new AddToListContainer(fqn, key, value, parentCache, changesContainer.getHistoryIndex(),
+ changesContainer.add(changesContatinerFactory.createAddToListContainer(fqn, key, value, parentCache, changesContainer.getHistoryIndex(),
local.get()));
}
@@ -662,266 +668,12 @@
public void removeFromList(Fqn fqn, String key, Object value)
{
CompressedChangesBuffer changesContainer = getChangesBufferSafe();
- changesContainer.add(new RemoveFromListContainer(fqn, key, value, parentCache,
+ changesContainer.add(changesContatinerFactory.createRemoveFromListContainer(fqn, key, value, parentCache,
changesContainer.getHistoryIndex(), local.get()));
}
public static enum ChangesType {
REMOVE, REMOVE_KEY, PUT, PUT_KEY, PUT_TO_LIST;
}
-
- protected static void putMap(Fqn fqn, Map<? extends Serializable, ? extends Object> data, Cache<Serializable, Object> cache, boolean localMode)
- {
- cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(localMode);
- cache.put(fqn, data);
- }
-
- protected static void putObject(Fqn fqn, Serializable key, Object value, Cache<Serializable, Object> cache, boolean localMode)
- {
- cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(localMode);
- cache.put(fqn, key, value);
- }
- /**
- * Container for changes
- */
- public static abstract class ChangesContainer implements Comparable<ChangesContainer>
- {
- protected final Fqn fqn;
-
- protected final ChangesType changesType;
-
- protected final Cache<Serializable, Object> cache;
-
- protected final int historicalIndex;
-
- protected final boolean localMode;
-
- public ChangesContainer(Fqn fqn, ChangesType changesType, Cache<Serializable, Object> cache, int historicalIndex,
- boolean localMode)
- {
- super();
- this.fqn = fqn;
- this.changesType = changesType;
- this.cache = cache;
- this.historicalIndex = historicalIndex;
- this.localMode = localMode;
- }
-
- /**
- * @return the fqn
- */
- public Fqn getFqn()
- {
- return fqn;
- }
-
- /**
- * @return the index of change in original sequence
- */
- public int getHistoricalIndex()
- {
- return historicalIndex;
- }
-
- /**
- * @return the changesType
- */
- public ChangesType getChangesType()
- {
- return changesType;
- }
-
- /* (non-Javadoc)
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString()
- {
- return fqn + " type=" + changesType + " historyIndex=" + historicalIndex;
- }
-
- public int compareTo(ChangesContainer o)
- {
- int result = fqn.compareTo(o.getFqn());
- return result == 0 ? historicalIndex - o.getHistoricalIndex() : result;
- }
-
- protected void setCacheLocalMode()
- {
- cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(localMode);
- }
-
- public abstract void apply();
- }
-
- /**
- * Put object container;
- */
- public static class PutObjectContainer extends ChangesContainer
- {
- private final Map<? extends Serializable, ? extends Object> data;
-
- public PutObjectContainer(Fqn fqn, Map<? extends Serializable, ? extends Object> data,
- Cache<Serializable, Object> cache, int historicalIndex, boolean local)
- {
- super(fqn, ChangesType.PUT, cache, historicalIndex, local);
-
- this.data = data;
- }
-
- @Override
- public void apply()
- {
- putMap(fqn, data, cache, localMode);
- }
- }
-
- /**
- * Put container.
- */
- public static class PutKeyValueContainer extends ChangesContainer
- {
- private final Serializable key;
-
- private final Object value;
-
- public PutKeyValueContainer(Fqn fqn, Serializable key, Object value, Cache<Serializable, Object> cache,
- int historicalIndex, boolean local)
- {
- super(fqn, ChangesType.PUT_KEY, cache, historicalIndex, local);
- this.key = key;
- this.value = value;
- }
-
- @Override
- public void apply()
- {
- putObject(fqn, key, value, cache, localMode);
- }
- }
-
- /**
- * It tries to get Set by given key. If it is Set then adds new value and puts new set back.
- * If null found, then new Set created (ordinary cache does).
- */
- 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, boolean local)
- {
- super(fqn, ChangesType.PUT_KEY, cache, historicalIndex, local);
- 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);
-
- putObject(fqn, key, newSet, cache, localMode);
- }
- else
- {
- LOG.error("Unexpected object found by FQN:" + getFqn() + " and key:" + key + ". Expected Set, but found:"
- + existingObject.getClass().getName());
- }
- }
- }
-
- /**
- * It tries to get set by given key. If it is set then removes value and puts new modified set back.
- */
- 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, boolean local)
- {
- super(fqn, ChangesType.REMOVE_KEY, cache, historicalIndex, local);
- 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;
- setCacheLocalMode();
- 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);
-
- putObject(fqn, key, newSet, cache, localMode);
- }
- }
- }
-
- /**
- * Remove container.
- */
- public static class RemoveKeyContainer extends ChangesContainer
- {
- private final Serializable key;
-
- 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;
- }
-
- @Override
- public void apply()
- {
- setCacheLocalMode();
- cache.remove(fqn, key);
- }
-
- }
-
- /**
- * Remove container.
- */
- public static class RemoveNodeContainer extends ChangesContainer
- {
-
- public RemoveNodeContainer(Fqn fqn, Cache<Serializable, Object> cache, int historicalIndex, boolean local)
- {
- super(fqn, ChangesType.REMOVE, cache, historicalIndex, local);
- }
-
- @Override
- public void apply()
- {
- setCacheLocalMode();
- cache.removeNode(fqn);
- }
- }
}
Deleted: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCacheExp.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCacheExp.java 2010-04-08 10:02:57 UTC (rev 2222)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCacheExp.java 2010-04-08 10:03:00 UTC (rev 2223)
@@ -1,84 +0,0 @@
-/*
- * 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.dataflow.persistent.jbosscache;
-
-import java.io.Serializable;
-import java.util.Map;
-
-import org.jboss.cache.Cache;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.eviction.ExpirationAlgorithmConfig;
-
-/**
- * Created by The eXo Platform SAS.
- *
- * <br/>Date: 2010
- *
- * @author <a href="mailto:alex.reshetnyak@exoplatform.com.ua">Alex Reshetnyak</a>
- * @version $Id$
- */
-public class BufferedJBossCacheExp extends BufferedJBossCache
-{
- /**
- * The expiration timeout.
- */
- public final static long DEFAULT_EXPIRATION_TIMEOUT = 900000; // 15 minutes.
-
- public final long expirationTimeOut;
-
- public BufferedJBossCacheExp(Cache<Serializable, Object> parentCache, long expirationTimeOut)
- {
- super(parentCache);
- this.expirationTimeOut = expirationTimeOut;
- }
-
- public BufferedJBossCacheExp(Cache<Serializable, Object> parentCache)
- {
- super(parentCache);
- this.expirationTimeOut = DEFAULT_EXPIRATION_TIMEOUT;
- }
-
- protected static void putMap(Fqn fqn, Map<? extends Serializable, ? extends Object> data, Cache<Serializable, Object> cache, boolean localMode)
- {
- putExpiration(fqn, cache, localMode);
-
- cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(localMode);
- cache.put(fqn, data);
-
- cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(localMode);
- cache.put(fqn, ExpirationAlgorithmConfig.EXPIRATION_KEY, new Long(System.currentTimeMillis() + DEFAULT_EXPIRATION_TIMEOUT));
- }
-
- protected static void putObject(Fqn fqn, Serializable key, Object value, Cache<Serializable, Object> cache, boolean localMode)
- {
- cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(localMode);
- cache.put(fqn, key, value);
- }
-
- public static void putExpiration(Fqn efqn, Cache<Serializable, Object> cache, boolean localMode)
- {
- for (int i = 2; i <= efqn.size(); i++)
- {
- Fqn pfqn = efqn.getSubFqn(0, i);
- cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(localMode);
- cache.put(pfqn, ExpirationAlgorithmConfig.EXPIRATION_KEY, new Long(System.currentTimeMillis() + DEFAULT_EXPIRATION_TIMEOUT));
- }
- }
-
-
-
-}
Added: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/ChangesContainerExpirationFactory.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/ChangesContainerExpirationFactory.java (rev 0)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/ChangesContainerExpirationFactory.java 2010-04-08 10:03:00 UTC (rev 2223)
@@ -0,0 +1,220 @@
+/*
+ * 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.dataflow.persistent.jbosscache;
+
+import java.io.Serializable;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.jboss.cache.Cache;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.eviction.ExpirationAlgorithmConfig;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * ChahgesContainerExpirationFactory this special factory to ExpirationAlgorithm
+ *
+ * <br/>Date: 2010
+ *
+ * @author <a href="mailto:alex.reshetnyak@exoplatform.com.ua">Alex Reshetnyak</a>
+ * @version $Id$
+ */
+public class ChangesContainerExpirationFactory
+ extends ChangesContainerFactory
+{
+
+ /**
+ * The expiration timeout.
+ */
+ public final static long DEFAULT_EXPIRATION_TIMEOUT = 900000; // 15 minutes.
+
+ public static long expirationTimeOut;
+
+ public ChangesContainerExpirationFactory(long expirationTimeOut)
+ {
+ this.expirationTimeOut = expirationTimeOut;
+ }
+
+ public ChangesContainerExpirationFactory()
+ {
+ this.expirationTimeOut = DEFAULT_EXPIRATION_TIMEOUT;
+ }
+
+ /**
+ * Put object container;
+ */
+ public static class PutObjectContainerExpiration extends PutObjectContainer
+ {
+
+ public PutObjectContainerExpiration(Fqn fqn, Map<? extends Serializable, ? extends Object> data,
+ Cache<Serializable, Object> cache, int historicalIndex, boolean local)
+ {
+ super(fqn, data, cache, historicalIndex, local);
+ }
+
+ @Override
+ public void apply()
+ {
+ setCacheLocalMode();
+ cache.put(fqn, data);
+
+ setCacheLocalMode();
+ cache.put(fqn, ExpirationAlgorithmConfig.EXPIRATION_KEY, new Long(System.currentTimeMillis() + expirationTimeOut));
+ }
+ }
+
+ /**
+ * Put container.
+ */
+ public static class PutKeyValueContainerExpiration extends PutKeyValueContainer
+ {
+
+ public PutKeyValueContainerExpiration(Fqn fqn, Serializable key, Object value, Cache<Serializable, Object> cache,
+ int historicalIndex, boolean local)
+ {
+ super(fqn, key, value, cache, historicalIndex, local);
+ }
+
+ @Override
+ public void apply()
+ {
+ setCacheLocalMode();
+ cache.put(fqn, ExpirationAlgorithmConfig.EXPIRATION_KEY, new Long(System.currentTimeMillis() + expirationTimeOut));
+
+ setCacheLocalMode();
+ cache.put(fqn, key, value);
+ }
+
+ public Serializable getKey()
+ {
+ return key;
+ }
+
+ public Object getValue()
+ {
+ return value;
+ }
+
+ }
+
+ /**
+ * It tries to get Set by given key. If it is Set then adds new value and puts new set back.
+ * If null found, then new Set created (ordinary cache does).
+ */
+ public static class AddToListContainerExpiration extends AddToListContainer
+ {
+
+ public AddToListContainerExpiration(Fqn fqn, Serializable key, Object value, Cache<Serializable, Object> cache,
+ int historicalIndex, boolean local)
+ {
+ super(fqn, key, value, cache, historicalIndex, local);
+ }
+
+ @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);
+
+ setCacheLocalMode();
+ cache.put(fqn, ExpirationAlgorithmConfig.EXPIRATION_KEY, new Long(System.currentTimeMillis() + expirationTimeOut));
+
+ setCacheLocalMode();
+ cache.put(fqn, key, newSet);
+ }
+ else
+ {
+ LOG.error("Unexpected object found by FQN:" + getFqn() + " and key:" + key + ". Expected Set, but found:"
+ + existingObject.getClass().getName());
+ }
+ }
+ }
+
+ /**
+ * It tries to get set by given key. If it is set then removes value and puts new modified set back.
+ */
+ public static class RemoveFromListContainerExpiration extends RemoveFromListContainer
+ {
+
+ public RemoveFromListContainerExpiration(Fqn fqn, Serializable key, Object value, Cache<Serializable, Object> cache,
+ int historicalIndex, boolean local)
+ {
+ super(fqn, key, value, cache, historicalIndex, local);
+ }
+
+ @Override
+ public void apply()
+ {
+ // force writeLock on next read
+ cache.getInvocationContext().getOptionOverrides().setForceWriteLock(true);
+ // object found by FQN and key;
+ setCacheLocalMode();
+ 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);
+
+ setCacheLocalMode();
+ cache.put(fqn, ExpirationAlgorithmConfig.EXPIRATION_KEY, new Long(System.currentTimeMillis() + expirationTimeOut));
+
+ setCacheLocalMode();
+ cache.put(fqn, key, newSet);
+ }
+ }
+ }
+
+ public ChangesContainer createPutObjectContainer(Fqn fqn, Map<? extends Serializable, ? extends Object> data,
+ Cache<Serializable, Object> cache, int historicalIndex, boolean local)
+ {
+ return new PutObjectContainerExpiration(fqn, data, cache, historicalIndex, local);
+ }
+
+ public ChangesContainer createPutKeyValueContainer(Fqn fqn, Serializable key, Object value, Cache<Serializable, Object> cache,
+ int historicalIndex, boolean local)
+ {
+ return new PutKeyValueContainerExpiration(fqn, key, value, cache, historicalIndex, local);
+ }
+
+ public ChangesContainer createAddToListContainer(Fqn fqn, Serializable key, Object value, Cache<Serializable, Object> cache,
+ int historicalIndex, boolean local)
+ {
+ return new AddToListContainerExpiration(fqn, key, value, cache, historicalIndex, local);
+ }
+
+ public ChangesContainer createRemoveFromListContainer(Fqn fqn, Serializable key, Object value, Cache<Serializable, Object> cache,
+ int historicalIndex, boolean local)
+ {
+ return new RemoveFromListContainerExpiration(fqn, key, value, cache, historicalIndex, local);
+ }
+
+}
Property changes on: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/ChangesContainerExpirationFactory.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/ChangesContainerFactory.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/ChangesContainerFactory.java (rev 0)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/ChangesContainerFactory.java 2010-04-08 10:03:00 UTC (rev 2223)
@@ -0,0 +1,335 @@
+/*
+ * 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.dataflow.persistent.jbosscache;
+
+import java.io.Serializable;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache.BufferedJBossCache.ChangesType;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+import org.jboss.cache.Cache;
+import org.jboss.cache.Fqn;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * <br/>Date: 2010
+ *
+ * @author <a href="mailto:alex.reshetnyak@exoplatform.com.ua">Alex Reshetnyak</a>
+ * @version $Id$
+ */
+public class ChangesContainerFactory
+{
+ protected static final Log LOG =
+ ExoLogger.getLogger("org.exoplatform." +
+ "services.jcr.impl.dataflow.persistent.jbosscache.ChangesContatinerFactory");
+
+ /**
+ * Container for changes
+ */
+ public static abstract class ChangesContainer implements Comparable<ChangesContainer>
+ {
+ protected final Fqn fqn;
+
+ protected final ChangesType changesType;
+
+ protected final Cache<Serializable, Object> cache;
+
+ protected final int historicalIndex;
+
+ protected final boolean localMode;
+
+ public ChangesContainer(Fqn fqn, ChangesType changesType, Cache<Serializable, Object> cache, int historicalIndex,
+ boolean localMode)
+ {
+ super();
+ this.fqn = fqn;
+ this.changesType = changesType;
+ this.cache = cache;
+ this.historicalIndex = historicalIndex;
+ this.localMode = localMode;
+ }
+
+ /**
+ * @return the fqn
+ */
+ public Fqn getFqn()
+ {
+ return fqn;
+ }
+
+ /**
+ * @return the index of change in original sequence
+ */
+ public int getHistoricalIndex()
+ {
+ return historicalIndex;
+ }
+
+ /**
+ * @return the changesType
+ */
+ public ChangesType getChangesType()
+ {
+ return changesType;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString()
+ {
+ return fqn + " type=" + changesType + " historyIndex=" + historicalIndex;
+ }
+
+ public int compareTo(ChangesContainer o)
+ {
+ int result = fqn.compareTo(o.getFqn());
+ return result == 0 ? historicalIndex - o.getHistoricalIndex() : result;
+ }
+
+ protected void setCacheLocalMode()
+ {
+ cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(localMode);
+ }
+
+ public abstract void apply();
+ }
+
+ /**
+ * Put object container;
+ */
+ public static class PutObjectContainer extends ChangesContainer
+ {
+ protected final Map<? extends Serializable, ? extends Object> data;
+
+ public PutObjectContainer(Fqn fqn, Map<? extends Serializable, ? extends Object> data,
+ Cache<Serializable, Object> cache, int historicalIndex, boolean local)
+ {
+ super(fqn, ChangesType.PUT, cache, historicalIndex, local);
+
+ this.data = data;
+ }
+
+ @Override
+ public void apply()
+ {
+ setCacheLocalMode();
+ cache.put(fqn, data);
+ }
+ }
+
+ /**
+ * Put container.
+ */
+ public static class PutKeyValueContainer extends ChangesContainer
+ {
+ protected final Serializable key;
+
+ protected final Object value;
+
+ public PutKeyValueContainer(Fqn fqn, Serializable key, Object value, Cache<Serializable, Object> cache,
+ int historicalIndex, boolean local)
+ {
+ super(fqn, ChangesType.PUT_KEY, cache, historicalIndex, local);
+ this.key = key;
+ this.value = value;
+ }
+
+ @Override
+ public void apply()
+ {
+ setCacheLocalMode();
+ cache.put(fqn, key, value);
+ }
+
+ public Serializable getKey()
+ {
+ return key;
+ }
+
+ public Object getValue()
+ {
+ return value;
+ }
+
+ }
+
+ /**
+ * It tries to get Set by given key. If it is Set then adds new value and puts new set back.
+ * If null found, then new Set created (ordinary cache does).
+ */
+ public static class AddToListContainer extends ChangesContainer
+ {
+ protected final Serializable key;
+
+ protected final Object value;
+
+ public AddToListContainer(Fqn fqn, Serializable key, Object value, Cache<Serializable, Object> cache,
+ int historicalIndex, boolean local)
+ {
+ super(fqn, ChangesType.PUT_KEY, cache, historicalIndex, local);
+ 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);
+ setCacheLocalMode();
+ cache.put(fqn, key, newSet);
+ }
+ else
+ {
+ LOG.error("Unexpected object found by FQN:" + getFqn() + " and key:" + key + ". Expected Set, but found:"
+ + existingObject.getClass().getName());
+ }
+ }
+ }
+
+ /**
+ * It tries to get set by given key. If it is set then removes value and puts new modified set back.
+ */
+ public static class RemoveFromListContainer extends ChangesContainer
+ {
+ protected final Serializable key;
+
+ protected final Object value;
+
+ public RemoveFromListContainer(Fqn fqn, Serializable key, Object value, Cache<Serializable, Object> cache,
+ int historicalIndex, boolean local)
+ {
+ super(fqn, ChangesType.REMOVE_KEY, cache, historicalIndex, local);
+ 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;
+ setCacheLocalMode();
+ 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);
+ setCacheLocalMode();
+ cache.put(fqn, key, newSet);
+ }
+ }
+ }
+
+ /**
+ * Remove container.
+ */
+ public static class RemoveKeyContainer extends ChangesContainer
+ {
+ private final Serializable key;
+
+ 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;
+ }
+
+ @Override
+ public void apply()
+ {
+ setCacheLocalMode();
+ cache.remove(fqn, key);
+ }
+
+ }
+
+ /**
+ * Remove container.
+ */
+ public static class RemoveNodeContainer extends ChangesContainer
+ {
+
+ public RemoveNodeContainer(Fqn fqn, Cache<Serializable, Object> cache, int historicalIndex, boolean local)
+ {
+ super(fqn, ChangesType.REMOVE, cache, historicalIndex, local);
+ }
+
+ @Override
+ public void apply()
+ {
+ setCacheLocalMode();
+ cache.removeNode(fqn);
+ }
+ }
+
+ public ChangesContainer createPutObjectContainer(Fqn fqn, Map<? extends Serializable, ? extends Object> data,
+ Cache<Serializable, Object> cache, int historicalIndex, boolean local)
+ {
+ return new PutObjectContainer(fqn, data, cache, historicalIndex, local);
+ }
+
+ public ChangesContainer createPutKeyValueContainer(Fqn fqn, Serializable key, Object value, Cache<Serializable, Object> cache,
+ int historicalIndex, boolean local)
+ {
+ return new PutKeyValueContainer(fqn, key, value, cache, historicalIndex, local);
+ }
+
+ public ChangesContainer createAddToListContainer(Fqn fqn, Serializable key, Object value, Cache<Serializable, Object> cache,
+ int historicalIndex, boolean local)
+ {
+ return new AddToListContainer(fqn, key, value, cache, historicalIndex, local);
+ }
+
+ public ChangesContainer createRemoveFromListContainer(Fqn fqn, Serializable key, Object value, Cache<Serializable, Object> cache,
+ int historicalIndex, boolean local)
+ {
+ return new RemoveFromListContainer(fqn, key, value, cache, historicalIndex, local);
+ }
+
+ public ChangesContainer createRemoveKeyContainer(Fqn fqn, Serializable key, Cache<Serializable, Object> cache, int historicalIndex,
+ boolean local)
+ {
+ return new RemoveKeyContainer(fqn, key, cache, historicalIndex, local);
+ }
+
+ public ChangesContainer createRemoveNodeContainer(Fqn fqn, Cache<Serializable, Object> cache, int historicalIndex, boolean local)
+ {
+ return new RemoveNodeContainer(fqn, cache, historicalIndex, local);
+ }
+
+}
Property changes on: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/ChangesContainerFactory.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/CompressedChangesBuffer.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/CompressedChangesBuffer.java 2010-04-08 10:02:57 UTC (rev 2222)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/CompressedChangesBuffer.java 2010-04-08 10:03:00 UTC (rev 2223)
@@ -18,16 +18,16 @@
*/
package org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache;
-import org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache.BufferedJBossCache.ChangesContainer;
-import org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache.BufferedJBossCache.ChangesType;
-import org.jboss.cache.Fqn;
-
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache.BufferedJBossCache.ChangesType;
+import org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache.ChangesContainerFactory.ChangesContainer;
+import org.jboss.cache.Fqn;
+
/**
* Sorting cache modification "as is" in {@link BufferedJBossCache} may harm data consistency.
* Here is a link, showing possible trouble:
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java 2010-04-08 10:02:57 UTC (rev 2222)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java 2010-04-08 10:03:00 UTC (rev 2223)
@@ -307,7 +307,7 @@
}
// TODO: create appropriate cache with useExpiration set or not.
- this.cache = new BufferedJBossCache(factory.createCache(wsConfig.getCache()));
+ this.cache = new BufferedJBossCache(factory.createCache(wsConfig.getCache()), new ChangesContainerExpirationFactory());
this.itemsRoot = Fqn.fromElements(ITEMS);
this.childNodes = Fqn.fromElements(CHILD_NODES);
Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/TestCompressedChangesBuffer.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/TestCompressedChangesBuffer.java 2010-04-08 10:02:57 UTC (rev 2222)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/TestCompressedChangesBuffer.java 2010-04-08 10:03:00 UTC (rev 2223)
@@ -18,15 +18,15 @@
*/
package org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache;
+import java.util.HashMap;
+
import junit.framework.TestCase;
-import org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache.BufferedJBossCache.ChangesContainer;
-import org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache.BufferedJBossCache.PutObjectContainer;
-import org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache.BufferedJBossCache.RemoveNodeContainer;
+import org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache.ChangesContainerFactory.ChangesContainer;
+import org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache.ChangesContainerFactory.PutObjectContainer;
+import org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache.ChangesContainerFactory.RemoveNodeContainer;
import org.jboss.cache.Fqn;
-import java.util.HashMap;
-
/**
* @author <a href="mailto:foo@bar.org">Foo Bar</a>
* @version $Id: exo-jboss-codetemplates.xml 34360 2009-07-22 23:58:59Z aheritier $
Modified: jcr/trunk/exo.jcr.component.core/src/test/resources/conf/standalone/test-jbosscache-config.xml
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/resources/conf/standalone/test-jbosscache-config.xml 2010-04-08 10:02:57 UTC (rev 2222)
+++ jcr/trunk/exo.jcr.component.core/src/test/resources/conf/standalone/test-jbosscache-config.xml 2010-04-08 10:03:00 UTC (rev 2223)
@@ -15,7 +15,7 @@
actionPolicyClass="org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache.ParentNodeEvictionActionPolicy"
eventQueueSize="1000000">
<property name="maxNodes" value="50000" />
- <property name="warnNoExpirationKey" value="true" />
+ <property name="warnNoExpirationKey" value="false" />
</default>
</eviction>
16 years, 3 months
exo-jcr SVN: r2222 - jcr/branches/1.14.x.
by do-not-reply@jboss.org
Author: pnedonosko
Date: 2010-04-08 06:02:57 -0400 (Thu, 08 Apr 2010)
New Revision: 2222
Modified:
jcr/branches/1.14.x/pom.xml
Log:
EXOJCR-604 deps on doc-style v1
Modified: jcr/branches/1.14.x/pom.xml
===================================================================
--- jcr/branches/1.14.x/pom.xml 2010-04-08 09:51:38 UTC (rev 2221)
+++ jcr/branches/1.14.x/pom.xml 2010-04-08 10:02:57 UTC (rev 2222)
@@ -42,7 +42,7 @@
<org.exoplatform.kernel.version>2.2.1-GA-SNAPSHOT</org.exoplatform.kernel.version>
<org.exoplatform.core.version>2.4.0-Beta01-SNAPSHOT</org.exoplatform.core.version>
<org.exoplatform.ws.version>2.1.1-GA-SNAPSHOT</org.exoplatform.ws.version>
- <org.exoplatform.doc-style.version>2-SNAPSHOT</org.exoplatform.doc-style.version>
+ <org.exoplatform.doc-style.version>2</org.exoplatform.doc-style.version>
</properties>
<dependencyManagement>
<dependencies>
16 years, 3 months
exo-jcr SVN: r2221 - jcr/trunk/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-04-08 05:51:38 -0400 (Thu, 08 Apr 2010)
New Revision: 2221
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java
Log:
EXOJCR-545: Added JBossCache configuration analyzer.
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java 2010-04-08 07:22:21 UTC (rev 2220)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java 2010-04-08 09:51:38 UTC (rev 2221)
@@ -38,8 +38,11 @@
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
import org.exoplatform.services.transaction.TransactionService;
+import org.jboss.cache.Cache;
import org.jboss.cache.Fqn;
import org.jboss.cache.Node;
+import org.jboss.cache.config.EvictionRegionConfig;
+import org.jboss.cache.eviction.ExpirationAlgorithm;
import java.io.Serializable;
import java.util.ArrayList;
@@ -65,24 +68,24 @@
* <ul>
* <li>/$ITEMS - stores items by Id (i.e. /$ITEMS/itemId)</li>
* <li>/$CHILD_NODES, /$CHILD_PROPS - stores items by parentId and name (i.e. /$CHILD_NODES/parentId/childName.$ITEM_ID)</li>
- * <li>/$CHILD_NODES_LIST, /$CHILD_PROPS_LIST - stores child list by parentId and child Id
+ * <li>/$CHILD_NODES_LIST, /$CHILD_PROPS_LIST - stores child list by parentId and child Id
* (i.e. /$CHILD_NODES_LIST/parentId.lists = serialized Set<Object>)</li>
* </ul>
- * </li>
+ * </li>
* <li>all child properties/nodes lists should be evicted from parent at same time
* i.e. for /$CHILD_NODES_LIST, /$CHILD_PROPS_LIST we need customized eviction policy (EvictionActionPolicy) to evict
* whole list on one of childs eviction
- * </li>
+ * </li>
* </ul>
*
- * <p/>
- * Current state notes (subject of change):
+ * <p/>
+ * Current state notes (subject of change):
* <ul>
* <li>cache implements WorkspaceStorageCache, without any stuff about references and locks</li>
* <li>transaction style implemented via JBC barches, do with JTA (i.e. via exo's TransactionService + JBoss TM)</li>
* <li>we need customized eviction policy (EvictionActionPolicy) for /$CHILD_NODES_LIST, /$CHILD_PROPS_LIST</li>
* </ul>
- *
+ *
* @author <a href="mailto:peter.nedonosko@exoplatform.com">Peter Nedonosko</a>
* @version $Id: JBossCacheWorkspaceStorageCache.java 13869 2008-05-05 08:40:10Z pnedonosko $
*/
@@ -253,7 +256,7 @@
*/
public JBossCacheWorkspaceStorageCache(WorkspaceEntry wsConfig, TransactionService transactionService,
ConfigurationManager cfm) throws RepositoryException, RepositoryConfigurationException
- {
+ {
if (wsConfig.getCache() == null)
{
throw new RepositoryConfigurationException("Cache configuration not found");
@@ -271,6 +274,39 @@
factory = new ExoJBossCacheFactory<Serializable, Object>(cfm);
}
+ // create parent JBossCache instance
+ Cache<Serializable, Object> parentCache = factory.createCache(wsConfig.getCache());
+ // get all eviction configurations
+ List<EvictionRegionConfig> evictionConfigurations =
+ parentCache.getConfiguration().getEvictionConfig().getEvictionRegionConfigs();
+ // append and default eviction configuration, since it is not present in region configurations
+ evictionConfigurations.add(parentCache.getConfiguration().getEvictionConfig().getDefaultEvictionRegionConfig());
+
+ boolean useExpiration = false;
+ Iterator<EvictionRegionConfig> iterator = evictionConfigurations.iterator();
+
+ // looking over all eviction configurations till the end or till some expiration algorithm subclass not found.
+ while (iterator.hasNext() && !useExpiration)
+ {
+ try
+ {
+ String evictionClassName = iterator.next().getEvictionAlgorithmConfig().getEvictionAlgorithmClassName();
+ Class<?> evictionClass = Class.forName(evictionClassName);
+ // returns true if ExpirationAlgorithm is superClass of evictionClass
+ useExpiration = useExpiration || ExpirationAlgorithm.class.isAssignableFrom(evictionClass);
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new RepositoryConfigurationException("Unable to check JBossCache eviction class.", e);
+ }
+ }
+
+ if (useExpiration)
+ {
+ LOG.info("Using BufferedJBossCache compatible with Expiration algorithm.");
+ }
+
+ // TODO: create appropriate cache with useExpiration set or not.
this.cache = new BufferedJBossCache(factory.createCache(wsConfig.getCache()));
this.itemsRoot = Fqn.fromElements(ITEMS);
@@ -287,17 +323,17 @@
createResidentNode(childProps);
createResidentNode(childPropsList);
createResidentNode(itemsRoot);
- }
+ }
/**
* Cache constructor with JBossCache JTA transaction support.
*
- * @param wsConfig WorkspaceEntry workspace config
+ * @param wsConfig WorkspaceEntry workspace config
* @throws RepositoryException if error of initialization
* @throws RepositoryConfigurationException if error of configuration
*/
public JBossCacheWorkspaceStorageCache(WorkspaceEntry wsConfig, ConfigurationManager cfm)
- throws RepositoryException, RepositoryConfigurationException
+ throws RepositoryException, RepositoryConfigurationException
{
this(wsConfig, null, cfm);
}
@@ -336,7 +372,7 @@
/**
* Return TransactionManager used by JBossCache backing the JCR cache.
*
- * @return TransactionManager
+ * @return TransactionManager
*/
public TransactionManager getTransactionManager()
{
@@ -406,8 +442,8 @@
{
if (state.isPersisted())
{
- // There was a problem with removing a list of samename siblings in on transaction,
- // so putItemInBufferedCache(..) and updateInBufferedCache(..) used instead put(..) and update (..) methods.
+ // There was a problem with removing a list of samename siblings in on transaction,
+ // so putItemInBufferedCache(..) and updateInBufferedCache(..) used instead put(..) and update (..) methods.
ItemData prevItem = putItemInBufferedCache(state.getData());
if (prevItem != null && state.isNode())
{
@@ -446,8 +482,8 @@
}
/**
- * {@inheritDoc}
- */
+ * {@inheritDoc}
+ */
public void addChildNodes(NodeData parent, List<NodeData> childs)
{
boolean inTransaction = cache.isTransactionActive();
@@ -541,7 +577,7 @@
// {
// cache.beginTransaction();
// cache.setLocal(true);
- //
+ //
// }
// finally
// {
@@ -632,7 +668,7 @@
/**
* Internal get child properties.
*
- * @param parentId String
+ * @param parentId String
* @param withValue boolean, if true only "full" Propeties can be returned
* @return List of PropertyData
*/
@@ -777,7 +813,7 @@
{
// add in CHILD_NODES
cache.put(makeChildFqn(childNodes, node.getParentIdentifier(), node.getQPath().getEntries()[node.getQPath()
- .getEntries().length - 1]), ITEM_ID, node.getIdentifier());
+ .getEntries().length - 1]), ITEM_ID, node.getIdentifier());
// if MODIFY and List present OR FORCE_MODIFY, then write
if ((modifyListsOfChild == ModifyChildOption.MODIFY && cache.getNode(makeChildListFqn(childNodesList, node
.getParentIdentifier())) != null)
@@ -798,7 +834,7 @@
{
// add in CHILD_NODES
cache.put(makeChildFqn(childNodes, node.getParentIdentifier(), node.getQPath().getEntries()[node.getQPath()
- .getEntries().length - 1]), ITEM_ID, node.getIdentifier());
+ .getEntries().length - 1]), ITEM_ID, node.getIdentifier());
// if MODIFY and List present OR FORCE_MODIFY, then write
if ((modifyListsOfChild == ModifyChildOption.MODIFY && cache.getNode(makeChildListFqn(childNodesList, node
.getParentIdentifier())) != null)
@@ -822,7 +858,7 @@
{
// add in CHILD_PROPS
cache.put(makeChildFqn(childProps, prop.getParentIdentifier(), prop.getQPath().getEntries()[prop.getQPath()
- .getEntries().length - 1]), ITEM_ID, prop.getIdentifier());
+ .getEntries().length - 1]), ITEM_ID, prop.getIdentifier());
// if MODIFY and List present OR FORCE_MODIFY, then write
if ((modifyListsOfChild == ModifyChildOption.MODIFY && cache.getNode(makeChildListFqn(childPropsList, prop
.getParentIdentifier())) != null)
@@ -844,7 +880,7 @@
// remove from CHILD_NODES of parent
cache.removeNode(makeChildFqn(childNodes, item.getParentIdentifier(), item.getQPath().getEntries()[item
- .getQPath().getEntries().length - 1]));
+ .getQPath().getEntries().length - 1]));
// remove from CHILD_NODES_LIST of parent
cache.removeFromList(makeChildListFqn(childNodesList, item.getParentIdentifier()), ITEM_LIST, item
@@ -867,7 +903,7 @@
{
// remove from CHILD_PROPS
cache.removeNode(makeChildFqn(childProps, item.getParentIdentifier(), item.getQPath().getEntries()[item
- .getQPath().getEntries().length - 1]));
+ .getQPath().getEntries().length - 1]));
// remove from CHILD_PROPS_LIST
cache.removeFromList(makeChildListFqn(childPropsList, item.getParentIdentifier()), ITEM_LIST, item
@@ -900,7 +936,7 @@
}
/**
- * Update Node hierachy in case of same-name siblings reorder.
+ * Update Node hierachy in case of same-name siblings reorder.
* Assumes the new (updated) nodes already putted in the cache. Previous name of updated nodes will be calculated
* and that node will be deleted (if has same id as the new node). Childs paths will be updated to a new node path.
*
@@ -912,7 +948,7 @@
// get previously cached NodeData and using its name remove child on the parent
Fqn<String> prevFqn =
makeChildFqn(childNodes, node.getParentIdentifier(), prevNode.getQPath().getEntries()[prevNode.getQPath()
- .getEntries().length - 1]);
+ .getEntries().length - 1]);
if (node.getIdentifier().equals(cache.get(prevFqn, ITEM_ID)))
{
// it's same-name siblings re-ordering, delete previous child
@@ -942,7 +978,7 @@
// get previously cached NodeData and using its name remove child on the parent
Fqn<String> prevFqn =
makeChildFqn(childNodes, node.getParentIdentifier(), prevNode.getQPath().getEntries()[prevNode.getQPath()
- .getEntries().length - 1]);
+ .getEntries().length - 1]);
if (node.getIdentifier().equals(cache.getFromBuffer(prevFqn, ITEM_ID)))
{
// it's same-name siblings re-ordering, delete previous child
@@ -978,15 +1014,15 @@
PropertyData prevProp = iter.next();
if (inheritACL
- && (prevProp.getQPath().getName().equals(Constants.EXO_PERMISSIONS) || prevProp.getQPath().getName()
- .equals(Constants.EXO_OWNER)))
+ && (prevProp.getQPath().getName().equals(Constants.EXO_PERMISSIONS) || prevProp.getQPath().getName()
+ .equals(Constants.EXO_OWNER)))
{
inheritACL = false;
}
// recreate with new path for child Props only
QPath newPath =
QPath
- .makeChildPath(rootPath, prevProp.getQPath().getEntries()[prevProp.getQPath().getEntries().length - 1]);
+ .makeChildPath(rootPath, prevProp.getQPath().getEntries()[prevProp.getQPath().getEntries().length - 1]);
TransientPropertyData newProp =
new TransientPropertyData(newPath, prevProp.getIdentifier(), prevProp.getPersistedVersion(), prevProp
.getType(), prevProp.getParentIdentifier(), prevProp.isMultiValued(), prevProp.getValues());
@@ -1000,7 +1036,7 @@
// recreate with new path for child Nodes only
QPath newPath =
QPath
- .makeChildPath(rootPath, prevNode.getQPath().getEntries()[prevNode.getQPath().getEntries().length - 1]);
+ .makeChildPath(rootPath, prevNode.getQPath().getEntries()[prevNode.getQPath().getEntries().length - 1]);
TransientNodeData newNode =
new TransientNodeData(newPath, prevNode.getIdentifier(), prevNode.getPersistedVersion(), prevNode
.getPrimaryTypeName(), prevNode.getMixinTypeNames(), prevNode.getOrderNumber(), prevNode
@@ -1035,7 +1071,7 @@
TransientNodeData newNode =
new TransientNodeData(prevNode.getQPath(), prevNode.getIdentifier(), prevNode.getPersistedVersion(),
prevNode.getPrimaryTypeName(), prevNode.getMixinTypeNames(), prevNode.getOrderNumber(), prevNode
- .getParentIdentifier(), acl);
+ .getParentIdentifier(), acl);
// update this node
cache.put(makeItemFqn(newNode.getIdentifier()), ITEM_DATA, newNode);
// update childs recursive
16 years, 3 months
exo-jcr SVN: r2220 - jcr/branches/1.14.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent.
by do-not-reply@jboss.org
Author: tolusha
Date: 2010-04-08 03:22:21 -0400 (Thu, 08 Apr 2010)
New Revision: 2220
Modified:
jcr/branches/1.14.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/LinkedWorkspaceStorageCacheImpl.java
Log:
EXOJCR-609: skipp NullNodeData in LinkedWorkspaceStorageCacheImpl
Modified: jcr/branches/1.14.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/LinkedWorkspaceStorageCacheImpl.java
===================================================================
--- jcr/branches/1.14.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/LinkedWorkspaceStorageCacheImpl.java 2010-04-08 07:16:37 UTC (rev 2219)
+++ jcr/branches/1.14.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/LinkedWorkspaceStorageCacheImpl.java 2010-04-08 07:22:21 UTC (rev 2220)
@@ -26,6 +26,7 @@
import org.exoplatform.services.jcr.dataflow.persistent.WorkspaceStorageCache;
import org.exoplatform.services.jcr.datamodel.ItemData;
import org.exoplatform.services.jcr.datamodel.NodeData;
+import org.exoplatform.services.jcr.datamodel.NullNodeData;
import org.exoplatform.services.jcr.datamodel.PropertyData;
import org.exoplatform.services.jcr.datamodel.QPath;
import org.exoplatform.services.jcr.datamodel.QPathEntry;
@@ -917,6 +918,12 @@
if (enabled && item != null)
{
+ if (item instanceof NullNodeData)
+ {
+ // skip null values
+ return;
+ }
+
writeLock.lock();
try
{
16 years, 3 months
exo-jcr SVN: r2219 - in jcr/trunk/exo.jcr.component.core/src: test/resources/conf/standalone and 1 other directory.
by do-not-reply@jboss.org
Author: areshetnyak
Date: 2010-04-08 03:16:37 -0400 (Thu, 08 Apr 2010)
New Revision: 2219
Added:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCacheExp.java
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCache.java
jcr/trunk/exo.jcr.component.core/src/test/resources/conf/standalone/test-jbosscache-config.xml
Log:
EXOJCR-545 : Add implementation BufferedJBossCache with ExpitationAlgorithm
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCache.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCache.java 2010-04-07 14:03:09 UTC (rev 2218)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCache.java 2010-04-08 07:16:37 UTC (rev 2219)
@@ -30,6 +30,7 @@
import org.jboss.cache.NodeNotExistsException;
import org.jboss.cache.Region;
import org.jboss.cache.config.Configuration;
+import org.jboss.cache.eviction.ExpirationAlgorithmConfig;
import org.jboss.cache.interceptors.base.CommandInterceptor;
import org.jgroups.Address;
@@ -668,6 +669,18 @@
public static enum ChangesType {
REMOVE, REMOVE_KEY, PUT, PUT_KEY, PUT_TO_LIST;
}
+
+ protected static void putMap(Fqn fqn, Map<? extends Serializable, ? extends Object> data, Cache<Serializable, Object> cache, boolean localMode)
+ {
+ cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(localMode);
+ cache.put(fqn, data);
+ }
+
+ protected static void putObject(Fqn fqn, Serializable key, Object value, Cache<Serializable, Object> cache, boolean localMode)
+ {
+ cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(localMode);
+ cache.put(fqn, key, value);
+ }
/**
* Container for changes
@@ -760,8 +773,7 @@
@Override
public void apply()
{
- setCacheLocalMode();
- cache.put(fqn, data);
+ putMap(fqn, data, cache, localMode);
}
}
@@ -785,8 +797,7 @@
@Override
public void apply()
{
- setCacheLocalMode();
- cache.put(fqn, key, value);
+ putObject(fqn, key, value, cache, localMode);
}
}
@@ -825,8 +836,8 @@
newSet.addAll((Set<Object>)existingObject);
}
newSet.add(value);
- setCacheLocalMode();
- cache.put(fqn, key, newSet);
+
+ putObject(fqn, key, newSet, cache, localMode);
}
else
{
@@ -866,8 +877,8 @@
{
Set<Object> newSet = new HashSet<Object>((Set<Object>)existingObject);
newSet.remove(value);
- setCacheLocalMode();
- cache.put(fqn, key, newSet);
+
+ putObject(fqn, key, newSet, cache, localMode);
}
}
}
Added: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCacheExp.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCacheExp.java (rev 0)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCacheExp.java 2010-04-08 07:16:37 UTC (rev 2219)
@@ -0,0 +1,84 @@
+/*
+ * 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.dataflow.persistent.jbosscache;
+
+import java.io.Serializable;
+import java.util.Map;
+
+import org.jboss.cache.Cache;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.eviction.ExpirationAlgorithmConfig;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * <br/>Date: 2010
+ *
+ * @author <a href="mailto:alex.reshetnyak@exoplatform.com.ua">Alex Reshetnyak</a>
+ * @version $Id$
+ */
+public class BufferedJBossCacheExp extends BufferedJBossCache
+{
+ /**
+ * The expiration timeout.
+ */
+ public final static long DEFAULT_EXPIRATION_TIMEOUT = 900000; // 15 minutes.
+
+ public final long expirationTimeOut;
+
+ public BufferedJBossCacheExp(Cache<Serializable, Object> parentCache, long expirationTimeOut)
+ {
+ super(parentCache);
+ this.expirationTimeOut = expirationTimeOut;
+ }
+
+ public BufferedJBossCacheExp(Cache<Serializable, Object> parentCache)
+ {
+ super(parentCache);
+ this.expirationTimeOut = DEFAULT_EXPIRATION_TIMEOUT;
+ }
+
+ protected static void putMap(Fqn fqn, Map<? extends Serializable, ? extends Object> data, Cache<Serializable, Object> cache, boolean localMode)
+ {
+ putExpiration(fqn, cache, localMode);
+
+ cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(localMode);
+ cache.put(fqn, data);
+
+ cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(localMode);
+ cache.put(fqn, ExpirationAlgorithmConfig.EXPIRATION_KEY, new Long(System.currentTimeMillis() + DEFAULT_EXPIRATION_TIMEOUT));
+ }
+
+ protected static void putObject(Fqn fqn, Serializable key, Object value, Cache<Serializable, Object> cache, boolean localMode)
+ {
+ cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(localMode);
+ cache.put(fqn, key, value);
+ }
+
+ public static void putExpiration(Fqn efqn, Cache<Serializable, Object> cache, boolean localMode)
+ {
+ for (int i = 2; i <= efqn.size(); i++)
+ {
+ Fqn pfqn = efqn.getSubFqn(0, i);
+ cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(localMode);
+ cache.put(pfqn, ExpirationAlgorithmConfig.EXPIRATION_KEY, new Long(System.currentTimeMillis() + DEFAULT_EXPIRATION_TIMEOUT));
+ }
+ }
+
+
+
+}
Property changes on: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCacheExp.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Modified: jcr/trunk/exo.jcr.component.core/src/test/resources/conf/standalone/test-jbosscache-config.xml
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/resources/conf/standalone/test-jbosscache-config.xml 2010-04-07 14:03:09 UTC (rev 2218)
+++ jcr/trunk/exo.jcr.component.core/src/test/resources/conf/standalone/test-jbosscache-config.xml 2010-04-08 07:16:37 UTC (rev 2219)
@@ -11,9 +11,11 @@
<!-- Eviction configuration -->
<eviction wakeUpInterval="5000">
- <default algorithmClass="org.jboss.cache.eviction.FIFOAlgorithm" actionPolicyClass="org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache.ParentNodeEvictionActionPolicy" eventQueueSize="1000000">
- <property name="maxNodes" value="5000" />
- <property name="minTimeToLive" value="60000" />
+ <default algorithmClass="org.jboss.cache.eviction.ExpirationAlgorithm"
+ actionPolicyClass="org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache.ParentNodeEvictionActionPolicy"
+ eventQueueSize="1000000">
+ <property name="maxNodes" value="50000" />
+ <property name="warnNoExpirationKey" value="true" />
</default>
</eviction>
16 years, 3 months
exo-jcr SVN: r2218 - in jcr/branches/1.14.x/exo.jcr.component.core/src: main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache and 1 other directories.
by do-not-reply@jboss.org
Author: tolusha
Date: 2010-04-07 10:03:09 -0400 (Wed, 07 Apr 2010)
New Revision: 2218
Modified:
jcr/branches/1.14.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CacheableWorkspaceDataManager.java
jcr/branches/1.14.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCache.java
jcr/branches/1.14.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java
jcr/branches/1.14.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/TestCacheableWorkspaceDataManager.java
Log:
EXOJCR-609: store missing values
Modified: jcr/branches/1.14.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CacheableWorkspaceDataManager.java
===================================================================
--- jcr/branches/1.14.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CacheableWorkspaceDataManager.java 2010-04-07 13:07:13 UTC (rev 2217)
+++ jcr/branches/1.14.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CacheableWorkspaceDataManager.java 2010-04-07 14:03:09 UTC (rev 2218)
@@ -25,6 +25,7 @@
import org.exoplatform.services.jcr.datamodel.InternalQName;
import org.exoplatform.services.jcr.datamodel.ItemData;
import org.exoplatform.services.jcr.datamodel.NodeData;
+import org.exoplatform.services.jcr.datamodel.NullNodeData;
import org.exoplatform.services.jcr.datamodel.PropertyData;
import org.exoplatform.services.jcr.datamodel.QPath;
import org.exoplatform.services.jcr.datamodel.QPathEntry;
@@ -483,7 +484,7 @@
fixPropertyValues((PropertyData)data);
}
- return data == ITEM_DATA_NULL_VALUE ? null : data;
+ return data instanceof NullNodeData ? null : data;
}
/**
@@ -492,10 +493,10 @@
@Override
public ItemData getItemData(String identifier) throws RepositoryException
{
- // 2. Try from cache
+ // 1. Try from cache
ItemData data = getCachedItemData(identifier);
- // 3. Try from container
+ // 2 Try from container
if (data == null)
{
final DataRequest request = new DataRequest(identifier);
@@ -525,7 +526,7 @@
fixPropertyValues((PropertyData)data);
}
- return data == ITEM_DATA_NULL_VALUE ? null : data;
+ return data instanceof NullNodeData ? null : data;
}
/**
@@ -533,7 +534,7 @@
*/
@Override
public List<PropertyData> getReferencesData(String identifier, boolean skipVersionStorage)
- throws RepositoryException
+ throws RepositoryException
{
return super.getReferencesData(identifier, skipVersionStorage);
}
@@ -610,7 +611,7 @@
* Repository error
*/
protected List<NodeData> getChildNodesData(NodeData nodeData, boolean forcePersistentRead)
- throws RepositoryException
+ throws RepositoryException
{
List<NodeData> childNodes = null;
@@ -667,7 +668,7 @@
* Repository error
*/
protected List<PropertyData> getChildPropertiesData(NodeData nodeData, boolean forcePersistentRead)
- throws RepositoryException
+ throws RepositoryException
{
List<PropertyData> childProperties = null;
@@ -729,7 +730,7 @@
ItemData data = super.getItemData(parentData, name);
if (cache.isEnabled())
{
- cache.put(data == null ? ITEM_DATA_NULL_VALUE : data);
+ cache.put(data == null ? new NullNodeData(parentData, name) : data);
}
return data;
}
@@ -746,7 +747,14 @@
ItemData data = super.getItemData(identifier);
if (cache.isEnabled())
{
- cache.put(data == null ? ITEM_DATA_NULL_VALUE : data);
+ if (data != null)
+ {
+ cache.put(data);
+ }
+ else if (identifier != null)
+ {
+ cache.put(new NullNodeData(identifier));
+ }
}
return data;
}
@@ -763,7 +771,7 @@
* Repository error
*/
protected List<PropertyData> listChildPropertiesData(NodeData nodeData, boolean forcePersistentRead)
- throws RepositoryException
+ throws RepositoryException
{
List<PropertyData> propertiesList;
@@ -857,7 +865,7 @@
* @throws RepositoryException
*/
protected ValueData getPropertyValue(String propertyId, int orderNumb, int persistedVersion)
- throws IllegalStateException, RepositoryException
+ throws IllegalStateException, RepositoryException
{
// TODO use interface not JDBC
JDBCStorageConnection conn = (JDBCStorageConnection)dataContainer.openConnection();
Modified: jcr/branches/1.14.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCache.java
===================================================================
--- jcr/branches/1.14.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCache.java 2010-04-07 13:07:13 UTC (rev 2217)
+++ jcr/branches/1.14.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCache.java 2010-04-07 14:03:09 UTC (rev 2218)
@@ -156,6 +156,14 @@
this.local.set(local);
}
+ /**
+ * Returns current state.
+ */
+ public boolean isLocal()
+ {
+ return this.local.get();
+ }
+
public int getNumberOfNodes()
{
return ((CacheSPI<Serializable, Object>)parentCache).getNumberOfNodes();
Modified: jcr/branches/1.14.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java
===================================================================
--- jcr/branches/1.14.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java 2010-04-07 13:07:13 UTC (rev 2217)
+++ jcr/branches/1.14.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java 2010-04-07 14:03:09 UTC (rev 2218)
@@ -28,6 +28,7 @@
import org.exoplatform.services.jcr.datamodel.InternalQName;
import org.exoplatform.services.jcr.datamodel.ItemData;
import org.exoplatform.services.jcr.datamodel.NodeData;
+import org.exoplatform.services.jcr.datamodel.NullNodeData;
import org.exoplatform.services.jcr.datamodel.PropertyData;
import org.exoplatform.services.jcr.datamodel.QPath;
import org.exoplatform.services.jcr.datamodel.QPathEntry;
@@ -95,6 +96,8 @@
public static final String ITEMS = "$ITEMS".intern();
+ public static final String NULL_ITEMS = "$NULL_ITEMS".intern();
+
public static final String CHILD_NODES = "$CHILD_NODES".intern();
public static final String CHILD_PROPS = "$CHILD_PROPS".intern();
@@ -115,6 +118,8 @@
protected final Fqn<String> itemsRoot;
+ protected final Fqn<String> nullItemsRoot;
+
protected final Fqn<String> childNodes;
protected final Fqn<String> childProps;
@@ -274,6 +279,7 @@
this.cache = new BufferedJBossCache(factory.createCache(wsConfig.getCache()));
this.itemsRoot = Fqn.fromElements(ITEMS);
+ this.nullItemsRoot = Fqn.fromElements(NULL_ITEMS);
this.childNodes = Fqn.fromElements(CHILD_NODES);
this.childProps = Fqn.fromElements(CHILD_PROPS);
this.childNodesList = Fqn.fromElements(CHILD_NODES_LIST);
@@ -287,6 +293,7 @@
createResidentNode(childProps);
createResidentNode(childPropsList);
createResidentNode(itemsRoot);
+ createResidentNode(nullItemsRoot);
}
/**
@@ -356,13 +363,21 @@
cache.beginTransaction();
}
cache.setLocal(true);
- if (item.isNode())
+
+ if (item instanceof NullNodeData)
{
- putNode((NodeData)item, ModifyChildOption.NOT_MODIFY);
+ putNullNode((NullNodeData)item);
}
else
{
- putProperty((PropertyData)item, ModifyChildOption.NOT_MODIFY);
+ if (item.isNode())
+ {
+ putNode((NodeData)item, ModifyChildOption.NOT_MODIFY);
+ }
+ else
+ {
+ putProperty((PropertyData)item, ModifyChildOption.NOT_MODIFY);
+ }
}
}
finally
@@ -557,18 +572,19 @@
// get as node first
String itemId = (String)cache.get(makeChildFqn(childNodes, parentId, name), ITEM_ID);
- if (itemId == null)
+ if (itemId != null)
{
- // try as property
- itemId = (String)cache.get(makeChildFqn(childProps, parentId, name), ITEM_ID);
+ return getFromCacheById(itemId);
}
+ // try as property
+ itemId = (String)cache.get(makeChildFqn(childProps, parentId, name), ITEM_ID);
if (itemId != null)
{
- return get(itemId);
+ return getFromCacheById(itemId);
}
- return null;
+ return (ItemData)cache.get(makeNullItemFqn(parentId + "$" + name.getAsString(true)), ITEM_DATA);
}
/**
@@ -576,7 +592,9 @@
*/
public ItemData get(String id)
{
- return (ItemData)cache.get(makeItemFqn(id), ITEM_DATA);
+ ItemData data = getFromCacheById(id);
+
+ return data != null ? data : (ItemData)cache.get(makeNullItemFqn(id), ITEM_DATA);
}
/**
@@ -695,6 +713,17 @@
}
/**
+ * Make Item absolute Fqn, i.e. /$NULL_ITEMS/itemID.
+ *
+ * @param itemId String
+ * @return Fqn
+ */
+ protected Fqn<String> makeNullItemFqn(String itemId)
+ {
+ return Fqn.fromRelativeElements(nullItemsRoot, itemId);
+ }
+
+ /**
* Make child Item absolute Fqn, i.e. /root/parentId/childName.
*
* @param root Fqn
@@ -733,6 +762,14 @@
}
/**
+ * Gets item data from cache by item identifier.
+ */
+ protected ItemData getFromCacheById(String id)
+ {
+ return (ItemData)cache.get(makeItemFqn(id), ITEM_DATA);
+ }
+
+ /**
* Internal put Item.
*
* @param item ItemData, new data to put in the cache
@@ -771,6 +808,15 @@
*/
protected ItemData putNode(NodeData node, ModifyChildOption modifyListsOfChild)
{
+
+ // remove possible NullNodeData from cache
+ boolean local = cache.isLocal();
+ cache.setLocal(false);
+
+ removeNullNode(node);
+
+ cache.setLocal(local);
+
// if not a root node
if (node.getParentIdentifier() != null)
{
@@ -790,6 +836,41 @@
return (ItemData)cache.put(makeItemFqn(node.getIdentifier()), ITEM_DATA, node);
}
+ /**
+ * Internal put NullNode.
+ *
+ * @param node, NodeData, new data to put in the cache
+ * @return ItemData, previous data or null
+ */
+ protected ItemData putNullNode(NullNodeData node)
+ {
+ return (ItemData)cache.put(makeNullItemFqn(node.getIdentifier()), ITEM_DATA, node);
+ }
+
+ /**
+ * Removes NullNode from cache.
+ *
+ * @param item
+ * that possible has corresponding NullNode in cache
+ *
+ */
+ protected void removeNullNode(ItemData item)
+ {
+ Fqn<String> fqn = makeNullItemFqn(item.getIdentifier());
+ if ((NullNodeData)cache.get(fqn, ITEM_DATA) != null)
+ {
+ cache.removeNode(fqn);
+ }
+
+ fqn =
+ makeNullItemFqn(item.getParentIdentifier() + "$"
+ + item.getQPath().getEntries()[item.getQPath().getEntries().length - 1].getAsString(true));
+ if (cache.get(fqn, ITEM_DATA) != null)
+ {
+ cache.removeNode(fqn);
+ }
+ }
+
protected ItemData putNodeInBufferedCache(NodeData node, ModifyChildOption modifyListsOfChild)
{
// if not a root node
@@ -819,6 +900,15 @@
*/
protected PropertyData putProperty(PropertyData prop, ModifyChildOption modifyListsOfChild)
{
+
+ // remove possible NullNodeData from cache
+ boolean local = cache.isLocal();
+ cache.setLocal(false);
+
+ removeNullNode(prop);
+
+ cache.setLocal(local);
+
// add in CHILD_PROPS
cache.put(makeChildFqn(childProps, prop.getParentIdentifier(), prop.getQPath().getEntries()[prop.getQPath()
.getEntries().length - 1]), ITEM_ID, prop.getIdentifier());
@@ -829,6 +919,10 @@
{
cache.addToList(makeChildListFqn(childPropsList, prop.getParentIdentifier()), ITEM_LIST, prop.getIdentifier());
}
+
+ ItemData result =
+ get(prop.getParentIdentifier(), prop.getQPath().getEntries()[prop.getQPath().getEntries().length - 1]);
+
// add in ITEMS
return (PropertyData)cache.put(makeItemFqn(prop.getIdentifier()), ITEM_DATA, prop);
}
Modified: jcr/branches/1.14.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/TestCacheableWorkspaceDataManager.java
===================================================================
--- jcr/branches/1.14.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/TestCacheableWorkspaceDataManager.java 2010-04-07 13:07:13 UTC (rev 2217)
+++ jcr/branches/1.14.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/TestCacheableWorkspaceDataManager.java 2010-04-07 14:03:09 UTC (rev 2218)
@@ -24,7 +24,9 @@
import org.exoplatform.services.jcr.dataflow.persistent.WorkspaceStorageCache;
import org.exoplatform.services.jcr.datamodel.ItemData;
import org.exoplatform.services.jcr.datamodel.NodeData;
+import org.exoplatform.services.jcr.datamodel.NullNodeData;
import org.exoplatform.services.jcr.datamodel.PropertyData;
+import org.exoplatform.services.jcr.datamodel.QPath;
import org.exoplatform.services.jcr.datamodel.QPathEntry;
import org.exoplatform.services.jcr.datamodel.ValueData;
import org.exoplatform.services.jcr.impl.storage.SystemDataContainerHolder;
@@ -163,7 +165,8 @@
public void testGetItemDataByNodeDataNQPathEntry() throws Exception
{
- final NodeData nodeData = new PersistedNodeData("getItemData", null, null, 0, 1, null, null, null);
+ final NodeData nodeData =
+ new PersistedNodeData("getItemData", new QPath(new QPathEntry[]{}), null, 0, 1, null, null, null);
assertEquals(0, con.getItemDataByNodeDataNQPathEntryCalls.get());
MyTask task = new MyTask()
{
16 years, 3 months