summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-09-12 11:33:46 (EDT)
committerEike Stepper2007-09-12 11:33:46 (EDT)
commitb11f4eda02caf5f1f41d7d1103b7308a99da56b4 (patch)
tree1c33ce6fe305833bc38884a0421c4d5d1f0adf42
parent3df10783a4f7664004c7e6ef2adc62516bea3a0f (diff)
downloadcdo-b11f4eda02caf5f1f41d7d1103b7308a99da56b4.zip
cdo-b11f4eda02caf5f1f41d7d1103b7308a99da56b4.tar.gz
cdo-b11f4eda02caf5f1f41d7d1103b7308a99da56b4.tar.bz2
[202064] More client-side intelligence (SmartReadAhead Thread)
https://bugs.eclipse.org/bugs/show_bug.cgi?id=202064
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/LoadRevisionIndication.java47
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/FetchRuleAnalyzerTest.java105
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/analyzer/CDOFetchRuleManager.java5
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOAbstractFeatureRuleAnalyzer.java118
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOAnalyzerFeatureInfo.java119
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOClusterOfFetchRule.java94
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDODynamicFetchRuleAnalyzer.java210
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOFeatureAnalyzerModelBased.java61
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOFeatureAnalyzerUI.java128
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOFetchFeatureInfo.java44
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOFetchRuleManagerThreadLocal.java (renamed from plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDODynamicFetchRuleManager.java)16
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOGraph.java112
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOGraphAnalyzer.java111
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/NOOPFetchRuleManager.java7
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/protocol/LoadRevisionRequest.java8
15 files changed, 648 insertions, 537 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/LoadRevisionIndication.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/LoadRevisionIndication.java
index 042b0e8..44a27a1 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/LoadRevisionIndication.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/LoadRevisionIndication.java
@@ -11,8 +11,6 @@
package org.eclipse.emf.cdo.internal.server.protocol;
import org.eclipse.emf.cdo.internal.protocol.CDOIDImpl;
-import org.eclipse.emf.cdo.internal.protocol.CDOIDNull;
-import org.eclipse.emf.cdo.internal.protocol.analyzer.CDOFetchRule;
import org.eclipse.emf.cdo.internal.protocol.revision.CDORevisionImpl;
import org.eclipse.emf.cdo.internal.protocol.revision.CDORevisionImpl.MoveableList;
import org.eclipse.emf.cdo.internal.server.RevisionManager;
@@ -20,6 +18,7 @@ import org.eclipse.emf.cdo.internal.server.Session;
import org.eclipse.emf.cdo.internal.server.bundle.OM;
import org.eclipse.emf.cdo.protocol.CDOID;
import org.eclipse.emf.cdo.protocol.CDOProtocolConstants;
+import org.eclipse.emf.cdo.protocol.analyzer.CDOFetchRule;
import org.eclipse.emf.cdo.protocol.model.CDOClass;
import org.eclipse.emf.cdo.protocol.model.CDOFeature;
@@ -48,7 +47,9 @@ public class LoadRevisionIndication extends CDOReadIndication
protected Map<CDOClass, CDOFetchRule> fetchRules = new HashMap<CDOClass, CDOFetchRule>();
- protected CDOID contextID = CDOIDNull.NULL;
+ protected CDOID contextID;
+
+ protected int loadRevisionCollectionChunkSize;
public LoadRevisionIndication()
{
@@ -80,6 +81,12 @@ public class LoadRevisionIndication extends CDOReadIndication
int fetchSize = in.readInt();
if (fetchSize > 0)
{
+ loadRevisionCollectionChunkSize = in.readInt();
+ if (loadRevisionCollectionChunkSize < 1)
+ {
+ loadRevisionCollectionChunkSize = 1;
+ }
+
contextID = CDOIDImpl.read(in);
if (PROTOCOL.isEnabled()) PROTOCOL.format("Reading fetch rules for context {0}", contextID);
@@ -96,24 +103,28 @@ public class LoadRevisionIndication extends CDOReadIndication
{
Session session = getSession();
List<CDORevisionImpl> additionalRevisions = new ArrayList<CDORevisionImpl>();
- HashSet<CDOID> revisions = new HashSet<CDOID>();
+ Set<CDOID> revisions = new HashSet<CDOID>();
if (PROTOCOL.isEnabled()) PROTOCOL.format("Writing {0} revisions", ids.length);
+ for (CDOID id : ids)
+ {
+ revisions.add(id);
+ }
+
// Need to fetch the rule first.
+ Set<CDOFetchRule> visitedFetchRules = new HashSet<CDOFetchRule>();
if (!contextID.isNull() && fetchRules.size() > 0)
{
if (PROTOCOL.isEnabled()) PROTOCOL.format("Collecting more objects based on rules");
CDORevisionImpl revisionContext = getRevision(contextID);
- Set<CDOFetchRule> workingFetchRules = new HashSet<CDOFetchRule>();
- collectRevisionsByRule(revisionContext, referenceChunk, revisions, additionalRevisions, workingFetchRules);
+ collectRevisions(revisionContext, revisions, additionalRevisions, visitedFetchRules);
}
for (CDOID id : ids)
{
CDORevisionImpl revision = getRevision(id);
revision.write(out, session, referenceChunk);
- revisions.add(revision.getID());
- session.collectContainedRevisions(revision, referenceChunk, revisions, additionalRevisions);
+ collectRevisions(revision, revisions, additionalRevisions, visitedFetchRules);
}
out.writeInt(additionalRevisions.size());
@@ -130,16 +141,17 @@ public class LoadRevisionIndication extends CDOReadIndication
return getRevisionManager().getRevision(id, referenceChunk);
}
- private void collectRevisionsByRule(CDORevisionImpl revision, int referenceChunk, Set<CDOID> revisions,
- List<CDORevisionImpl> additionalRevisions, Set<CDOFetchRule> workingFetchRules)
+ private void collectRevisions(CDORevisionImpl revision, Set<CDOID> revisions,
+ List<CDORevisionImpl> additionalRevisions, Set<CDOFetchRule> visitedFetchRules)
{
+ getSession().collectContainedRevisions(revision, this.referenceChunk, revisions, additionalRevisions);
CDOFetchRule fetchRule = fetchRules.get(revision.getCDOClass());
- if (fetchRule == null || workingFetchRules.contains(fetchRule))
+ if (fetchRule == null || visitedFetchRules.contains(fetchRule))
{
return;
}
- workingFetchRules.add(fetchRule);
+ visitedFetchRules.add(fetchRule);
RevisionManager revisionManager = getSessionManager().getRepository().getRevisionManager();
for (CDOFeature feature : fetchRule.getFeatures())
@@ -147,7 +159,7 @@ public class LoadRevisionIndication extends CDOReadIndication
if (feature.isMany())
{
MoveableList list = revision.getList(feature);
- int toIndex = Math.min(referenceChunk, list.size()) - 1;
+ int toIndex = Math.min(this.loadRevisionCollectionChunkSize, list.size()) - 1;
for (int i = 0; i <= toIndex; i++)
{
Object value = list.get(i);
@@ -159,9 +171,7 @@ public class LoadRevisionIndication extends CDOReadIndication
CDORevisionImpl containedRevision = revisionManager.getRevision(id, referenceChunk);
revisions.add(containedRevision.getID());
additionalRevisions.add(containedRevision);
-
- collectRevisionsByRule(containedRevision, referenceChunk, revisions, additionalRevisions,
- workingFetchRules);
+ collectRevisions(containedRevision, revisions, additionalRevisions, visitedFetchRules);
}
}
}
@@ -177,13 +187,12 @@ public class LoadRevisionIndication extends CDOReadIndication
CDORevisionImpl containedRevision = revisionManager.getRevision(id, referenceChunk);
revisions.add(containedRevision.getID());
additionalRevisions.add(containedRevision);
-
- collectRevisionsByRule(containedRevision, referenceChunk, revisions, additionalRevisions, workingFetchRules);
+ collectRevisions(containedRevision, revisions, additionalRevisions, visitedFetchRules);
}
}
}
}
- workingFetchRules.remove(fetchRule);
+ visitedFetchRules.remove(fetchRule);
}
}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/FetchRuleAnalyzerTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/FetchRuleAnalyzerTest.java
new file mode 100644
index 0000000..feb8524
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/FetchRuleAnalyzerTest.java
@@ -0,0 +1,105 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Simon McDuff - initial API and implementation
+ **************************************************************************/
+package org.eclipse.emf.cdo.tests;
+
+import org.eclipse.emf.cdo.CDOSession;
+import org.eclipse.emf.cdo.CDOTransaction;
+import org.eclipse.emf.cdo.eresource.CDOResource;
+import org.eclipse.emf.cdo.tests.model1.Company;
+import org.eclipse.emf.cdo.tests.model1.Model1Factory;
+import org.eclipse.emf.cdo.tests.model1.PurchaseOrder;
+import org.eclipse.emf.cdo.tests.model1.SalesOrder;
+import org.eclipse.emf.cdo.tests.model1.Supplier;
+
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.eclipse.emf.internal.cdo.CDOSessionImpl;
+import org.eclipse.emf.internal.cdo.CDOTransactionImpl;
+import org.eclipse.emf.internal.cdo.analyzer.CDOFeatureAnalyzerModelBased;
+import org.eclipse.emf.internal.cdo.analyzer.CDOFetchRuleManagerThreadLocal;
+
+/**
+ * @author Eike Stepper
+ */
+public class FetchRuleAnalyzerTest extends AbstractCDOTest
+{
+ public void testLoadObject() throws Exception
+ {
+ {
+ // disableConsole();
+ msg("Opening session");
+ CDOSession session = openModel1Session();
+
+ msg("Opening transaction");
+ CDOTransaction transaction = session.openTransaction(new ResourceSetImpl());
+
+ msg("Creating resource");
+ CDOResource resource = transaction.createResource("/test2");
+
+ msg("Creating supplier");
+ for (int i = 0; i < 10; i++)
+ {
+ Company company = Model1Factory.eINSTANCE.createCompany();
+ company.setCity("CITY" + String.valueOf(i));
+
+ for (int j = 0; j < 10; j++)
+ {
+ PurchaseOrder purchaseOrder = Model1Factory.eINSTANCE.createPurchaseOrder();
+ company.getPurchaseOrders().add(purchaseOrder);
+
+ Supplier supplier = Model1Factory.eINSTANCE.createSupplier();
+
+ // Should it detect supplier to make it persistent...
+ // I don't want to do resource.getContents().add(supplier)
+ purchaseOrder.setSupplier(supplier);
+
+ SalesOrder salesOrder = Model1Factory.eINSTANCE.createSalesOrder();
+ company.getSalesOrders().add(salesOrder);
+ }
+
+ resource.getContents().add(company);
+ }
+
+ transaction.commit();
+ // XXX session.close();
+ enableConsole();
+ }
+
+ msg("Opening session");
+ CDOSessionImpl session = (CDOSessionImpl)openModel1Session();
+
+ session.getRevisionManager().setRuleManager(new CDOFetchRuleManagerThreadLocal());
+
+ msg("Opening transaction");
+ CDOTransactionImpl transaction = session.openTransaction(new ResourceSetImpl());
+
+ CDOFeatureAnalyzerModelBased featureanalyzerModelBased = new CDOFeatureAnalyzerModelBased();
+ transaction.setFeatureAnalyzer(featureanalyzerModelBased);
+ transaction.setLoadRevisionCollectionChunkSize(10);
+
+ msg("Getting resource");
+ CDOResource resource = transaction.getResource("/test2");
+
+ msg("Getting contents");
+ EList<EObject> contents = resource.getContents();
+ for (EObject eObject : contents)
+ {
+ Company company = (Company)eObject;
+ for (PurchaseOrder purchaseOrder : company.getPurchaseOrders())
+ {
+ purchaseOrder.getSupplier();
+ }
+ }
+
+ assertEquals(featureanalyzerModelBased.getFetchCount(), 12);
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/analyzer/CDOFetchRuleManager.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/analyzer/CDOFetchRuleManager.java
index 53b9556..531f3ad 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/analyzer/CDOFetchRuleManager.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/analyzer/CDOFetchRuleManager.java
@@ -14,8 +14,9 @@ package org.eclipse.emf.cdo.analyzer;
import java.util.Collection;
import java.util.List;
-import org.eclipse.emf.cdo.internal.protocol.analyzer.CDOFetchRule;
import org.eclipse.emf.cdo.protocol.CDOID;
+import org.eclipse.emf.cdo.protocol.analyzer.CDOFetchRule;
+
import org.eclipse.emf.internal.cdo.analyzer.NOOPFetchRuleManager;
/**
@@ -28,4 +29,6 @@ public interface CDOFetchRuleManager
public CDOID getContext();
public List<CDOFetchRule> getFetchRules(Collection<CDOID> ids);
+
+ public int getLoadRevisionCollectionChunkSize();
}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOAbstractFeatureRuleAnalyzer.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOAbstractFeatureRuleAnalyzer.java
new file mode 100644
index 0000000..523ebae
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOAbstractFeatureRuleAnalyzer.java
@@ -0,0 +1,118 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Simon McDuff - initial API and implementation
+ * Eike Stepper - maintenance
+ **************************************************************************/
+package org.eclipse.emf.internal.cdo.analyzer;
+
+import org.eclipse.emf.cdo.analyzer.CDOFeatureAnalyzer;
+import org.eclipse.emf.cdo.analyzer.CDOFetchRuleManager;
+import org.eclipse.emf.cdo.protocol.model.CDOFeature;
+import org.eclipse.emf.internal.cdo.InternalCDOObject;
+import org.eclipse.emf.internal.cdo.bundle.OM;
+import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
+
+/**
+ * @author Eike Stepper
+ */
+public abstract class CDOAbstractFeatureRuleAnalyzer implements CDOFeatureAnalyzer, CDOFetchRuleManager
+{
+ private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, CDOAbstractFeatureRuleAnalyzer.class);
+
+ protected CDOFeature lastTraverseFeature;
+
+ protected int lastTraverseIndex;
+
+ protected long lastAccessTime;
+
+ protected long lastElapseTimeBetweenOperations;
+
+ protected InternalCDOObject lastTraverseCDOObject;
+
+ protected long lastLatencyTime;
+
+ protected int loadRevisionCollectionChunkSize;
+
+ /**
+ * TODO Can didFetch be derived from fetchCount?
+ */
+ private boolean didFetch;
+
+ private int fetchCount = 0;
+
+ public CDOAbstractFeatureRuleAnalyzer()
+ {
+ }
+
+ public int getFetchCount()
+ {
+ return fetchCount;
+ }
+
+ public int getLoadRevisionCollectionChunkSize()
+ {
+ return loadRevisionCollectionChunkSize;
+ }
+
+ public void preTraverseFeature(InternalCDOObject cdoObject, CDOFeature feature, int index)
+ {
+ if (TRACER.isEnabled())
+ {
+ TRACER.format("preTraverseFeature : {0}.{1}", cdoObject.cdoClass(), feature.getName());
+ }
+
+ loadRevisionCollectionChunkSize = cdoObject.cdoView().getLoadRevisionCollectionChunkSize();
+ lastTraverseFeature = feature;
+ lastTraverseCDOObject = cdoObject;
+ lastTraverseIndex = index;
+ lastElapseTimeBetweenOperations = System.currentTimeMillis() - lastAccessTime;
+ lastAccessTime = System.currentTimeMillis();
+ didFetch = false;
+
+ CDOFetchRuleManagerThreadLocal.join(this);
+ doPreTraverseFeature(cdoObject, feature, index);
+ }
+
+ public void postTraverseFeature(InternalCDOObject cdoObject, CDOFeature feature, int index, Object value)
+ {
+ if (TRACER.isEnabled())
+ {
+ TRACER.format("postTraverseFeature : {0}.{1}", cdoObject.cdoClass(), feature.getName());
+ }
+
+ try
+ {
+ doPostTraverseFeature(cdoObject, feature, index, value);
+ }
+ finally
+ {
+ CDOFetchRuleManagerThreadLocal.leave();
+ lastAccessTime = System.currentTimeMillis();
+ }
+ }
+
+ protected void doPreTraverseFeature(InternalCDOObject cdoObject, CDOFeature feature, int index)
+ {
+ }
+
+ protected void doPostTraverseFeature(InternalCDOObject cdoObject, CDOFeature feature, int index, Object value)
+ {
+ }
+
+ protected void fetchData()
+ {
+ didFetch = true;
+ fetchCount++;
+ }
+
+ protected boolean didFetch()
+ {
+ return didFetch;
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOAnalyzerFeatureInfo.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOAnalyzerFeatureInfo.java
new file mode 100644
index 0000000..bfd52ce
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOAnalyzerFeatureInfo.java
@@ -0,0 +1,119 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Simon McDuff - initial API and implementation
+ * Eike Stepper - maintenance
+ **************************************************************************/
+
+package org.eclipse.emf.internal.cdo.analyzer;
+
+import org.eclipse.emf.cdo.protocol.analyzer.CDOFetchRule;
+import org.eclipse.emf.cdo.protocol.model.CDOClass;
+import org.eclipse.emf.cdo.protocol.model.CDOFeature;
+
+import org.eclipse.emf.internal.cdo.bundle.OM;
+
+import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author Eike Stepper
+ */
+public class CDOAnalyzerFeatureInfo
+{
+ private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, CDOAnalyzerFeatureInfo.class);
+
+ private Map<CDOFetchFeatureInfo, CDOFetchFeatureInfo> featureStats = new HashMap<CDOFetchFeatureInfo, CDOFetchFeatureInfo>();
+
+ private Map<CDOClass, CDOFetchRule> fetchRules = new HashMap<CDOClass, CDOFetchRule>();
+
+ public CDOAnalyzerFeatureInfo()
+ {
+ }
+
+ public Collection<CDOFetchRule> getRules(CDOClass cdoClass, CDOFeature cdoFeature)
+ {
+ return fetchRules.values();
+ }
+
+ public synchronized CDOFetchFeatureInfo getFeatureStat(CDOClass cdoClass, CDOFeature cdoFeature)
+ {
+ CDOFetchFeatureInfo search = new CDOFetchFeatureInfo(cdoClass, cdoFeature);
+ CDOFetchFeatureInfo featureRule = featureStats.get(search);
+ if (featureRule == null)
+ {
+ featureRule = search;
+ featureStats.put(search, featureRule);
+ }
+
+ return featureRule;
+ }
+
+ public boolean isActive(CDOClass cdoClass, CDOFeature cdoFeature)
+ {
+ CDOFetchFeatureInfo search = new CDOFetchFeatureInfo(cdoClass, cdoFeature);
+ CDOFetchFeatureInfo featureRule = featureStats.get(search);
+ return featureRule != null && featureRule.isActive();
+ }
+
+ public void activate(CDOClass cdoClass, CDOFeature cdoFeature)
+ {
+ CDOFetchFeatureInfo info = getFeatureStat(cdoClass, cdoFeature);
+ if (!info.isActive())
+ {
+ info.setActive(true);
+ addRule(cdoClass, cdoFeature);
+ }
+ }
+
+ public void deactivate(CDOClass cdoClass, CDOFeature cdoFeature)
+ {
+ CDOFetchFeatureInfo info = getFeatureStat(cdoClass, cdoFeature);
+ if (info.isActive())
+ {
+ info.setActive(false);
+ removeRule(cdoClass, cdoFeature);
+ }
+ }
+
+ private void addRule(CDOClass cdoClass, CDOFeature cdoFeature)
+ {
+ if (TRACER.isEnabled())
+ {
+ TRACER.format("Adding rule : {0}.{1}", cdoClass.getName(), cdoFeature.getName());
+ }
+
+ CDOFetchRule fetchRule = fetchRules.get(cdoClass);
+ if (fetchRule == null)
+ {
+ fetchRule = new CDOFetchRule(cdoClass);
+ fetchRules.put(cdoClass, fetchRule);
+ }
+
+ fetchRule.addFeature(cdoFeature);
+ }
+
+ private void removeRule(CDOClass cdoClass, CDOFeature cdoFeature)
+ {
+ if (TRACER.isEnabled())
+ {
+ TRACER.format("Removing rule : {0}.{1}", cdoClass.getName(), cdoFeature.getName());
+ }
+
+ CDOFetchRule fetchRule = fetchRules.get(cdoClass);
+ if (fetchRule == null)
+ {
+ return;
+ }
+
+ fetchRule.removeFeature(cdoFeature);
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOClusterOfFetchRule.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOClusterOfFetchRule.java
index e48941e..b044e30 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOClusterOfFetchRule.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOClusterOfFetchRule.java
@@ -11,112 +11,60 @@
**************************************************************************/
package org.eclipse.emf.internal.cdo.analyzer;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
-import org.eclipse.emf.cdo.internal.protocol.analyzer.CDOFetchRule;
import org.eclipse.emf.cdo.protocol.model.CDOClass;
import org.eclipse.emf.cdo.protocol.model.CDOFeature;
-import org.eclipse.emf.internal.cdo.bundle.OM;
-import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
/**
* @author Eike Stepper
*/
public class CDOClusterOfFetchRule
{
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, CDOClusterOfFetchRule.class);
-
- private Map<CDOFeature, CDOFetchFeatureInfo> featureStats = new HashMap<CDOFeature, CDOFetchFeatureInfo>();
-
- private Map<CDOClass, CDOFetchRule> fetchRules = new HashMap<CDOClass, CDOFetchRule>();
+ private CDOAnalyzerFeatureInfo featureInfo = new CDOAnalyzerFeatureInfo();
private CDOFeature rootFeature;
+ private CDOClass rootClass;
+
private long lastUpdate;
- public CDOClusterOfFetchRule(CDOFeature rootFeature)
+ public CDOClusterOfFetchRule(CDOClass rootClass, CDOFeature rootFeature)
{
this.rootFeature = rootFeature;
+ this.rootClass = rootClass;
lastUpdate = System.currentTimeMillis();
}
- public boolean isActive()
- {
- return !fetchRules.isEmpty();
- }
-
- public Iterator<CDOFetchRule> iterator()
+ public CDOFeature getRootFeature()
{
- return fetchRules.values().iterator();
+ return rootFeature;
}
- public synchronized CDOFetchFeatureInfo getFeatureStat(CDOFeature cdoFeature)
+ public CDOAnalyzerFeatureInfo getFeatureInfo()
{
- CDOFetchFeatureInfo featureRule = featureStats.get(cdoFeature);
- if (featureRule == null)
- {
- featureRule = new CDOFetchFeatureInfo();
- featureStats.put(cdoFeature, featureRule);
- }
-
- return featureRule;
+ return featureInfo;
}
- public synchronized CDOFetchRule addFeatureRule(CDOClass cdoClass, CDOFeature cdoFeature)
+ public long getLastUpdate()
{
- if (TRACER.isEnabled())
- {
- TRACER.format("Adding new fetch rule : {0}.{1} from root feature {2}", cdoClass.getName(), cdoFeature.getName(),
- rootFeature);
- }
-
- lastUpdate = System.currentTimeMillis();
- CDOFetchRule fetchRule = getFetchRule(cdoClass);
- fetchRule.addFeature(cdoFeature);
- return fetchRule;
+ return lastUpdate;
}
- public synchronized CDOFetchRule removeFeatureRule(CDOClass cdoClass, CDOFeature cdoFeature)
+ @Override
+ public int hashCode()
{
- if (TRACER.isEnabled())
- {
- TRACER.format("Removing fetch rule : {0}.{1} from root feature {2}", cdoClass.getName(), cdoFeature.getName(),
- rootFeature);
- }
-
- lastUpdate = System.currentTimeMillis();
-
- CDOFetchRule fetchRule = getFetchRule(cdoClass);
- fetchRule.removeFeature(cdoFeature);
- if (fetchRule.isEmpty())
- {
- fetchRules.remove(cdoClass);
- }
-
- return fetchRule;
+ // TODO Missing "rootClass.hashCode() ^ " or intention?
+ return rootFeature.hashCode();
}
- public synchronized CDOFetchRule getFetchRule(CDOClass cdoFeature)
+ @Override
+ public boolean equals(Object object)
{
- CDOFetchRule featureRule = fetchRules.get(cdoFeature);
- if (featureRule == null)
+ if (object instanceof CDOClusterOfFetchRule)
{
- featureRule = new CDOFetchRule(cdoFeature);
- fetchRules.put(cdoFeature, featureRule);
+ CDOClusterOfFetchRule featureInfo = (CDOClusterOfFetchRule)object;
+ return featureInfo.rootClass == rootClass && featureInfo.rootFeature == rootFeature;
}
- return featureRule;
- }
-
- public long getLastUpdate()
- {
- return lastUpdate;
- }
-
- public CDOFeature getRootFeature()
- {
- return rootFeature;
+ return false;
}
}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDODynamicFetchRuleAnalyzer.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDODynamicFetchRuleAnalyzer.java
deleted file mode 100644
index 864a9d0..0000000
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDODynamicFetchRuleAnalyzer.java
+++ /dev/null
@@ -1,210 +0,0 @@
-/***************************************************************************
- * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Simon McDuff - initial API and implementation
- * Eike Stepper - maintenance
- **************************************************************************/
-package org.eclipse.emf.internal.cdo.analyzer;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.emf.cdo.CDOView;
-import org.eclipse.emf.cdo.analyzer.CDOFeatureAnalyzer;
-import org.eclipse.emf.cdo.analyzer.CDOFetchRuleManager;
-import org.eclipse.emf.cdo.internal.protocol.analyzer.CDOFetchRule;
-import org.eclipse.emf.cdo.protocol.CDOID;
-import org.eclipse.emf.cdo.protocol.model.CDOClass;
-import org.eclipse.emf.cdo.protocol.model.CDOFeature;
-import org.eclipse.emf.internal.cdo.InternalCDOObject;
-import org.eclipse.emf.internal.cdo.bundle.OM;
-import org.eclipse.emf.internal.cdo.util.FSMUtil;
-import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
-
-/**
- * @author Eike Stepper
- */
-public class CDODynamicFetchRuleAnalyzer implements CDOFeatureAnalyzer, CDOFetchRuleManager
-{
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, CDODynamicFetchRuleAnalyzer.class);
-
- private static final long ELAPSE_TIME = 400L;
-
- private Map<CDOFeature, CDOClusterOfFetchRule> featureRules = new HashMap<CDOFeature, CDOClusterOfFetchRule>();
-
- private CDOGraphAnalyzer graphAnalyzer = new CDOGraphAnalyzer();
-
- private CDOGraph currentGraph;
-
- private long lastAccessTime;
-
- private boolean inUse;
-
- private InternalCDOObject lastRevision;
-
- private CDOView view;
-
- private boolean doesFetch;
-
- public CDODynamicFetchRuleAnalyzer(CDOView view)
- {
- this.view = view;
- }
-
- public CDOClusterOfFetchRule getCurrentFeatureRule()
- {
- return currentGraph.getFeatureRule();
- }
-
- public CDOGraph getCurrentGraph()
- {
- return currentGraph;
- }
-
- public void preTraverseFeature(InternalCDOObject cdoObject, CDOFeature feature, int index)
- {
- CDOClass cdoClass = cdoObject.cdoClass();
- doesFetch = false;
- CDODynamicFetchRuleManager.join(this);
- lastRevision = cdoObject;
- if (TRACER.isEnabled())
- {
- TRACER.format("preTraverseFeature : {0}.{1}", cdoClass.getName(), feature.getName());
- }
-
- // Do not handle these cases
- long currentTime = System.currentTimeMillis();
- long elapseTimeBeforeLastRequest = currentTime - lastAccessTime;
- lastAccessTime = currentTime;
-
- // Don`t handle containment relationship
- if (!feature.isReference())
- {
- return;
- }
-
- if (elapseTimeBeforeLastRequest > ELAPSE_TIME)
- {
- graphAnalyzer.clear();
- }
-
- // Purge old graph that we didn't update for specific elapse time
- graphAnalyzer.purge(ELAPSE_TIME * 2, ELAPSE_TIME * 2);
-
- CDOClusterOfFetchRule featureRule = getFeatureRule(cdoClass, feature);
-
- // Get the graph <cdoObject> belongs to
- currentGraph = graphAnalyzer.getGraph(cdoObject.cdoID(), featureRule);
- lastAccessTime = System.currentTimeMillis();
-
- if (currentGraph.getFeatureRule().getRootFeature() == feature)
- {
- if (graphAnalyzer.isTimeToRemove(currentGraph, lastAccessTime, ELAPSE_TIME))
- {
- // Clean it!!
- currentGraph.clean();
- return;
- }
- }
-
- // need to calculate currentFeature to calculate the connected graph
- if (feature.isMany() && index != 0)
- {
- return;
- }
-
- // Get the cluster of rule for that feature
- CDOClusterOfFetchRule currentFeatureRule = currentGraph.getFeatureRule();
- CDOFetchFeatureInfo infoOfFeature = currentFeatureRule.getFeatureStat(feature);
- infoOfFeature.updateTimeInfo(elapseTimeBeforeLastRequest);
-
- // Detect a new rule
- if (!infoOfFeature.isActive() && infoOfFeature.getTimeBeforeUsed() < ELAPSE_TIME)
- {
- currentFeatureRule.addFeatureRule(cdoClass, feature);
- infoOfFeature.setActive(true);
- }
-
- // Detect if the rule is still good!
- else if (infoOfFeature.isActive() && infoOfFeature.getTimeBeforeUsed() > ELAPSE_TIME)
- {
- // Unregister rules
- currentFeatureRule.removeFeatureRule(cdoClass, feature);
- infoOfFeature.setActive(false);
- }
-
- lastAccessTime = currentTime;
- inUse = true;
- }
-
- public void postTraverseFeature(InternalCDOObject cdoObject, CDOFeature feature, int index, Object object)
- {
- if (TRACER.isEnabled())
- {
- TRACER.format("postTraverseFeature : {0}.{1}", cdoObject.cdoClass(), feature.getName());
- }
-
- if (currentGraph != null)
- {
- // Adding return object to the link graph
- InternalCDOObject destObject = FSMUtil.adapt(object, view);
- currentGraph.add(cdoObject.cdoID(), feature, destObject.cdoID());
-
- // calculate latency time
- if (doesFetch == true)
- {
- CDOClusterOfFetchRule currentFeatureRule = currentGraph.getFeatureRule();
- CDOFetchFeatureInfo infoOfFeature = currentFeatureRule.getFeatureStat(feature);
- infoOfFeature.updateLatencyTime(System.currentTimeMillis() - lastAccessTime);
- }
- }
-
- lastAccessTime = System.currentTimeMillis();
- inUse = false;
- CDODynamicFetchRuleManager.leave();
- }
-
- public CDOID getContext()
- {
- return lastRevision.cdoID();
- }
-
- public synchronized CDOClusterOfFetchRule getFeatureRule(CDOClass cdoClass, CDOFeature cdoFeature)
- {
- CDOClusterOfFetchRule featureRule = featureRules.get(cdoFeature);
- if (featureRule == null)
- {
- featureRule = new CDOClusterOfFetchRule(cdoFeature);
- featureRules.put(cdoFeature, featureRule);
- }
-
- return featureRule;
- }
-
- public List<CDOFetchRule> getFetchRules(Collection<CDOID> ids)
- {
- doesFetch = true;
- if (!inUse || currentGraph == null)
- {
- return null;
- }
-
- List<CDOFetchRule> list = new ArrayList<CDOFetchRule>();
- for (Iterator<CDOFetchRule> it = currentGraph.getFeatureRule().iterator(); it.hasNext();)
- {
- CDOFetchRule fetchRule = it.next();
- list.add(fetchRule);
- }
-
- return list;
- }
-}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOFeatureAnalyzerModelBased.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOFeatureAnalyzerModelBased.java
new file mode 100644
index 0000000..2cdfd89
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOFeatureAnalyzerModelBased.java
@@ -0,0 +1,61 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Simon McDuff - initial API and implementation
+ * Eike Stepper - maintenance
+ **************************************************************************/
+package org.eclipse.emf.internal.cdo.analyzer;
+
+import org.eclipse.emf.cdo.protocol.CDOID;
+import org.eclipse.emf.cdo.protocol.analyzer.CDOFetchRule;
+import org.eclipse.emf.cdo.protocol.model.CDOFeature;
+
+import org.eclipse.emf.internal.cdo.InternalCDOObject;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * @author Eike Stepper
+ */
+public class CDOFeatureAnalyzerModelBased extends CDOAbstractFeatureRuleAnalyzer
+{
+ CDOAnalyzerFeatureInfo featureInfos = new CDOAnalyzerFeatureInfo();
+
+ public CDOFeatureAnalyzerModelBased()
+ {
+ }
+
+ @Override
+ public void doPreTraverseFeature(InternalCDOObject cdoObject, CDOFeature feature, int index)
+ {
+ }
+
+ @Override
+ public void doPostTraverseFeature(InternalCDOObject cdoObject, CDOFeature feature, int index, Object value)
+ {
+ if (didFetch())
+ {
+ featureInfos.activate(cdoObject.cdoClass(), feature);
+ }
+ }
+
+ public CDOID getContext()
+ {
+ return null;
+ }
+
+ public List<CDOFetchRule> getFetchRules(Collection<CDOID> ids)
+ {
+ fetchData();
+ List<CDOFetchRule> rules = new ArrayList<CDOFetchRule>();
+ rules.addAll(featureInfos.getRules(this.lastTraverseCDOObject.cdoClass(), this.lastTraverseFeature));
+ return rules;
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOFeatureAnalyzerUI.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOFeatureAnalyzerUI.java
new file mode 100644
index 0000000..050b936
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOFeatureAnalyzerUI.java
@@ -0,0 +1,128 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Simon McDuff - initial API and implementation
+ * Eike Stepper - maintenance
+ **************************************************************************/
+package org.eclipse.emf.internal.cdo.analyzer;
+
+import org.eclipse.emf.cdo.internal.protocol.CDOIDNull;
+import org.eclipse.emf.cdo.protocol.CDOID;
+import org.eclipse.emf.cdo.protocol.analyzer.CDOFetchRule;
+import org.eclipse.emf.cdo.protocol.model.CDOClass;
+import org.eclipse.emf.cdo.protocol.model.CDOFeature;
+
+import org.eclipse.emf.internal.cdo.InternalCDOObject;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author Eike Stepper
+ */
+public class CDOFeatureAnalyzerUI extends CDOAbstractFeatureRuleAnalyzer
+{
+ private static final long ELAPSE_TIME = 400L;
+
+ private Map<CDOClusterOfFetchRule, CDOClusterOfFetchRule> featureRules = new HashMap<CDOClusterOfFetchRule, CDOClusterOfFetchRule>();
+
+ private CDOClusterOfFetchRule currentClusterOfFetchRule;
+
+ private long maxTimeBetweenOperation;
+
+ public CDOFeatureAnalyzerUI()
+ {
+ this(ELAPSE_TIME);
+ }
+
+ public CDOFeatureAnalyzerUI(long maxTimeBetweenOperation)
+ {
+ this.maxTimeBetweenOperation = maxTimeBetweenOperation;
+ }
+
+ public CDOID getContext()
+ {
+ if (this.lastTraverseFeature.isMany())
+ {
+ return CDOIDNull.NULL;
+ }
+
+ return lastTraverseCDOObject.cdoID();
+ }
+
+ public synchronized CDOClusterOfFetchRule getFeatureRule(CDOClass cdoClass, CDOFeature cdoFeature)
+ {
+ CDOClusterOfFetchRule search = new CDOClusterOfFetchRule(cdoClass, cdoFeature);
+ CDOClusterOfFetchRule featureRule = featureRules.get(search);
+ if (featureRule == null)
+ {
+ featureRule = search;
+ featureRules.put(search, featureRule);
+ }
+
+ return featureRule;
+ }
+
+ public List<CDOFetchRule> getFetchRules(Collection<CDOID> ids)
+ {
+ boolean addRootFeature = true;
+ fetchData();
+
+ if (lastTraverseFeature.isMany())
+ {
+ addRootFeature = false;
+ }
+
+ CDOClusterOfFetchRule search = new CDOClusterOfFetchRule(lastTraverseCDOObject.cdoClass(), lastTraverseFeature);
+ CDOClusterOfFetchRule fetchOfRule = featureRules.get(search);
+ if (fetchOfRule == null)
+ {
+ return null;
+ }
+
+ Collection<CDOFetchRule> fetchRules = fetchOfRule.getFeatureInfo().getRules(null, null);
+ List<CDOFetchRule> list = new ArrayList<CDOFetchRule>();
+ for (CDOFetchRule fetchRule : fetchRules)
+ {
+ if (addRootFeature == true || lastTraverseCDOObject.cdoClass() != fetchRule.getCDOClass())
+ {
+ list.add(fetchRule);
+ }
+ }
+
+ return list;
+ }
+
+ @Override
+ protected void doPreTraverseFeature(InternalCDOObject cdoObject, CDOFeature feature, int index)
+ {
+ // Don`t handle containment relationship
+ if (!feature.isReference())
+ {
+ return;
+ }
+
+ if (lastElapseTimeBetweenOperations > maxTimeBetweenOperation || currentClusterOfFetchRule == null)
+ {
+ // The user interacted with the UI. Restart a new ClusterOfFetchRule
+ currentClusterOfFetchRule = getFeatureRule(cdoObject.cdoClass(), feature);
+ }
+ }
+
+ @Override
+ protected void doPostTraverseFeature(InternalCDOObject cdoObject, CDOFeature feature, int index, Object object)
+ {
+ if (didFetch())
+ {
+ currentClusterOfFetchRule.getFeatureInfo().activate(cdoObject.cdoClass(), feature);
+ }
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOFetchFeatureInfo.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOFetchFeatureInfo.java
index fba9612..69f4c92 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOFetchFeatureInfo.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOFetchFeatureInfo.java
@@ -11,6 +11,9 @@
**************************************************************************/
package org.eclipse.emf.internal.cdo.analyzer;
+import org.eclipse.emf.cdo.protocol.model.CDOClass;
+import org.eclipse.emf.cdo.protocol.model.CDOFeature;
+
/**
* @author Eike Stepper
*/
@@ -22,20 +25,36 @@ public class CDOFetchFeatureInfo
private boolean active;
- public CDOFetchFeatureInfo()
+ private CDOClass cdoClass;
+
+ private CDOFeature cdoFeature;
+
+ public CDOFetchFeatureInfo(CDOClass cdoClass, CDOFeature cdoFeature)
{
+ this.cdoClass = cdoClass;
+ this.cdoFeature = cdoFeature;
active = false;
latencyTime = -1;
}
+ public CDOClass getCDOClass()
+ {
+ return cdoClass;
+ }
+
+ public CDOFeature getCDOFeature()
+ {
+ return cdoFeature;
+ }
+
public boolean isActive()
{
return active;
}
- public void setActive(boolean isActive)
+ public void setActive(boolean active)
{
- active = isActive;
+ this.active = active;
}
public long getTimeBeforeUsed()
@@ -81,4 +100,23 @@ public class CDOFetchFeatureInfo
setTimeBeforeUsed((getTimeBeforeUsed() + elapseTimeBeforeLastRequest) / 2);
}
}
+
+ @Override
+ public int hashCode()
+ {
+ // TODO Missing "cdoClass.hashCode() ^ " or intention?
+ return cdoFeature.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object object)
+ {
+ if (object instanceof CDOFetchFeatureInfo)
+ {
+ CDOFetchFeatureInfo featureInfo = (CDOFetchFeatureInfo)object;
+ return featureInfo.cdoClass == cdoClass && featureInfo.cdoFeature == cdoFeature;
+ }
+
+ return false;
+ }
}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDODynamicFetchRuleManager.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOFetchRuleManagerThreadLocal.java
index e194f59..827adb6 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDODynamicFetchRuleManager.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOFetchRuleManagerThreadLocal.java
@@ -12,8 +12,8 @@
package org.eclipse.emf.internal.cdo.analyzer;
import org.eclipse.emf.cdo.analyzer.CDOFetchRuleManager;
-import org.eclipse.emf.cdo.internal.protocol.analyzer.CDOFetchRule;
import org.eclipse.emf.cdo.protocol.CDOID;
+import org.eclipse.emf.cdo.protocol.analyzer.CDOFetchRule;
import java.util.Collection;
import java.util.List;
@@ -21,11 +21,11 @@ import java.util.List;
/**
* @author Eike Stepper
*/
-public class CDODynamicFetchRuleManager implements CDOFetchRuleManager
+public class CDOFetchRuleManagerThreadLocal implements CDOFetchRuleManager
{
private static final ThreadLocal<CDOFetchRuleManager> threadLocal = new ThreadLocal<CDOFetchRuleManager>();
- public CDODynamicFetchRuleManager()
+ public CDOFetchRuleManagerThreadLocal()
{
}
@@ -46,13 +46,19 @@ public class CDODynamicFetchRuleManager implements CDOFetchRuleManager
public CDOID getContext()
{
- CDOFetchRuleManager analyzer = CDODynamicFetchRuleManager.getCurrent();
+ CDOFetchRuleManager analyzer = CDOFetchRuleManagerThreadLocal.getCurrent();
return analyzer != null ? analyzer.getContext() : null;
}
public List<CDOFetchRule> getFetchRules(Collection<CDOID> ids)
{
- CDOFetchRuleManager analyzer = CDODynamicFetchRuleManager.getCurrent();
+ CDOFetchRuleManager analyzer = CDOFetchRuleManagerThreadLocal.getCurrent();
return analyzer != null ? analyzer.getFetchRules(ids) : null;
}
+
+ public int getLoadRevisionCollectionChunkSize()
+ {
+ CDOFetchRuleManager analyzer = CDOFetchRuleManagerThreadLocal.getCurrent();
+ return analyzer != null ? analyzer.getLoadRevisionCollectionChunkSize() : 0;
+ }
}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOGraph.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOGraph.java
deleted file mode 100644
index 964ed37..0000000
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOGraph.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/***************************************************************************
- * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Simon McDuff - initial API and implementation
- * Eike Stepper - maintenance
- **************************************************************************/
-package org.eclipse.emf.internal.cdo.analyzer;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.eclipse.emf.cdo.protocol.CDOID;
-import org.eclipse.emf.cdo.protocol.model.CDOFeature;
-import org.eclipse.emf.internal.cdo.bundle.OM;
-import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
-
-/**
- * @author Eike Stepper
- */
-public class CDOGraph
-{
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, CDOGraph.class);
-
- private CDOGraphAnalyzer analyzer;
-
- private CDOClusterOfFetchRule featureRule;
-
- private List<CDOID> clusterOfObjects = new ArrayList<CDOID>();
-
- private long lastUpdated;
-
- private long creationTime;
-
- public CDOGraph(CDOGraphAnalyzer analyzer, CDOID rootID, CDOClusterOfFetchRule featureRule)
- {
- this.analyzer = analyzer;
- this.featureRule = featureRule;
- // Adding the root element
- add(rootID, null, rootID);
- creationTime = System.currentTimeMillis();
- }
-
- public List<CDOID> getObjects()
- {
- return clusterOfObjects;
- }
-
- public CDOClusterOfFetchRule getFeatureRule()
- {
- return featureRule;
- }
-
- public long getLastUpdated()
- {
- return lastUpdated;
- }
-
- public long getCreationTime()
- {
- return creationTime;
- }
-
- public CDOID getRoot()
- {
- return getObjects().get(0);
- }
-
- public void clean()
- {
- Iterator<CDOID> itr = clusterOfObjects.iterator();
- itr.next(); // Skip the Root!
- while (itr.hasNext())
- {
- analyzer.removeTrackingID(itr.next());
- }
-
- creationTime = System.currentTimeMillis();
- }
-
- public void update()
- {
- lastUpdated = System.currentTimeMillis();
- }
-
- public void add(CDOID fromID, CDOFeature feature, CDOID id)
- {
- // For now .. we do not need to calculate the path.. later we will do!!
- clusterOfObjects.add(id);
- analyzer.addTrackingID(id, this);
- }
-
- public void remove()
- {
- if (TRACER.isEnabled())
- {
- TRACER.format("Removing CDOGraph {0}", this);
- }
-
- for (CDOID id : clusterOfObjects)
- {
- analyzer.removeTrackingID(id);
- }
-
- analyzer.removeTracking(this);
- }
-}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOGraphAnalyzer.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOGraphAnalyzer.java
deleted file mode 100644
index 3265c24..0000000
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOGraphAnalyzer.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/***************************************************************************
- * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Simon McDuff - initial API and implementation
- * Eike Stepper - maintenance
- **************************************************************************/
-package org.eclipse.emf.internal.cdo.analyzer;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-
-import org.eclipse.emf.cdo.protocol.CDOID;
-import org.eclipse.emf.internal.cdo.bundle.OM;
-import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
-
-/**
- * @author Eike Stepper
- */
-public class CDOGraphAnalyzer
-{
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, CDOGraphAnalyzer.class);
-
- private Map<CDOID, CDOGraph> idToGraphMap = new HashMap<CDOID, CDOGraph>();
-
- private HashSet<CDOGraph> uniqueGraphs = new HashSet<CDOGraph>();
-
- private long lastPurgeOperation;
-
- public CDOGraphAnalyzer()
- {
- lastPurgeOperation = System.currentTimeMillis();
- }
-
- public CDOGraph getGraph(CDOID fromID, CDOClusterOfFetchRule featureRule)
- {
- CDOGraph graph = idToGraphMap.get(fromID);
- if (graph == null)
- {
- graph = new CDOGraph(this, fromID, featureRule);
- uniqueGraphs.add(graph);
- }
-
- // Update is time value
- graph.update();
- return graph;
- }
-
- public void purge(long elapseTimeForPurging, long elapseTimeToClear)
- {
- long time = System.currentTimeMillis();
- if (time - lastPurgeOperation > elapseTimeForPurging)
- {
- if (TRACER.isEnabled())
- {
- TRACER.format("Purging graph {0}", this);
- }
-
- ArrayList<CDOGraph> listToRemove = new ArrayList<CDOGraph>();
- for (CDOGraph graph : uniqueGraphs)
- {
- if (isTimeToRemove(graph, time, elapseTimeToClear))
- {
- listToRemove.add(graph);
- }
- }
-
- for (CDOGraph graph : listToRemove)
- {
- graph.remove();
- }
-
- lastPurgeOperation = System.currentTimeMillis();
- }
- }
-
- public boolean isTimeToRemove(CDOGraph graph, long currentTimestamp, long elapseTimeToClear)
- {
- return currentTimestamp - graph.getLastUpdated() > elapseTimeToClear
- || currentTimestamp - graph.getFeatureRule().getLastUpdate() > elapseTimeToClear
- && currentTimestamp - graph.getCreationTime() > elapseTimeToClear;
- }
-
- public void addTrackingID(CDOID id, CDOGraph graph)
- {
- idToGraphMap.put(id, graph);
- graph.update();
- }
-
- public void removeTrackingID(CDOID id)
- {
- idToGraphMap.remove(id);
- }
-
- public void removeTracking(CDOGraph graph)
- {
- uniqueGraphs.remove(graph);
- }
-
- public void clear()
- {
- idToGraphMap.clear();
- uniqueGraphs.clear();
- }
-}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/NOOPFetchRuleManager.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/NOOPFetchRuleManager.java
index 3ba37ac..c88b0bd 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/NOOPFetchRuleManager.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/NOOPFetchRuleManager.java
@@ -16,8 +16,8 @@ import java.util.List;
import org.eclipse.emf.cdo.analyzer.CDOFetchRuleManager;
import org.eclipse.emf.cdo.internal.protocol.CDOIDNull;
-import org.eclipse.emf.cdo.internal.protocol.analyzer.CDOFetchRule;
import org.eclipse.emf.cdo.protocol.CDOID;
+import org.eclipse.emf.cdo.protocol.analyzer.CDOFetchRule;
/**
* @author Eike Stepper
@@ -37,4 +37,9 @@ public class NOOPFetchRuleManager implements CDOFetchRuleManager
{
return null;
}
+
+ public int getLoadRevisionCollectionChunkSize()
+ {
+ return 1;
+ }
}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/protocol/LoadRevisionRequest.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/protocol/LoadRevisionRequest.java
index d3475be..44102ab 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/protocol/LoadRevisionRequest.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/protocol/LoadRevisionRequest.java
@@ -18,10 +18,11 @@ import java.util.List;
import org.eclipse.emf.cdo.analyzer.CDOFetchRuleManager;
import org.eclipse.emf.cdo.internal.protocol.CDOIDImpl;
-import org.eclipse.emf.cdo.internal.protocol.analyzer.CDOFetchRule;
import org.eclipse.emf.cdo.internal.protocol.revision.CDORevisionImpl;
import org.eclipse.emf.cdo.protocol.CDOID;
import org.eclipse.emf.cdo.protocol.CDOProtocolConstants;
+import org.eclipse.emf.cdo.protocol.analyzer.CDOFetchRule;
+
import org.eclipse.emf.internal.cdo.CDORevisionManagerImpl;
import org.eclipse.emf.internal.cdo.CDOSessionImpl;
import org.eclipse.emf.internal.cdo.CDOSessionPackageManager;
@@ -85,9 +86,12 @@ public class LoadRevisionRequest extends CDOClientRequest<List<CDORevisionImpl>>
{
// At this point, fetch size is more than one.
int fetchSize = fetchRules.size();
- out.writeInt(fetchSize);
CDOID contextID = ruleManager.getContext();
+
+ out.writeInt(fetchSize);
+ out.writeInt(ruleManager.getLoadRevisionCollectionChunkSize());
CDOIDImpl.write(out, contextID);
+
for (CDOFetchRule fetchRule : fetchRules)
{
fetchRule.write(out);