Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 78135 Details for
Bug 202064
More client-side intelligence (SmartReadAhead Thread)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Update
20070911-Analyzer.patch (text/plain), 54.11 KB, created by
Simon Mc Duff
on 2007-09-11 22:09:32 EDT
(
hide
)
Description:
Update
Filename:
MIME Type:
Creator:
Simon Mc Duff
Created:
2007-09-11 22:09:32 EDT
Size:
54.11 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.emf.cdo.server >Index: src/org/eclipse/emf/cdo/internal/server/protocol/LoadRevisionIndication.java >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf.cdo/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/LoadRevisionIndication.java,v >retrieving revision 1.12 >diff -u -r1.12 LoadRevisionIndication.java >--- src/org/eclipse/emf/cdo/internal/server/protocol/LoadRevisionIndication.java 10 Sep 2007 07:38:27 -0000 1.12 >+++ src/org/eclipse/emf/cdo/internal/server/protocol/LoadRevisionIndication.java 12 Sep 2007 02:08:29 -0000 >@@ -50,6 +50,8 @@ > > protected CDOID contextID = CDOIDNull.NULL; > >+ protected int loadRevisionCollectionChunkSize = 1; >+ > public LoadRevisionIndication() > { > } >@@ -78,11 +80,17 @@ > } > > 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); >- >+ >+ > for (int i = 0; i < fetchSize; i++) > { > CDOFetchRule fetchRule = new CDOFetchRule(in, getPackageManager()); >@@ -99,24 +107,33 @@ > HashSet<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); >+ >+ CDORevisionImpl revisionContext = getRevision(contextID); >+ >+ 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()); >+ > if (PROTOCOL.isEnabled()) PROTOCOL.format("Writing {0} additional revisions", additionalRevisions.size()); > > for (CDORevisionImpl revision : additionalRevisions) >@@ -130,16 +147,19 @@ > 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 +167,7 @@ > 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 +179,7 @@ > 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 +195,12 @@ > 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); > } > } >#P org.eclipse.emf.cdo.tests >Index: src/org/eclipse/emf/cdo/tests/FetchRuleAnalyzerTest.java >=================================================================== >RCS file: src/org/eclipse/emf/cdo/tests/FetchRuleAnalyzerTest.java >diff -N src/org/eclipse/emf/cdo/tests/FetchRuleAnalyzerTest.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/emf/cdo/tests/FetchRuleAnalyzerTest.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,121 @@ >+/*************************************************************************** >+ * 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.CDOState; >+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.cdo.util.CDOUtil; >+ >+import org.eclipse.net4j.IBufferHandler; >+import org.eclipse.net4j.IChannel; >+ >+import org.eclipse.emf.common.util.EList; >+import org.eclipse.emf.common.util.URI; >+import org.eclipse.emf.ecore.EObject; >+import org.eclipse.emf.ecore.resource.ResourceSet; >+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; >+ >+import java.util.Date; >+ >+/** >+ * @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 = (CDOTransactionImpl)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.getNbFetch(), 12); >+ >+ msg("Verifying name"); >+ } >+} >#P org.eclipse.emf.cdo >Index: src/org/eclipse/emf/internal/cdo/analyzer/NOOPFetchRuleManager.java >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf.cdo/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/NOOPFetchRuleManager.java,v >retrieving revision 1.1 >diff -u -r1.1 NOOPFetchRuleManager.java >--- src/org/eclipse/emf/internal/cdo/analyzer/NOOPFetchRuleManager.java 10 Sep 2007 07:38:31 -0000 1.1 >+++ src/org/eclipse/emf/internal/cdo/analyzer/NOOPFetchRuleManager.java 12 Sep 2007 02:08:29 -0000 >@@ -37,4 +37,10 @@ > { > return null; > } >+ >+ public int getLoadRevisionCollectionChunkSize() >+ { >+ // TODO Auto-generated method stub >+ return 1; >+ } > } >Index: src/org/eclipse/emf/internal/cdo/analyzer/CDOClusterOfFetchRule.java >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf.cdo/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOClusterOfFetchRule.java,v >retrieving revision 1.1 >diff -u -r1.1 CDOClusterOfFetchRule.java >--- src/org/eclipse/emf/internal/cdo/analyzer/CDOClusterOfFetchRule.java 10 Sep 2007 07:38:31 -0000 1.1 >+++ src/org/eclipse/emf/internal/cdo/analyzer/CDOClusterOfFetchRule.java 12 Sep 2007 02:08:29 -0000 >@@ -11,11 +11,6 @@ > **************************************************************************/ > 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; >@@ -28,95 +23,64 @@ > { > 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 CDOFeatureInfo featureInfo = new CDOFeatureInfo(); >+ > 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() >- { >- return fetchRules.values().iterator(); >- } >- >- public synchronized CDOFetchFeatureInfo getFeatureStat(CDOFeature cdoFeature) >- { >- CDOFetchFeatureInfo featureRule = featureStats.get(cdoFeature); >- if (featureRule == null) >- { >- featureRule = new CDOFetchFeatureInfo(); >- featureStats.put(cdoFeature, featureRule); >- } >- >- return featureRule; >- } >- >- public synchronized CDOFetchRule addFeatureRule(CDOClass cdoClass, CDOFeature cdoFeature) >- { >- 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; >- } >- >- public synchronized CDOFetchRule removeFeatureRule(CDOClass cdoClass, CDOFeature cdoFeature) >- { >- 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; >- } >- >- public synchronized CDOFetchRule getFetchRule(CDOClass cdoFeature) >- { >- CDOFetchRule featureRule = fetchRules.get(cdoFeature); >- if (featureRule == null) >- { >- featureRule = new CDOFetchRule(cdoFeature); >- fetchRules.put(cdoFeature, featureRule); >- } >- >- return featureRule; >- } >- >+ /** >+ * >+ */ >+ public int hashCode() >+ { >+ return rootFeature.hashCode(); >+ } >+ >+ /** >+ * >+ */ >+ public boolean equals(Object object) >+ { >+ if (object instanceof CDOClusterOfFetchRule) >+ { >+ CDOClusterOfFetchRule featureInfo = (CDOClusterOfFetchRule)object; >+ return featureInfo.rootClass == this.rootClass && >+ featureInfo.rootFeature == this.rootFeature; >+ } >+ return false; >+ } >+ >+ /** >+ * >+ * @return >+ */ > public long getLastUpdate() > { > return lastUpdate; > } >- >+ /** >+ * >+ * @return >+ */ > public CDOFeature getRootFeature() > { > return rootFeature; > } >+ >+ public CDOFeatureInfo getFeatureInfo() >+ { >+ >+ return featureInfo; >+ } > } >Index: src/org/eclipse/emf/internal/cdo/analyzer/CDODynamicFetchRuleManager.java >=================================================================== >RCS file: src/org/eclipse/emf/internal/cdo/analyzer/CDODynamicFetchRuleManager.java >diff -N src/org/eclipse/emf/internal/cdo/analyzer/CDODynamicFetchRuleManager.java >--- src/org/eclipse/emf/internal/cdo/analyzer/CDODynamicFetchRuleManager.java 10 Sep 2007 07:38:31 -0000 1.1 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,58 +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 org.eclipse.emf.cdo.analyzer.CDOFetchRuleManager; >-import org.eclipse.emf.cdo.internal.protocol.analyzer.CDOFetchRule; >-import org.eclipse.emf.cdo.protocol.CDOID; >- >-import java.util.Collection; >-import java.util.List; >- >-/** >- * @author Eike Stepper >- */ >-public class CDODynamicFetchRuleManager implements CDOFetchRuleManager >-{ >- private static final ThreadLocal<CDOFetchRuleManager> threadLocal = new ThreadLocal<CDOFetchRuleManager>(); >- >- public CDODynamicFetchRuleManager() >- { >- } >- >- public static void join(CDOFetchRuleManager fetchRulemanager) >- { >- threadLocal.set(fetchRulemanager); >- } >- >- public static CDOFetchRuleManager getCurrent() >- { >- return threadLocal.get(); >- } >- >- public static void leave() >- { >- threadLocal.set(null); >- } >- >- public CDOID getContext() >- { >- CDOFetchRuleManager analyzer = CDODynamicFetchRuleManager.getCurrent(); >- return analyzer != null ? analyzer.getContext() : null; >- } >- >- public List<CDOFetchRule> getFetchRules(Collection<CDOID> ids) >- { >- CDOFetchRuleManager analyzer = CDODynamicFetchRuleManager.getCurrent(); >- return analyzer != null ? analyzer.getFetchRules(ids) : null; >- } >-} >Index: src/org/eclipse/emf/internal/cdo/analyzer/CDOGraph.java >=================================================================== >RCS file: src/org/eclipse/emf/internal/cdo/analyzer/CDOGraph.java >diff -N src/org/eclipse/emf/internal/cdo/analyzer/CDOGraph.java >--- src/org/eclipse/emf/internal/cdo/analyzer/CDOGraph.java 10 Sep 2007 07:38:31 -0000 1.1 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -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); >- } >-} >Index: src/org/eclipse/emf/internal/cdo/analyzer/CDODynamicFetchRuleAnalyzer.java >=================================================================== >RCS file: src/org/eclipse/emf/internal/cdo/analyzer/CDODynamicFetchRuleAnalyzer.java >diff -N src/org/eclipse/emf/internal/cdo/analyzer/CDODynamicFetchRuleAnalyzer.java >--- src/org/eclipse/emf/internal/cdo/analyzer/CDODynamicFetchRuleAnalyzer.java 10 Sep 2007 07:38:31 -0000 1.1 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -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; >- } >-} >Index: src/org/eclipse/emf/internal/cdo/analyzer/CDOGraphAnalyzer.java >=================================================================== >RCS file: src/org/eclipse/emf/internal/cdo/analyzer/CDOGraphAnalyzer.java >diff -N src/org/eclipse/emf/internal/cdo/analyzer/CDOGraphAnalyzer.java >--- src/org/eclipse/emf/internal/cdo/analyzer/CDOGraphAnalyzer.java 10 Sep 2007 07:38:31 -0000 1.1 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -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(); >- } >-} >Index: src/org/eclipse/emf/internal/cdo/analyzer/CDOFetchFeatureInfo.java >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf.cdo/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOFetchFeatureInfo.java,v >retrieving revision 1.1 >diff -u -r1.1 CDOFetchFeatureInfo.java >--- src/org/eclipse/emf/internal/cdo/analyzer/CDOFetchFeatureInfo.java 10 Sep 2007 07:38:31 -0000 1.1 >+++ src/org/eclipse/emf/internal/cdo/analyzer/CDOFetchFeatureInfo.java 12 Sep 2007 02:08:29 -0000 >@@ -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 > */ >@@ -21,13 +24,32 @@ > private long latencyTime; > > private boolean active; >- >- public CDOFetchFeatureInfo() >+ >+ private CDOClass cdoClass; >+ >+ private CDOFeature cdoFeature; >+ >+ public CDOFetchFeatureInfo(CDOClass cdoClass, CDOFeature cdoFeature) > { > active = false; > latencyTime = -1; >+ this.cdoClass = cdoClass; >+ this.cdoFeature = cdoFeature; >+ } >+ public int hashCode() >+ { >+ return cdoFeature.hashCode(); >+ } >+ public boolean equals(Object object) >+ { >+ if (object instanceof CDOFetchFeatureInfo) >+ { >+ CDOFetchFeatureInfo featureInfo = (CDOFetchFeatureInfo)object; >+ return featureInfo.cdoClass == this.cdoClass && >+ featureInfo.cdoFeature == this.cdoFeature; >+ } >+ return false; > } >- > public boolean isActive() > { > return active; >@@ -81,4 +103,10 @@ > setTimeBeforeUsed((getTimeBeforeUsed() + elapseTimeBeforeLastRequest) / 2); > } > } >+public CDOClass getCdoClass() { >+ return cdoClass; >+} >+public CDOFeature getCdoFeature() { >+ return cdoFeature; >+} > } >Index: src/org/eclipse/emf/internal/cdo/protocol/LoadRevisionRequest.java >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf.cdo/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/protocol/LoadRevisionRequest.java,v >retrieving revision 1.12 >diff -u -r1.12 LoadRevisionRequest.java >--- src/org/eclipse/emf/internal/cdo/protocol/LoadRevisionRequest.java 10 Sep 2007 09:57:18 -0000 1.12 >+++ src/org/eclipse/emf/internal/cdo/protocol/LoadRevisionRequest.java 12 Sep 2007 02:08:29 -0000 >@@ -85,9 +85,12 @@ > { > // 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); >Index: src/org/eclipse/emf/cdo/analyzer/CDOFetchRuleManager.java >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf.cdo/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/analyzer/CDOFetchRuleManager.java,v >retrieving revision 1.1 >diff -u -r1.1 CDOFetchRuleManager.java >--- src/org/eclipse/emf/cdo/analyzer/CDOFetchRuleManager.java 10 Sep 2007 07:38:30 -0000 1.1 >+++ src/org/eclipse/emf/cdo/analyzer/CDOFetchRuleManager.java 12 Sep 2007 02:08:29 -0000 >@@ -28,4 +28,7 @@ > public CDOID getContext(); > > public List<CDOFetchRule> getFetchRules(Collection<CDOID> ids); >+ >+ public int getLoadRevisionCollectionChunkSize(); >+ > } >Index: src/org/eclipse/emf/internal/cdo/analyzer/CDOFeatureAnalyzerModelBased.java >=================================================================== >RCS file: src/org/eclipse/emf/internal/cdo/analyzer/CDOFeatureAnalyzerModelBased.java >diff -N src/org/eclipse/emf/internal/cdo/analyzer/CDOFeatureAnalyzerModelBased.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/emf/internal/cdo/analyzer/CDOFeatureAnalyzerModelBased.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,76 @@ >+/*************************************************************************** >+ * 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.List; >+ >+import org.eclipse.emf.cdo.internal.protocol.analyzer.CDOFetchRule; >+import org.eclipse.emf.cdo.protocol.CDOID; >+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 class CDOFeatureAnalyzerModelBased extends CDOAbstracFeatureRuleAnalyzer >+{ >+ private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, CDOFeatureAnalyzerModelBased.class); >+ >+ CDOFeatureInfo featureInfos = new CDOFeatureInfo(); >+ >+ /** >+ * >+ */ >+ public void doPreTraverseFeature(InternalCDOObject cdoObject, CDOFeature feature, int index) >+ { >+ >+ } >+ >+ /** >+ * >+ */ >+ public void doPostTraverseFeature(InternalCDOObject cdoObject, CDOFeature feature, int index, Object value) >+ { >+ if (didFetch()) >+ featureInfos.activate(cdoObject.cdoClass(), feature); >+ } >+ >+ /** >+ * >+ */ >+ public CDOID getContext() >+ { >+ // TODO Auto-generated method stu >+ return null; >+ } >+ >+ /** >+ * >+ */ >+ public List<CDOFetchRule> getFetchRules(Collection<CDOID> ids) >+ { >+ this.fetchData(); >+ >+ List<CDOFetchRule> rules = new ArrayList<CDOFetchRule>(); >+ >+ rules.addAll(featureInfos.getRules(this.lastTraverseCDOObject.cdoClass(), this.lastTraverseFeature)); >+ >+ return rules; >+ } >+ >+ >+ >+} >Index: src/org/eclipse/emf/internal/cdo/analyzer/CDOAbstracFeatureRuleAnalyzer.java >=================================================================== >RCS file: src/org/eclipse/emf/internal/cdo/analyzer/CDOAbstracFeatureRuleAnalyzer.java >diff -N src/org/eclipse/emf/internal/cdo/analyzer/CDOAbstracFeatureRuleAnalyzer.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/emf/internal/cdo/analyzer/CDOAbstracFeatureRuleAnalyzer.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,135 @@ >+/*************************************************************************** >+ * 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 CDOAbstracFeatureRuleAnalyzer implements CDOFeatureAnalyzer, CDOFetchRuleManager >+{ >+ private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, CDOAbstracFeatureRuleAnalyzer.class); >+ >+ protected CDOFeature lastTraverseFeature; >+ >+ protected int lastTraverseIndex; >+ >+ protected long lastAccessTime; >+ >+ protected long lastElapseTimeBetweenOperations; >+ >+ protected InternalCDOObject lastTraverseCDOObject; >+ >+ protected long lastLatencyTime; >+ >+ protected int loadRevisionCollectionChunkSize; >+ >+ private boolean didFetch; >+ >+ private int nbFetch = 0; >+ >+ >+ /** >+ * >+ */ >+ 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(); >+ >+ // TODO Auto-generated method stub >+ lastTraverseFeature = feature; >+ >+ lastTraverseCDOObject = cdoObject; >+ >+ lastTraverseIndex = index; >+ >+ lastElapseTimeBetweenOperations = System.currentTimeMillis() - lastAccessTime; >+ >+ lastAccessTime = System.currentTimeMillis(); >+ >+ didFetch = false; >+ >+ CDOFetchRuleManagerThreadLocal.join(this); >+ >+ doPreTraverseFeature( cdoObject, feature, index); >+ } >+ /** >+ * >+ */ >+ protected void fetchData() >+ { >+ didFetch = true; >+ nbFetch++; >+ } >+ /** >+ * >+ * @return >+ */ >+ protected boolean didFetch() >+ { >+ return didFetch; >+ } >+ /** >+ * >+ * @param cdoObject >+ * @param feature >+ * @param index >+ */ >+ public void doPreTraverseFeature(InternalCDOObject cdoObject, CDOFeature feature, int 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(); >+ } >+ >+ } >+ >+ public void doPostTraverseFeature(InternalCDOObject cdoObject, CDOFeature feature, int index, Object value) >+ { >+ >+ } >+ public int getNbFetch() >+ { >+ return this.nbFetch; >+ } >+ public int getLoadRevisionCollectionChunkSize() >+ { >+ return loadRevisionCollectionChunkSize; >+ } >+} >Index: src/org/eclipse/emf/internal/cdo/analyzer/CDOFeatureAnalyzerUI.java >=================================================================== >RCS file: src/org/eclipse/emf/internal/cdo/analyzer/CDOFeatureAnalyzerUI.java >diff -N src/org/eclipse/emf/internal/cdo/analyzer/CDOFeatureAnalyzerUI.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/emf/internal/cdo/analyzer/CDOFeatureAnalyzerUI.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,149 @@ >+/*************************************************************************** >+ * 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.CDOIDNull; >+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 CDOFeatureAnalyzerUI extends CDOAbstracFeatureRuleAnalyzer implements CDOFetchRuleManager >+{ >+ private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, CDOFeatureAnalyzerUI.class); >+ >+ 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 void doPreTraverseFeature(InternalCDOObject cdoObject, CDOFeature feature, int index) >+ { >+ // Don`t handle containment relationship >+ if (!feature.isReference()) >+ { >+ return; >+ } >+ >+ >+ if (this.lastElapseTimeBetweenOperations > maxTimeBetweenOperation || currentClusterOfFetchRule == null) >+ { >+ // The user interacted with the UI. Restart a new ClusterOfFetchRule >+ currentClusterOfFetchRule = getFeatureRule(cdoObject.cdoClass(), feature); >+ } >+ >+ } >+ >+ /** >+ * >+ */ >+ public void doPostTraverseFeature(InternalCDOObject cdoObject, CDOFeature feature, int index, Object object) >+ { >+ if (didFetch()) >+ { >+ currentClusterOfFetchRule.getFeatureInfo().activate(cdoObject.cdoClass(), feature); >+ } >+ } >+ >+ /** >+ * >+ */ >+ public CDOID getContext() >+ { >+ >+ if (this.lastTraverseFeature.isMany()) >+ return CDOIDNull.NULL; >+ >+ return lastTraverseCDOObject.cdoID(); >+ } >+ >+ /** >+ * >+ * @param cdoClass >+ * @param cdoFeature >+ * @return >+ */ >+ 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; >+ >+ this.fetchData(); >+ >+ if (this.lastTraverseFeature.isMany()) >+ { >+ addRootFeature = false; >+ } >+ >+ CDOClusterOfFetchRule search = new CDOClusterOfFetchRule(lastTraverseCDOObject.cdoClass(), lastTraverseFeature); >+ >+ CDOClusterOfFetchRule fetchOfRule = this.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; >+ } >+} >Index: src/org/eclipse/emf/internal/cdo/analyzer/CDOFetchRuleManagerThreadLocal.java >=================================================================== >RCS file: src/org/eclipse/emf/internal/cdo/analyzer/CDOFetchRuleManagerThreadLocal.java >diff -N src/org/eclipse/emf/internal/cdo/analyzer/CDOFetchRuleManagerThreadLocal.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/emf/internal/cdo/analyzer/CDOFetchRuleManagerThreadLocal.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,64 @@ >+/*************************************************************************** >+ * 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.CDOFetchRuleManager; >+import org.eclipse.emf.cdo.internal.protocol.analyzer.CDOFetchRule; >+import org.eclipse.emf.cdo.protocol.CDOID; >+ >+import java.util.Collection; >+import java.util.List; >+ >+/** >+ * @author Eike Stepper >+ */ >+public class CDOFetchRuleManagerThreadLocal implements CDOFetchRuleManager >+{ >+ private static final ThreadLocal<CDOFetchRuleManager> threadLocal = new ThreadLocal<CDOFetchRuleManager>(); >+ >+ public CDOFetchRuleManagerThreadLocal() >+ { >+ } >+ >+ public static void join(CDOFetchRuleManager fetchRulemanager) >+ { >+ threadLocal.set(fetchRulemanager); >+ } >+ >+ public static CDOFetchRuleManager getCurrent() >+ { >+ return threadLocal.get(); >+ } >+ >+ public static void leave() >+ { >+ threadLocal.set(null); >+ } >+ >+ public CDOID getContext() >+ { >+ CDOFetchRuleManager analyzer = CDOFetchRuleManagerThreadLocal.getCurrent(); >+ return analyzer != null ? analyzer.getContext() : null; >+ } >+ >+ public List<CDOFetchRule> getFetchRules(Collection<CDOID> ids) >+ { >+ CDOFetchRuleManager analyzer = CDOFetchRuleManagerThreadLocal.getCurrent(); >+ return analyzer != null ? analyzer.getFetchRules(ids) : null; >+ } >+ >+ public int getLoadRevisionCollectionChunkSize() >+ { >+ CDOFetchRuleManager analyzer = CDOFetchRuleManagerThreadLocal.getCurrent(); >+ return analyzer != null ? analyzer.getLoadRevisionCollectionChunkSize() : 0; >+ } >+} >Index: src/org/eclipse/emf/internal/cdo/analyzer/CDOFeatureInfo.java >=================================================================== >RCS file: src/org/eclipse/emf/internal/cdo/analyzer/CDOFeatureInfo.java >diff -N src/org/eclipse/emf/internal/cdo/analyzer/CDOFeatureInfo.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/emf/internal/cdo/analyzer/CDOFeatureInfo.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,139 @@ >+/*************************************************************************** >+ * 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.Collection; >+import java.util.HashMap; >+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 CDOFeatureInfo >+{ >+ private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, CDOFeatureInfo.class); >+ >+ private Map<CDOFetchFeatureInfo, CDOFetchFeatureInfo> featureStats = new HashMap<CDOFetchFeatureInfo, CDOFetchFeatureInfo>(); >+ private Map<CDOClass, CDOFetchRule> fetchRules = new HashMap<CDOClass, CDOFetchRule>(); >+ >+ /** >+ * >+ * @param cdoClass >+ * @param cdoFeature >+ * @return >+ */ >+ 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; >+ } >+ /** >+ * >+ * @param cdoClass >+ * @param cdoFeature >+ * @return >+ */ >+ public boolean isActivate(CDOClass cdoClass, CDOFeature cdoFeature) >+ { >+ CDOFetchFeatureInfo search = new CDOFetchFeatureInfo(cdoClass, cdoFeature); >+ CDOFetchFeatureInfo featureRule = featureStats.get(search); >+ return (featureRule != null && featureRule.isActive()); >+ } >+ /** >+ * >+ * @param cdoClass >+ * @param cdoFeature >+ */ >+ public void activate(CDOClass cdoClass, CDOFeature cdoFeature) >+ { >+ CDOFetchFeatureInfo info = getFeatureStat(cdoClass, cdoFeature); >+ if (!info.isActive()) >+ { >+ info.setActive(true); >+ addRule(cdoClass, cdoFeature); >+ } >+ } >+ /** >+ * >+ * @param cdoClass >+ * @param cdoFeature >+ */ >+ public void desactivate(CDOClass cdoClass, CDOFeature cdoFeature) >+ { >+ CDOFetchFeatureInfo info = getFeatureStat(cdoClass, cdoFeature); >+ if (info.isActive()) >+ { >+ info.setActive(false); >+ removeRule(cdoClass, cdoFeature); >+ } >+ } >+ /** >+ * >+ * @param cdoClass >+ * @param cdoFeature >+ */ >+ private void addRule(CDOClass cdoClass, CDOFeature cdoFeature) >+ { >+ if (TRACER.isEnabled()) >+ { >+ TRACER.format("Adding a new 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); >+ >+ } >+ /** >+ * >+ * @param cdoClass >+ * @param cdoFeature >+ * @return >+ */ >+ public Collection<CDOFetchRule> getRules(CDOClass cdoClass, CDOFeature cdoFeature) >+ { >+ return fetchRules.values(); >+ } >+ >+ /** >+ * >+ * @param cdoClass >+ * @param 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); >+ } >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 202064
:
77860
|
77861
|
77950
|
77969
| 78135 |
78236
|
78242
|
78243
|
78395