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 77861 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]
Oops.. BETA 2
analyzer.patch (text/plain), 35.15 KB, created by
Simon Mc Duff
on 2007-09-06 22:32:36 EDT
(
hide
)
Description:
Oops.. BETA 2
Filename:
MIME Type:
Creator:
Simon Mc Duff
Created:
2007-09-06 22:32:36 EDT
Size:
35.15 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.9 >diff -u -r1.9 LoadRevisionIndication.java >--- src/org/eclipse/emf/cdo/internal/server/protocol/LoadRevisionIndication.java 6 Sep 2007 09:42:35 -0000 1.9 >+++ src/org/eclipse/emf/cdo/internal/server/protocol/LoadRevisionIndication.java 7 Sep 2007 02:34:37 -0000 >@@ -10,12 +10,17 @@ > **************************************************************************/ > package org.eclipse.emf.cdo.internal.server.protocol; > >+import org.eclipse.emf.cdo.internal.analyzer.CDOFetchRule; > import org.eclipse.emf.cdo.internal.protocol.CDOIDImpl; >+import org.eclipse.emf.cdo.internal.protocol.CDOIDNull; > 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.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.model.CDOClass; >+import org.eclipse.emf.cdo.protocol.model.CDOFeature; > > import org.eclipse.net4j.internal.util.om.trace.ContextTracer; > import org.eclipse.net4j.util.io.ExtendedDataInputStream; >@@ -23,7 +28,10 @@ > > import java.io.IOException; > import java.util.ArrayList; >+import java.util.HashMap; >+import java.util.HashSet; > import java.util.List; >+import java.util.Set; > > /** > * @author Eike Stepper >@@ -36,6 +44,10 @@ > > protected int referenceChunk; > >+ protected HashMap<CDOClass, CDOFetchRule> fetchRules = new HashMap<CDOClass, CDOFetchRule>(); >+ >+ protected CDOID contextId = CDOIDNull.NULL; >+ > public LoadRevisionIndication() > { > } >@@ -62,25 +74,92 @@ > if (PROTOCOL.isEnabled()) PROTOCOL.format("Read ID: {0}", id); > ids[i] = id; > } >+ >+ int fetchSize = in.readInt(); >+ if (fetchSize > 0) >+ { >+ contextId = CDOIDImpl.read(in); >+ for (int i =0; i< fetchSize; i++) >+ { >+ CDOFetchRule fetchRule = new CDOFetchRule(in, getPackageManager()); >+ for (CDOFeature cdoFeature : fetchRule.getCdoFeatures()) >+ fetchRules.put(fetchRule.getCdoClass(), fetchRule); >+ } >+ } > } > >+ private void collectRevisionsByRule(CDORevisionImpl revision, int referenceChunk, HashMap<CDOID, CDORevisionImpl> attachedObjects, Set<CDOFetchRule> workingFetchRule) >+ { >+ CDOFetchRule fetchRule = fetchRules.get(revision.getCDOClass()); >+ >+ if (fetchRule == null || workingFetchRule.contains(fetchRule)) >+ return; >+ >+ workingFetchRule.add(fetchRule); >+ >+ for (CDOFeature feature : fetchRule.getCdoFeatures()) >+ { >+ if (!feature.isMany()) >+ { >+ Object object = revision.get(feature, 0); >+ if (object != null && object instanceof CDOID) >+ { >+ CDOID cdoId = (CDOID)object; >+ if (!cdoId.isNull() && attachedObjects.get(cdoId) == null) >+ { >+ CDORevisionImpl containedRevision = (CDORevisionImpl)getSessionManager().getRepository().getRevisionManager().getRevision(cdoId, referenceChunk); >+ attachedObjects.put(containedRevision.getID(), containedRevision); >+ collectRevisionsByRule(containedRevision, referenceChunk, attachedObjects, workingFetchRule); >+ } >+ } >+ } >+ else if (feature.isMany()) >+ { >+ MoveableList list = revision.getList(feature); >+ int toIndex = Math.min(referenceChunk, list.size()); >+ for (int i = 0; i < toIndex; i++) >+ { >+ Object object = list.get(i); >+ if (object instanceof CDOID) >+ { >+ >+ CDOID cdoId = (CDOID)object; >+ CDORevisionImpl containedRevision = (CDORevisionImpl)getSessionManager().getRepository().getRevisionManager().getRevision(cdoId, referenceChunk); >+ attachedObjects.put(containedRevision.getID(), containedRevision); >+ >+ collectRevisionsByRule(containedRevision, referenceChunk, attachedObjects, workingFetchRule); >+ } >+ } >+ } >+ } >+ workingFetchRule.remove(fetchRule); >+ } >+ > @Override > protected void responding(ExtendedDataOutputStream out) throws IOException > { > Session session = getSession(); >- List<CDORevisionImpl> containedRevisions = new ArrayList<CDORevisionImpl>(0); >+ HashMap<CDOID, CDORevisionImpl> containedRevisions = new HashMap<CDOID, CDORevisionImpl>(0); > > if (PROTOCOL.isEnabled()) PROTOCOL.format("Writing {0} revisions", ids.length); >+ > for (CDOID id : ids) > { > CDORevisionImpl revision = getRevision(id); > revision.write(out, session, referenceChunk); > session.collectContainedRevisions(revision, referenceChunk, containedRevisions); > } >- >+ >+ if (!contextId.isNull() && fetchRules.size() > 0 ) >+ { >+ int newReferenceChunk = Math.max(referenceChunk, 1000); >+ CDORevisionImpl revisionContext = getRevision(contextId); >+ this.collectRevisionsByRule(revisionContext, newReferenceChunk, containedRevisions, new HashSet<CDOFetchRule>()); >+ } >+ > out.writeInt(containedRevisions.size()); > if (PROTOCOL.isEnabled()) PROTOCOL.format("Writing {0} additional revisions", containedRevisions.size()); >- for (CDORevisionImpl revision : containedRevisions) >+ for (CDORevisionImpl revision : containedRevisions.values()) > { > revision.write(out, session, referenceChunk); > } >Index: src/org/eclipse/emf/cdo/internal/server/Session.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/Session.java,v >retrieving revision 1.18 >diff -u -r1.18 Session.java >--- src/org/eclipse/emf/cdo/internal/server/Session.java 6 Sep 2007 09:42:35 -0000 1.18 >+++ src/org/eclipse/emf/cdo/internal/server/Session.java 7 Sep 2007 02:34:37 -0000 >@@ -35,6 +35,7 @@ > import java.text.MessageFormat; > import java.util.Collection; > import java.util.HashSet; >+import java.util.Map; > import java.util.Set; > import java.util.concurrent.ConcurrentHashMap; > import java.util.concurrent.ConcurrentMap; >@@ -187,7 +188,7 @@ > * TODO I can't see how recursion is controlled/limited > */ > public void collectContainedRevisions(CDORevisionImpl revision, int referenceChunk, >- Collection<CDORevisionImpl> containedRevisions) >+ Map<CDOID, CDORevisionImpl> containedRevisions) > { > RevisionManager revisionManager = getSessionManager().getRepository().getRevisionManager(); > CDOClassImpl cdoClass = revision.getCDOClass(); >@@ -203,9 +204,12 @@ > CDOID id = (CDOID)value; > if (!id.isNull()) > { >- CDORevisionImpl containedRevision = revisionManager.getRevision(id, referenceChunk); >- containedRevisions.add(containedRevision); >- collectContainedRevisions(containedRevision, referenceChunk, containedRevisions); >+ if (containedRevisions.get(id) == null) >+ { >+ CDORevisionImpl containedRevision = revisionManager.getRevision(id, referenceChunk); >+ containedRevisions.put(id, containedRevision); >+ collectContainedRevisions(containedRevision, referenceChunk, containedRevisions); >+ } > } > } > } >#P org.eclipse.emf.cdo >Index: src/org/eclipse/emf/internal/cdo/CDOViewImpl.java >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf.cdo/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOViewImpl.java,v >retrieving revision 1.69 >diff -u -r1.69 CDOViewImpl.java >--- src/org/eclipse/emf/internal/cdo/CDOViewImpl.java 6 Sep 2007 09:42:39 -0000 1.69 >+++ src/org/eclipse/emf/internal/cdo/CDOViewImpl.java 7 Sep 2007 02:34:38 -0000 >@@ -15,6 +15,7 @@ > import org.eclipse.emf.cdo.CDOView; > import org.eclipse.emf.cdo.CDOViewEvent; > import org.eclipse.emf.cdo.CDOViewResourcesEvent; >+import org.eclipse.emf.cdo.analyzer.*; > import org.eclipse.emf.cdo.eresource.CDOResource; > import org.eclipse.emf.cdo.eresource.EresourceFactory; > import org.eclipse.emf.cdo.eresource.impl.CDOResourceImpl; >@@ -56,7 +57,6 @@ > import java.util.List; > import java.util.Map; > import java.util.Set; >- > /** > * @author Eike Stepper > */ >@@ -83,6 +83,8 @@ > > private int loadRevisionCollectionChunkSize; > >+ private IFeatureAnalyzer featureAnalyzer = IFeatureAnalyzer.eNOOP; >+ > public CDOViewImpl(int id, CDOSessionImpl session) > { > this.viewID = id; >@@ -792,4 +794,12 @@ > { > this.loadRevisionCollectionChunkSize = loadRevisionCollectionChunkSize; > } >+ >+public IFeatureAnalyzer getFeatureAnalyzer() { >+ return featureAnalyzer; >+} >+ >+public void setFeatureAnalyzer(IFeatureAnalyzer featureAnalyzer) { >+ this.featureAnalyzer = featureAnalyzer; >+} > } >Index: src/org/eclipse/emf/internal/cdo/CDOStore.java >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf.cdo/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOStore.java,v >retrieving revision 1.28 >diff -u -r1.28 CDOStore.java >--- src/org/eclipse/emf/internal/cdo/CDOStore.java 6 Sep 2007 09:42:39 -0000 1.28 >+++ src/org/eclipse/emf/internal/cdo/CDOStore.java 7 Sep 2007 02:34:38 -0000 >@@ -99,8 +99,12 @@ > > public Object get(InternalEObject eObject, EStructuralFeature eFeature, int index) > { >+ > InternalCDOObject cdoObject = getCDOObject(eObject); > CDOFeatureImpl cdoFeature = getCDOFeature(cdoObject, eFeature); >+ >+ view.getFeatureAnalyzer().preTraverseFeature(cdoObject.cdoRevision(), cdoFeature, index); >+ > if (TRACER.isEnabled()) > { > TRACER.format("get({0}, {1}, {2})", cdoObject, cdoFeature, index); >@@ -118,6 +122,8 @@ > > value = view.convertIDToObject(value); > } >+ >+ view.getFeatureAnalyzer().postTraverseFeature(cdoObject.cdoRevision(), cdoFeature, index); > > return value; > } >@@ -132,10 +138,10 @@ > { > MoveableList list = revision.getList(cdoFeature); > int fromIndex = index; >- int toIndex = Math.min(index + chunkSize - 1, list.size()); >+ int toIndex = Math.min(index + chunkSize, list.size()); > > Set<CDOID> notRegistered = new HashSet<CDOID>(); >- for (int i = fromIndex; i <= toIndex; i++) >+ for (int i = fromIndex; i < toIndex; i++) > { > Object element = list.get(i); > if (element instanceof CDOID) >@@ -149,7 +155,7 @@ > } > } > } >- >+ > if (!notRegistered.isEmpty()) > { > int referenceChunk = session.getReferenceChunkSize(); >Index: src/org/eclipse/emf/internal/cdo/CDORevisionManagerImpl.java >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf.cdo/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDORevisionManagerImpl.java,v >retrieving revision 1.14 >diff -u -r1.14 CDORevisionManagerImpl.java >--- src/org/eclipse/emf/internal/cdo/CDORevisionManagerImpl.java 6 Sep 2007 09:42:39 -0000 1.14 >+++ src/org/eclipse/emf/internal/cdo/CDORevisionManagerImpl.java 7 Sep 2007 02:34:38 -0000 >@@ -11,6 +11,7 @@ > package org.eclipse.emf.internal.cdo; > > import org.eclipse.emf.cdo.CDORevisionManager; >+import org.eclipse.emf.cdo.analyzer.IFetchRuleManager; > import org.eclipse.emf.cdo.internal.protocol.revision.CDORevisionImpl; > import org.eclipse.emf.cdo.internal.protocol.revision.CDORevisionResolverImpl; > import org.eclipse.emf.cdo.internal.protocol.revision.CDORevisionImpl.MoveableList; >@@ -37,7 +38,9 @@ > public class CDORevisionManagerImpl extends CDORevisionResolverImpl implements CDORevisionManager > { > private CDOSessionImpl session; >- >+ >+ private IFetchRuleManager ruleManager = IFetchRuleManager.NOOP; >+ > public CDORevisionManagerImpl(CDOSessionImpl session) > { > this.session = session; >@@ -247,4 +250,12 @@ > throw new TransportException(ex); > } > } >+ >+public IFetchRuleManager getRuleManager() { >+ return ruleManager; >+} >+ >+public void setRuleManager(IFetchRuleManager ruleManager) { >+ this.ruleManager = ruleManager; >+} > } >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.9 >diff -u -r1.9 LoadRevisionRequest.java >--- src/org/eclipse/emf/internal/cdo/protocol/LoadRevisionRequest.java 6 Sep 2007 09:42:39 -0000 1.9 >+++ src/org/eclipse/emf/internal/cdo/protocol/LoadRevisionRequest.java 7 Sep 2007 02:34:38 -0000 >@@ -10,26 +10,26 @@ > **************************************************************************/ > package org.eclipse.emf.internal.cdo.protocol; > >+import java.io.IOException; >+import java.util.ArrayList; >+import java.util.Collection; >+import java.util.Collections; >+import java.util.List; >+ >+import org.eclipse.emf.cdo.internal.analyzer.CDOFetchRule; > import org.eclipse.emf.cdo.internal.protocol.CDOIDImpl; > 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.net4j.IChannel; >-import org.eclipse.net4j.internal.util.om.trace.ContextTracer; >-import org.eclipse.net4j.util.io.ExtendedDataInputStream; >-import org.eclipse.net4j.util.io.ExtendedDataOutputStream; >- >+import org.eclipse.emf.cdo.protocol.model.CDOFeature; > import org.eclipse.emf.internal.cdo.CDORevisionManagerImpl; > import org.eclipse.emf.internal.cdo.CDOSessionImpl; > import org.eclipse.emf.internal.cdo.CDOSessionPackageManager; > import org.eclipse.emf.internal.cdo.bundle.OM; >- >-import java.io.IOException; >-import java.util.ArrayList; >-import java.util.Collection; >-import java.util.Collections; >-import java.util.List; >+import org.eclipse.net4j.IChannel; >+import org.eclipse.net4j.internal.util.om.trace.ContextTracer; >+import org.eclipse.net4j.util.io.ExtendedDataInputStream; >+import org.eclipse.net4j.util.io.ExtendedDataOutputStream; > > /** > * @author Eike Stepper >@@ -74,6 +74,26 @@ > if (PROTOCOL.isEnabled()) PROTOCOL.format("Writing ID: {0}", id); > CDOIDImpl.write(out, id); > } >+ >+ List<CDOFetchRule> fetchRules = getSession().getRevisionManager().getRuleManager().getFetchRules(ids); >+ >+ if (fetchRules == null || fetchRules.size() == 0) >+ { >+ out.writeInt(0); >+ } >+ else >+ { >+ CDOID cdoIdContext = getSession().getRevisionManager().getRuleManager().getContext(); >+ >+ out.writeInt(fetchRules.size()); >+ >+ CDOIDImpl.write(out, cdoIdContext); >+ >+ for (CDOFetchRule fetchRule : fetchRules) >+ { >+ fetchRule.write(out); >+ } >+ } > } > > @Override >#P org.eclipse.emf.cdo.protocol >Index: src/org/eclipse/emf/cdo/internal/protocol/revision/CDORevisionResolverImpl.java >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf.cdo/plugins/org.eclipse.emf.cdo.protocol/src/org/eclipse/emf/cdo/internal/protocol/revision/CDORevisionResolverImpl.java,v >retrieving revision 1.31 >diff -u -r1.31 CDORevisionResolverImpl.java >--- src/org/eclipse/emf/cdo/internal/protocol/revision/CDORevisionResolverImpl.java 6 Sep 2007 10:08:52 -0000 1.31 >+++ src/org/eclipse/emf/cdo/internal/protocol/revision/CDORevisionResolverImpl.java 7 Sep 2007 02:34:39 -0000 >@@ -367,7 +367,8 @@ > int v = r.getVersion(); > if (v == version) > { >- throw new IllegalStateException("Duplicate revision"); >+ // Could have more than 1 version of the same objects... >+ return false; > } > > if (v < version) >Index: META-INF/MANIFEST.MF >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf.cdo/plugins/org.eclipse.emf.cdo.protocol/META-INF/MANIFEST.MF,v >retrieving revision 1.17 >diff -u -r1.17 MANIFEST.MF >--- META-INF/MANIFEST.MF 31 Aug 2007 15:10:46 -0000 1.17 >+++ META-INF/MANIFEST.MF 7 Sep 2007 02:34:39 -0000 >@@ -8,11 +8,13 @@ > Bundle-RequiredExecutionEnvironment: J2SE-1.5 > Require-Bundle: org.eclipse.net4j;bundle-version="[0.8.0,0.9.0)";visibility:=reexport > Import-Package: org.osgi.framework;version="1.3.0";resolution:=optional >-Export-Package: org.eclipse.emf.cdo.internal.protocol;version="0.8.0", >+Export-Package: org.eclipse.emf.cdo.internal.analyzer;version="0.8.0", >+ org.eclipse.emf.cdo.internal.protocol;version="0.8.0", > org.eclipse.emf.cdo.internal.protocol.model;version="0.8.0", > org.eclipse.emf.cdo.internal.protocol.model.core;version="0.8.0", > org.eclipse.emf.cdo.internal.protocol.model.resource;version="0.8.0", > org.eclipse.emf.cdo.internal.protocol.revision;version="0.8.0", >+ org.eclipse.emf.cdo.analyzer;version="0.8.0", > org.eclipse.emf.cdo.protocol;version="0.8.0", > org.eclipse.emf.cdo.protocol.model;version="0.8.0", > org.eclipse.emf.cdo.protocol.model.core;version="0.8.0", >Index: src/org/eclipse/emf/cdo/analyzer/NOOPFetchRuleManager.java >=================================================================== >RCS file: src/org/eclipse/emf/cdo/analyzer/NOOPFetchRuleManager.java >diff -N src/org/eclipse/emf/cdo/analyzer/NOOPFetchRuleManager.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/emf/cdo/analyzer/NOOPFetchRuleManager.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,31 @@ >+package org.eclipse.emf.cdo.analyzer; >+ >+import java.util.Collection; >+import java.util.List; >+ >+import org.eclipse.emf.cdo.internal.analyzer.CDOFetchRule; >+import org.eclipse.emf.cdo.internal.protocol.CDOIDNull; >+import org.eclipse.emf.cdo.protocol.CDOID; >+/** >+ * @author Simon McDuff >+ */ >+public class NOOPFetchRuleManager implements IFetchRuleManager { >+ >+ public List<CDOFetchRule> getFetchFule(CDOID id) >+ { >+ // TODO Auto-generated method stub >+ return null; >+ } >+ >+ public List<CDOFetchRule> getFetchRules(Collection<CDOID> id) >+ { >+ // TODO Auto-generated method stub >+ return null; >+ } >+ >+ public CDOID getContext() { >+ // TODO Auto-generated method stub >+ return CDOIDNull.NULL; >+ } >+ >+} >Index: src/org/eclipse/emf/cdo/analyzer/NOOPFeatureAnalyzer.java >=================================================================== >RCS file: src/org/eclipse/emf/cdo/analyzer/NOOPFeatureAnalyzer.java >diff -N src/org/eclipse/emf/cdo/analyzer/NOOPFeatureAnalyzer.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/emf/cdo/analyzer/NOOPFeatureAnalyzer.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,25 @@ >+package org.eclipse.emf.cdo.analyzer; >+ >+import org.eclipse.emf.cdo.protocol.model.CDOClass; >+import org.eclipse.emf.cdo.protocol.model.CDOFeature; >+import org.eclipse.emf.cdo.protocol.revision.CDORevision; >+/** >+ * @author Simon McDuff >+ */ >+ >+public class NOOPFeatureAnalyzer implements IFeatureAnalyzer >+{ >+ >+ public void postTraverseFeature(CDORevision cdoClass, CDOFeature cdoFeature, int index) >+ { >+ // TODO Auto-generated method stub >+ >+ } >+ >+ public void preTraverseFeature(CDORevision cdoClass, CDOFeature cdoFeature, int index) >+ { >+ // TODO Auto-generated method stub >+ >+ } >+ >+} >Index: src/org/eclipse/emf/cdo/internal/analyzer/CDOFeatureRule.java >=================================================================== >RCS file: src/org/eclipse/emf/cdo/internal/analyzer/CDOFeatureRule.java >diff -N src/org/eclipse/emf/cdo/internal/analyzer/CDOFeatureRule.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/emf/cdo/internal/analyzer/CDOFeatureRule.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,125 @@ >+package org.eclipse.emf.cdo.internal.analyzer; >+ >+import java.util.HashMap; >+import java.util.Iterator; >+ >+import org.eclipse.emf.cdo.internal.protocol.bundle.OM; >+import org.eclipse.emf.cdo.protocol.model.CDOClass; >+import org.eclipse.emf.cdo.protocol.model.CDOFeature; >+import org.eclipse.net4j.internal.util.om.trace.ContextTracer; >+ >+/** >+ * @author Simon McDuff >+ */ >+public class CDOFeatureRule >+{ >+ private static final ContextTracer DEBUG = new ContextTracer(OM.DEBUG, CDOFeatureRule.class); >+ >+ private CDOClass cdoClass = null; >+ private CDOFeature cdoFeature = null; >+ private HashMap<CDOFeature, CDOFetchFeatureStat> featureStats = new HashMap<CDOFeature, CDOFetchFeatureStat>(); >+ private HashMap<CDOClass, CDOFetchRule> fetchRulesMap = new HashMap<CDOClass, CDOFetchRule>(); >+ >+ >+ /** >+ * >+ * @param cdoClass >+ * @param cdoFeature >+ */ >+ public CDOFeatureRule(CDOClass cdoClass, CDOFeature cdoFeature) >+ { >+ this.cdoClass = cdoClass; >+ this.cdoFeature = cdoFeature; >+ } >+ >+ /** >+ * >+ * @return >+ */ >+ public Iterator<CDOFetchRule> iterator() >+ { >+ return fetchRulesMap.values().iterator(); >+ } >+ >+ /** >+ * >+ * @param cdoFeature >+ * @return >+ */ >+ synchronized public CDOFetchFeatureStat getFeatureStat(CDOFeature cdoFeature) >+ { >+ // >+ CDOFetchFeatureStat featureRule = featureStats.get(cdoFeature); >+ >+ if (featureRule == null) >+ { >+ featureRule = new CDOFetchFeatureStat(); >+ featureStats.put(cdoFeature, featureRule); >+ } >+ >+ return featureRule; >+ } >+ synchronized public CDOFetchRule addFeatureRule(CDOClass cdoClass, CDOFeature cdoFeature) >+ { >+ if (DEBUG.isEnabled()) >+ { >+ DEBUG.format("Adding new fetch rule : {0}.{1} from root {2}.{3}", cdoClass.getName(), cdoFeature.getName(), this.cdoClass.getName(),this.cdoFeature.getName()); >+ } >+ CDOFetchRule fetchRule = getFetchRule(cdoClass); >+ >+ fetchRule.addFeature( cdoFeature ); >+ >+ return fetchRule; >+ >+ } >+ synchronized public CDOFetchRule removeFeatureRule(CDOClass cdoClass, CDOFeature cdoFeature) >+ { >+ if (DEBUG.isEnabled()) >+ { >+ DEBUG.format("Adding new fetch rule : {0}.{1} from root {2}.{3}", cdoClass.getName(), cdoFeature.getName(), this.cdoClass.getName(),this.cdoFeature.getName()); >+ } >+ >+ CDOFetchRule fetchRule = getFetchRule(cdoClass); >+ >+ fetchRule.removeFeature( cdoFeature ); >+ >+ if (fetchRule.isEmpty()) >+ { >+ fetchRulesMap.remove( cdoClass ); >+ } >+ >+ return fetchRule; >+ >+ } >+ synchronized public CDOFetchRule getFetchRule(CDOClass cdoFeature) >+ { >+ // >+ CDOFetchRule featureRule = fetchRulesMap.get(cdoFeature); >+ >+ if (featureRule == null) >+ { >+ featureRule = new CDOFetchRule(cdoFeature); >+ fetchRulesMap.put(cdoFeature, featureRule); >+ } >+ >+ return featureRule; >+ } >+ /** >+ * >+ * @return >+ */ >+ public CDOClass getCdoClass() >+ { >+ return cdoClass; >+ } >+ /** >+ * >+ * @return >+ */ >+ public CDOFeature getCdoFeature() >+ { >+ return cdoFeature; >+ } >+ >+ >+} >Index: src/org/eclipse/emf/cdo/analyzer/IFetchRuleManager.java >=================================================================== >RCS file: src/org/eclipse/emf/cdo/analyzer/IFetchRuleManager.java >diff -N src/org/eclipse/emf/cdo/analyzer/IFetchRuleManager.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/emf/cdo/analyzer/IFetchRuleManager.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,19 @@ >+package org.eclipse.emf.cdo.analyzer; >+ >+import java.util.Collection; >+import java.util.List; >+ >+import org.eclipse.emf.cdo.internal.analyzer.CDOFetchRule; >+import org.eclipse.emf.cdo.protocol.CDOID; >+ >+/** >+ * @author Simon McDuff >+ */ >+public interface IFetchRuleManager >+{ >+ static IFetchRuleManager NOOP = new NOOPFetchRuleManager(); >+ >+ public CDOID getContext(); >+ >+ public List<CDOFetchRule> getFetchRules(Collection<CDOID> id); >+} >Index: src/org/eclipse/emf/cdo/internal/analyzer/CDOFeatureAnalyzer.java >=================================================================== >RCS file: src/org/eclipse/emf/cdo/internal/analyzer/CDOFeatureAnalyzer.java >diff -N src/org/eclipse/emf/cdo/internal/analyzer/CDOFeatureAnalyzer.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/emf/cdo/internal/analyzer/CDOFeatureAnalyzer.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,179 @@ >+package org.eclipse.emf.cdo.internal.analyzer; >+ >+import java.util.ArrayList; >+import java.util.Collection; >+import java.util.HashMap; >+import java.util.Iterator; >+import java.util.List; >+ >+import org.eclipse.emf.cdo.analyzer.IFeatureAnalyzer; >+import org.eclipse.emf.cdo.analyzer.IFetchRuleManager; >+import org.eclipse.emf.cdo.internal.protocol.bundle.OM; >+import org.eclipse.emf.cdo.internal.protocol.model.CDOClassImpl; >+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.cdo.protocol.revision.CDORevision; >+import org.eclipse.net4j.internal.util.om.trace.ContextTracer; >+ >+ >+/** >+ * @author Simon McDuff >+ */ >+public class CDOFeatureAnalyzer implements IFeatureAnalyzer, IFetchRuleManager >+{ >+ static private final ContextTracer DEBUG = new ContextTracer(OM.DEBUG, CDOFeatureAnalyzer.class); >+ >+ static private long ELAPSE_TIME = 400; >+ >+ static ThreadLocal<CDOFeatureAnalyzer> threadLocal = new ThreadLocal<CDOFeatureAnalyzer>(); >+ >+ private HashMap<CDOFeature, CDOFeatureRule> featureRulesMap = new HashMap<CDOFeature, CDOFeatureRule>(); >+ >+ private CDOFeatureRule lastFeatureRule = null; >+ >+ private long lastTimeAccess = 0; >+ >+ private boolean inUse = false; >+ >+ private CDORevision lastRevision = null; >+ >+ /** >+ * >+ * @return >+ */ >+ public CDOFeatureRule getCurrentFeatureRule() >+ { >+ return lastFeatureRule; >+ } >+ >+ /** >+ * >+ */ >+ public static CDOFeatureAnalyzer getCurrent() >+ { >+ return threadLocal.get(); >+ } >+ /** >+ * >+ */ >+ public void preTraverseFeature(CDORevision cdoRevision, CDOFeature cdoFeature, int index) >+ { >+ CDOClass cdoClass = cdoRevision.getCDOClass(); >+ threadLocal.set(this); >+ lastRevision = cdoRevision; >+ >+ if (DEBUG.isEnabled()) >+ { >+ DEBUG.format("preTraverseFeature : {0}.{1}", cdoClass.getName(), cdoFeature.getName()); >+ } >+ >+ // Do not handle these cases >+ if (!cdoFeature.isReference() || cdoFeature.isContainment() || (cdoFeature.isMany() && index != 0)) >+ { >+ lastTimeAccess = System.currentTimeMillis(); >+ return; >+ } >+ >+ long currentTime = System.currentTimeMillis(); >+ >+ long elapseTimeBeforeLastRequest = currentTime - lastTimeAccess; >+ >+ if (elapseTimeBeforeLastRequest > ELAPSE_TIME || lastFeatureRule == null) >+ { >+ CDOFeatureRule featureRule = getFeatureRule(cdoClass, cdoFeature); >+ lastFeatureRule = featureRule; >+ } >+ >+ CDOFetchFeatureStat stat = lastFeatureRule.getFeatureStat(cdoFeature); >+ >+ if (stat.getTimeUnusedBefore() != 0) >+ { >+ stat.setTimeUnsedBefore((stat.getTimeUnusedBefore() + elapseTimeBeforeLastRequest) / 2); >+ } >+ else >+ { >+ stat.setTimeUnsedBefore( elapseTimeBeforeLastRequest ); >+ } >+ >+ if (!stat.isValid() && stat.getTimeUnusedBefore() < CDOFeatureAnalyzer.ELAPSE_TIME) >+ { >+ CDOFetchRule fetchRule = lastFeatureRule.addFeatureRule(cdoClass, cdoFeature); >+ stat.setFetchRule( fetchRule ); >+ } >+ else if (stat.isValid() && stat.getTimeUnusedBefore() > CDOFeatureAnalyzer.ELAPSE_TIME) >+ { >+ // Unregister rules >+ lastFeatureRule.removeFeatureRule(cdoClass, cdoFeature); >+ stat.setFetchRule( null ); >+ } >+ >+ >+ lastTimeAccess = currentTime; >+ inUse=true; >+ } >+ >+ >+ >+ /** >+ * >+ */ >+ public void postTraverseFeature(CDORevision cdoRevision, CDOFeature cdoFeature, int index) >+ { >+ if (DEBUG.isEnabled()) >+ { >+ DEBUG.format("postTraverseFeature : {0}.{1}", cdoRevision.getCDOClass(), cdoFeature.getName()); >+ } >+ >+ // TODO Auto-generated method stub >+ lastTimeAccess = System.currentTimeMillis(); >+ inUse = false; >+ threadLocal.set(null); >+ } >+ >+ /** >+ * >+ */ >+ public CDOID getContext() >+ { >+ return lastRevision.getID(); >+ } >+ >+ /** >+ * >+ * @param cdoClass >+ * @param cdoFeature >+ * @return >+ */ >+ synchronized public CDOFeatureRule getFeatureRule(CDOClass cdoClass, CDOFeature cdoFeature) >+ { >+ CDOFeatureRule featureRule = featureRulesMap.get(cdoFeature); >+ >+ if (featureRule == null) >+ { >+ featureRule = new CDOFeatureRule(cdoClass, cdoFeature); >+ featureRulesMap.put(cdoFeature, featureRule); >+ } >+ >+ return featureRule; >+ } >+ >+ /** >+ * >+ */ >+ public List<CDOFetchRule> getFetchRules(Collection<CDOID> id) >+ { >+ // TODO Auto-generated method stub >+ if (!inUse || this.lastFeatureRule == null) >+ return null; >+ >+ ArrayList<CDOFetchRule> list = new ArrayList<CDOFetchRule>(); >+ Iterator<CDOFetchRule> itr = this.lastFeatureRule.iterator(); >+ while (itr.hasNext()) >+ list.add(itr.next()); >+ >+ return list; >+ >+ } >+ >+} >Index: src/org/eclipse/emf/cdo/internal/analyzer/CDOFetchRuleManager.java >=================================================================== >RCS file: src/org/eclipse/emf/cdo/internal/analyzer/CDOFetchRuleManager.java >diff -N src/org/eclipse/emf/cdo/internal/analyzer/CDOFetchRuleManager.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/emf/cdo/internal/analyzer/CDOFetchRuleManager.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,27 @@ >+package org.eclipse.emf.cdo.internal.analyzer; >+ >+import java.util.Collection; >+import java.util.List; >+ >+import org.eclipse.emf.cdo.analyzer.IFetchRuleManager; >+import org.eclipse.emf.cdo.protocol.CDOID; >+ >+/** >+ * @author Simon McDuff >+ */ >+public class CDOFetchRuleManager implements IFetchRuleManager >+{ >+ >+ public CDOID getContext() >+ { >+ // TODO Auto-generated method stub >+ return CDOFeatureAnalyzer.getCurrent().getContext(); >+ } >+ >+ public List<CDOFetchRule> getFetchRules(Collection<CDOID> id) >+ { >+ // TODO Auto-generated method stub >+ return CDOFeatureAnalyzer.getCurrent().getFetchRules(id); >+ } >+ >+} >Index: src/org/eclipse/emf/cdo/internal/analyzer/CDOFetchFeatureStat.java >=================================================================== >RCS file: src/org/eclipse/emf/cdo/internal/analyzer/CDOFetchFeatureStat.java >diff -N src/org/eclipse/emf/cdo/internal/analyzer/CDOFetchFeatureStat.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/emf/cdo/internal/analyzer/CDOFetchFeatureStat.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,55 @@ >+package org.eclipse.emf.cdo.internal.analyzer; >+ >+ >+ >+/** >+ * @author Simon McDuff >+ */ >+public class CDOFetchFeatureStat >+{ >+ >+ private CDOFetchRule fetchRule; >+ private long timeBeforeUsed; >+ private long latencyTime; >+ >+ public CDOFetchFeatureStat() >+ { >+ this.fetchRule = null; >+ } >+ >+ public long getTimeUnusedBefore() >+ { >+ return timeBeforeUsed; >+ } >+ >+ public void setTimeUnsedBefore(long timeUnsedBefore) >+ { >+ this.timeBeforeUsed = timeUnsedBefore; >+ } >+ >+ public long getLatencyTime() >+ { >+ return latencyTime; >+ } >+ >+ public void setLatencyTime(long timeToFetch) >+ { >+ this.latencyTime = timeToFetch; >+ } >+ >+ public CDOFetchRule getFetchRule() >+ { >+ return fetchRule; >+ } >+ >+ public boolean isValid() >+ { >+ return fetchRule != null; >+ } >+ public void setFetchRule(CDOFetchRule fetchRule) >+ { >+ this.fetchRule = fetchRule; >+ } >+ >+ >+} >Index: src/org/eclipse/emf/cdo/internal/analyzer/CDOFetchRule.java >=================================================================== >RCS file: src/org/eclipse/emf/cdo/internal/analyzer/CDOFetchRule.java >diff -N src/org/eclipse/emf/cdo/internal/analyzer/CDOFetchRule.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/emf/cdo/internal/analyzer/CDOFetchRule.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,87 @@ >+package org.eclipse.emf.cdo.internal.analyzer; >+ >+import java.io.IOException; >+import java.util.ArrayList; >+ >+import org.eclipse.emf.cdo.internal.protocol.model.CDOClassImpl; >+import org.eclipse.emf.cdo.internal.protocol.model.CDOClassRefImpl; >+import org.eclipse.emf.cdo.internal.protocol.model.CDOFeatureImpl; >+import org.eclipse.emf.cdo.protocol.model.CDOClass; >+import org.eclipse.emf.cdo.protocol.model.CDOFeature; >+import org.eclipse.emf.cdo.protocol.model.CDOPackageManager; >+import org.eclipse.net4j.util.io.ExtendedDataInput; >+import org.eclipse.net4j.util.io.ExtendedDataOutput; >+ >+/** >+ * @author Simon McDuff >+ */ >+public class CDOFetchRule >+{ >+ private CDOClass cdoClass; >+ private ArrayList<CDOFeature> cdoFeatures = new ArrayList<CDOFeature>(); >+ >+ public CDOFetchRule(CDOClass cdoClass ) >+ { >+ this.cdoClass = cdoClass; >+ } >+ public CDOFetchRule(ExtendedDataInput in, CDOPackageManager packageManager) throws IOException >+ { >+ CDOClassRefImpl classRef = new CDOClassRefImpl(in, null); >+ cdoClass = classRef.resolve(packageManager); >+ CDOFeature[] arrayOfFeature = cdoClass.getAllFeatures(); >+ int size = in.readInt(); >+ for (int i =0; i < size;i++) >+ { >+ int featureIndex = in.readInt(); >+ cdoFeatures.add(arrayOfFeature[featureIndex]); >+ } >+ } >+ public void addFeature(CDOFeature cdoFeature) >+ { >+ cdoFeatures.add(cdoFeature); >+ } >+ /* (non-Javadoc) >+ * @see org.eclipse.emf.cdo.internal.analyzer.IFetchRule#removeFeature(org.eclipse.emf.cdo.protocol.model.CDOFeature) >+ */ >+ public void removeFeature(CDOFeature cdoFeature) >+ { >+ cdoFeatures.remove(cdoFeature); >+ >+ } >+ /* (non-Javadoc) >+ * @see org.eclipse.emf.cdo.internal.analyzer.IFetchRule#isEmpty() >+ */ >+ public boolean isEmpty() >+ { >+ return cdoFeatures.isEmpty(); >+ } >+ >+ /** >+ * >+ * @param out >+ * @throws IOException >+ */ >+ public void write(ExtendedDataOutput out) throws IOException >+ { >+ ((CDOClassImpl)cdoClass).createClassRef().write(out, null); >+ out.writeInt(cdoFeatures.size()); >+ for (CDOFeature cdofeature : cdoFeatures) >+ { >+ out.writeInt(((CDOFeatureImpl)cdofeature).getFeatureIndex()); >+ } >+ >+ } >+ /* (non-Javadoc) >+ * @see org.eclipse.emf.cdo.internal.analyzer.IFetchRule#getCdoFeatures() >+ */ >+ public ArrayList<CDOFeature> getCdoFeatures() >+ { >+ return cdoFeatures; >+ } >+ /* (non-Javadoc) >+ * @see org.eclipse.emf.cdo.internal.analyzer.IFetchRule#getCdoClass() >+ */ >+ public CDOClass getCdoClass() { >+ return cdoClass; >+ } >+} >Index: src/org/eclipse/emf/cdo/analyzer/IFeatureAnalyzer.java >=================================================================== >RCS file: src/org/eclipse/emf/cdo/analyzer/IFeatureAnalyzer.java >diff -N src/org/eclipse/emf/cdo/analyzer/IFeatureAnalyzer.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/emf/cdo/analyzer/IFeatureAnalyzer.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,14 @@ >+package org.eclipse.emf.cdo.analyzer; >+ >+import org.eclipse.emf.cdo.protocol.model.CDOFeature; >+import org.eclipse.emf.cdo.protocol.revision.CDORevision; >+ >+/** >+ * @author Simon McDuff >+ */ >+public interface IFeatureAnalyzer >+{ >+ static IFeatureAnalyzer eNOOP = new NOOPFeatureAnalyzer(); >+ public void postTraverseFeature(CDORevision cdoRevision, CDOFeature cdoFeature, int index); >+ public void preTraverseFeature(CDORevision cdoRevision, CDOFeature cdoFeature, int index); >+}
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