[exo-jcr-commits] exo-jcr SVN: r2280 - jcr/branches/1.14.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core.
do-not-reply at jboss.org
do-not-reply at jboss.org
Thu Apr 15 04:45:41 EDT 2010
Author: tolusha
Date: 2010-04-15 04:45:40 -0400 (Thu, 15 Apr 2010)
New Revision: 2280
Modified:
jcr/branches/1.14.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SessionDataManager.java
Log:
EXOJCR-420: ItemReferencePool implemented with WeakHashMap<String, WeakReference<ItemImpl>>
Modified: jcr/branches/1.14.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SessionDataManager.java
===================================================================
--- jcr/branches/1.14.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SessionDataManager.java 2010-04-14 11:49:35 UTC (rev 2279)
+++ jcr/branches/1.14.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SessionDataManager.java 2010-04-15 08:45:40 UTC (rev 2280)
@@ -47,6 +47,7 @@
import org.exoplatform.services.log.Log;
import java.io.IOException;
+import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -924,22 +925,25 @@
Collection<ItemImpl> pooledItems = itemsPool.getAll();
for (ItemImpl item : pooledItems)
{
- if (item.getInternalPath().isDescendantOf(fromItem.getQPath())
- || item.getInternalPath().equals(fromItem.getQPath()))
+ if (item != null)
{
- ItemData ri = getItemData(item.getInternalIdentifier());
- if (ri != null)
+ if (item.getInternalPath().isDescendantOf(fromItem.getQPath())
+ || item.getInternalPath().equals(fromItem.getQPath()))
{
- itemsPool.reload(ri);
+ ItemData ri = getItemData(item.getInternalIdentifier());
+ if (ri != null)
+ {
+ itemsPool.reload(ri);
+ }
+ else
+ {
+ // the item is invalid, case of version restore - the item from non
+ // current version
+ item.invalidate();
+ }
+
+ invalidated.add(item);
}
- else
- {
- // the item is invalid, case of version restore - the item from non
- // current version
- item.invalidate();
- }
-
- invalidated.add(item);
}
}
}
@@ -1141,7 +1145,7 @@
// We can't remove this VH now.
return;
} // else -- if we has a references in workspace where the VH is being
- // deleted we can remove VH now.
+ // deleted we can remove VH now.
}
}
finally
@@ -1959,25 +1963,31 @@
protected final class ItemReferencePool
{
- private WeakHashMap<String, ItemImpl> items;
+ private WeakHashMap<String, WeakReference<ItemImpl>> items;
- //private WeakHashMap<String, ItemData> datas;
-
ItemReferencePool()
{
- items = new WeakHashMap<String, ItemImpl>();
- //datas = new WeakHashMap<String, ItemData>();
+ items = new WeakHashMap<String, WeakReference<ItemImpl>>();
}
ItemImpl remove(String identifier)
{
- //datas.remove(identifier);
- return items.remove(identifier);
+ WeakReference<ItemImpl> weakItem = items.remove(identifier);
+ return weakItem != null ? weakItem.get() : null;
}
Collection<ItemImpl> getAll()
{
- return items.values();
+ List<ItemImpl> list = new ArrayList<ItemImpl>();
+ for (WeakReference<ItemImpl> weakItem : items.values())
+ {
+ if (weakItem != null)
+ {
+ list.add(weakItem.get());
+ }
+ }
+
+ return list;
}
int size()
@@ -2018,23 +2028,20 @@
ItemImpl get(final ItemData newData, final NodeData parent) throws RepositoryException
{
final String identifier = newData.getIdentifier();
- ItemImpl item = items.get(identifier);
+
+ WeakReference<ItemImpl> weakItem = items.get(identifier);
+ ItemImpl item = weakItem != null ? weakItem.get() : null;
+
if (item != null)
{
item.loadData(newData, parent);
}
else
{
- // ItemData preloaded = datas.remove(identifier);
- // item =
- // itemFactory.createItem(preloaded != null
- // && preloaded.getPersistedVersion() > newData.getPersistedVersion() ? preloaded : newData);
- //datas.remove(identifier);
-
// TODO if (changesLog.get) check if DELETED!!
item = itemFactory.createItem(newData, parent);
- items.put(item.getInternalIdentifier(), item);
+ items.put(item.getInternalIdentifier(), new WeakReference<ItemImpl>(item));
}
return item;
}
@@ -2054,16 +2061,14 @@
ItemImpl reload(String identifier, ItemData newItemData) throws RepositoryException
{
- ItemImpl item = items.get(identifier);
+ WeakReference<ItemImpl> weakItem = items.get(identifier);
+ ItemImpl item = weakItem != null ? weakItem.get() : null;
+
if (item != null)
{
item.loadData(newItemData);
return item;
}
- // else
- // {
- // datas.put(identifier, newItemData);
- // }
return null;
}
@@ -2081,10 +2086,13 @@
for (NodeImpl node : nodes)
{
String id = node.getInternalIdentifier();
- NodeImpl pooled = (NodeImpl)items.get(id);
+
+ WeakReference<ItemImpl> weakItem = items.get(id);
+ NodeImpl pooled = weakItem != null ? (NodeImpl)weakItem.get() : null;
+
if (pooled == null)
{
- items.put(id, node);
+ items.put(id, new WeakReference<ItemImpl>(node));
children.add(node);
}
else
@@ -2110,10 +2118,13 @@
for (PropertyImpl prop : props)
{
String id = prop.getInternalIdentifier();
- PropertyImpl pooled = (PropertyImpl)items.get(id);
+
+ WeakReference<ItemImpl> weakItem = items.get(id);
+ PropertyImpl pooled = weakItem != null ? (PropertyImpl)weakItem.get() : null;
+
if (pooled == null)
{
- items.put(id, prop);
+ items.put(id, new WeakReference<ItemImpl>(prop));
children.add(prop);
}
else
@@ -2135,12 +2146,15 @@
{
List<ItemImpl> desc = new ArrayList<ItemImpl>();
- Collection<ItemImpl> snapshort = items.values();
+ Collection<ItemImpl> snapshort = getAll();
for (ItemImpl pitem : snapshort)
{
- if (pitem.getData().getQPath().isDescendantOf(parentPath))
+ if (pitem != null)
{
- desc.add(pitem);
+ if (pitem.getData().getQPath().isDescendantOf(parentPath))
+ {
+ desc.add(pitem);
+ }
}
}
@@ -2152,11 +2166,14 @@
String str = "Items Pool: \n";
try
{
- for (ItemImpl item : items.values())
+ for (ItemImpl item : getAll())
{
- str +=
- (item.isNode() ? "Node\t\t" : "Property\t") + "\t" + item.isValid() + "\t" + item.isNew() + "\t"
- + item.getInternalIdentifier() + "\t" + item.getPath() + "\n";
+ if (item != null)
+ {
+ str +=
+ (item.isNode() ? "Node\t\t" : "Property\t") + "\t" + item.isValid() + "\t" + item.isNew() + "\t"
+ + item.getInternalIdentifier() + "\t" + item.getPath() + "\n";
+ }
}
}
catch (Exception e)
More information about the exo-jcr-commits
mailing list