Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 202064 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/emf/cdo/internal/server/protocol/LoadRevisionIndication.java (-3 / +82 lines)
Lines 10-21 Link Here
10
 **************************************************************************/
10
 **************************************************************************/
11
package org.eclipse.emf.cdo.internal.server.protocol;
11
package org.eclipse.emf.cdo.internal.server.protocol;
12
12
13
import org.eclipse.emf.cdo.internal.analyzer.CDOFetchRule;
13
import org.eclipse.emf.cdo.internal.protocol.CDOIDImpl;
14
import org.eclipse.emf.cdo.internal.protocol.CDOIDImpl;
15
import org.eclipse.emf.cdo.internal.protocol.CDOIDNull;
14
import org.eclipse.emf.cdo.internal.protocol.revision.CDORevisionImpl;
16
import org.eclipse.emf.cdo.internal.protocol.revision.CDORevisionImpl;
17
import org.eclipse.emf.cdo.internal.protocol.revision.CDORevisionImpl.MoveableList;
15
import org.eclipse.emf.cdo.internal.server.Session;
18
import org.eclipse.emf.cdo.internal.server.Session;
16
import org.eclipse.emf.cdo.internal.server.bundle.OM;
19
import org.eclipse.emf.cdo.internal.server.bundle.OM;
17
import org.eclipse.emf.cdo.protocol.CDOID;
20
import org.eclipse.emf.cdo.protocol.CDOID;
18
import org.eclipse.emf.cdo.protocol.CDOProtocolConstants;
21
import org.eclipse.emf.cdo.protocol.CDOProtocolConstants;
22
import org.eclipse.emf.cdo.protocol.model.CDOClass;
23
import org.eclipse.emf.cdo.protocol.model.CDOFeature;
19
24
20
import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
25
import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
21
import org.eclipse.net4j.util.io.ExtendedDataInputStream;
26
import org.eclipse.net4j.util.io.ExtendedDataInputStream;
Lines 23-29 Link Here
23
28
24
import java.io.IOException;
29
import java.io.IOException;
25
import java.util.ArrayList;
30
import java.util.ArrayList;
31
import java.util.HashMap;
32
import java.util.HashSet;
26
import java.util.List;
33
import java.util.List;
34
import java.util.Set;
27
35
28
/**
36
/**
29
 * @author Eike Stepper
37
 * @author Eike Stepper
Lines 36-41 Link Here
36
44
37
  protected int referenceChunk;
45
  protected int referenceChunk;
38
46
47
  protected HashMap<CDOClass, CDOFetchRule> fetchRules = new HashMap<CDOClass, CDOFetchRule>();
48
49
  protected CDOID contextId = CDOIDNull.NULL; 
50
  
39
  public LoadRevisionIndication()
51
  public LoadRevisionIndication()
40
  {
52
  {
41
  }
53
  }
Lines 62-86 Link Here
62
      if (PROTOCOL.isEnabled()) PROTOCOL.format("Read ID: {0}", id);
74
      if (PROTOCOL.isEnabled()) PROTOCOL.format("Read ID: {0}", id);
63
      ids[i] = id;
75
      ids[i] = id;
64
    }
76
    }
77
    
78
    int fetchSize = in.readInt();
79
	if (fetchSize > 0)
80
	{
81
		contextId = CDOIDImpl.read(in);
82
		for (int i =0; i< fetchSize; i++)
83
		{
84
			CDOFetchRule fetchRule = new CDOFetchRule(in, getPackageManager());
85
			for (CDOFeature cdoFeature : fetchRule.getCdoFeatures())
86
				fetchRules.put(fetchRule.getCdoClass(), fetchRule);
87
		}
88
	}    
65
  }
89
  }
66
90
91
  private void collectRevisionsByRule(CDORevisionImpl revision, int referenceChunk, HashMap<CDOID, CDORevisionImpl> attachedObjects, Set<CDOFetchRule> workingFetchRule)
92
  {
93
	  CDOFetchRule fetchRule = fetchRules.get(revision.getCDOClass());
94
	  
95
	  if (fetchRule == null || workingFetchRule.contains(fetchRule))
96
		  return;
97
	  
98
	  workingFetchRule.add(fetchRule);
99
	  
100
	  for (CDOFeature feature : fetchRule.getCdoFeatures())
101
	  {
102
		  if (!feature.isMany())
103
		  {
104
			  Object object = revision.get(feature, 0);
105
			  if (object != null && object instanceof CDOID)
106
			  {
107
				  CDOID cdoId = (CDOID)object;
108
  		  		  if (!cdoId.isNull() && attachedObjects.get(cdoId) ==  null)
109
  		  		  {
110
			  			CDORevisionImpl containedRevision = (CDORevisionImpl)getSessionManager().getRepository().getRevisionManager().getRevision(cdoId, referenceChunk);
111
			  			attachedObjects.put(containedRevision.getID(), containedRevision);
112
			  			collectRevisionsByRule(containedRevision, referenceChunk, attachedObjects, workingFetchRule);
113
			  	  }
114
			  }
115
		  }
116
		  else if (feature.isMany())
117
		  {
118
		      MoveableList list = revision.getList(feature);
119
		      int toIndex = Math.min(referenceChunk, list.size());
120
		      for (int i = 0; i < toIndex; i++)
121
		      {
122
		    	  Object object = list.get(i);
123
		    	  if (object instanceof CDOID)
124
		    	  {
125
		    		    
126
		    		    CDOID cdoId = (CDOID)object;
127
			  			CDORevisionImpl containedRevision = (CDORevisionImpl)getSessionManager().getRepository().getRevisionManager().getRevision(cdoId, referenceChunk);
128
			  			attachedObjects.put(containedRevision.getID(), containedRevision);
129
			  			
130
			  			collectRevisionsByRule(containedRevision, referenceChunk, attachedObjects, workingFetchRule);
131
		    	  }
132
		      }
133
		  }
134
	  }
135
	  workingFetchRule.remove(fetchRule);
136
  }
137
  
67
  @Override
138
  @Override
68
  protected void responding(ExtendedDataOutputStream out) throws IOException
139
  protected void responding(ExtendedDataOutputStream out) throws IOException
69
  {
140
  {
70
    Session session = getSession();
141
    Session session = getSession();
71
    List<CDORevisionImpl> containedRevisions = new ArrayList<CDORevisionImpl>(0);
142
    HashMap<CDOID, CDORevisionImpl> containedRevisions = new HashMap<CDOID, CDORevisionImpl>(0);
72
143
73
    if (PROTOCOL.isEnabled()) PROTOCOL.format("Writing {0} revisions", ids.length);
144
    if (PROTOCOL.isEnabled()) PROTOCOL.format("Writing {0} revisions", ids.length);
145
    
74
    for (CDOID id : ids)
146
    for (CDOID id : ids)
75
    {
147
    {
76
      CDORevisionImpl revision = getRevision(id);
148
      CDORevisionImpl revision = getRevision(id);
77
      revision.write(out, session, referenceChunk);
149
      revision.write(out, session, referenceChunk);
78
      session.collectContainedRevisions(revision, referenceChunk, containedRevisions);
150
      session.collectContainedRevisions(revision, referenceChunk, containedRevisions);
79
    }
151
    }
80
152
    
153
    if (!contextId.isNull() && fetchRules.size() > 0 )
154
    {
155
    	int newReferenceChunk = Math.max(referenceChunk, 1000);
156
    	CDORevisionImpl revisionContext = getRevision(contextId);
157
    	this.collectRevisionsByRule(revisionContext, newReferenceChunk, containedRevisions, new HashSet<CDOFetchRule>());
158
    }
159
    
81
    out.writeInt(containedRevisions.size());
160
    out.writeInt(containedRevisions.size());
82
    if (PROTOCOL.isEnabled()) PROTOCOL.format("Writing {0} additional revisions", containedRevisions.size());
161
    if (PROTOCOL.isEnabled()) PROTOCOL.format("Writing {0} additional revisions", containedRevisions.size());
83
    for (CDORevisionImpl revision : containedRevisions)
162
    for (CDORevisionImpl revision : containedRevisions.values())
84
    {
163
    {
85
      revision.write(out, session, referenceChunk);
164
      revision.write(out, session, referenceChunk);
86
    }
165
    }
(-)src/org/eclipse/emf/cdo/internal/server/Session.java (-4 / +8 lines)
Lines 35-40 Link Here
35
import java.text.MessageFormat;
35
import java.text.MessageFormat;
36
import java.util.Collection;
36
import java.util.Collection;
37
import java.util.HashSet;
37
import java.util.HashSet;
38
import java.util.Map;
38
import java.util.Set;
39
import java.util.Set;
39
import java.util.concurrent.ConcurrentHashMap;
40
import java.util.concurrent.ConcurrentHashMap;
40
import java.util.concurrent.ConcurrentMap;
41
import java.util.concurrent.ConcurrentMap;
Lines 187-193 Link Here
187
   * TODO I can't see how recursion is controlled/limited
188
   * TODO I can't see how recursion is controlled/limited
188
   */
189
   */
189
  public void collectContainedRevisions(CDORevisionImpl revision, int referenceChunk,
190
  public void collectContainedRevisions(CDORevisionImpl revision, int referenceChunk,
190
      Collection<CDORevisionImpl> containedRevisions)
191
      Map<CDOID, CDORevisionImpl> containedRevisions)
191
  {
192
  {
192
    RevisionManager revisionManager = getSessionManager().getRepository().getRevisionManager();
193
    RevisionManager revisionManager = getSessionManager().getRepository().getRevisionManager();
193
    CDOClassImpl cdoClass = revision.getCDOClass();
194
    CDOClassImpl cdoClass = revision.getCDOClass();
Lines 203-211 Link Here
203
          CDOID id = (CDOID)value;
204
          CDOID id = (CDOID)value;
204
          if (!id.isNull())
205
          if (!id.isNull())
205
          {
206
          {
206
            CDORevisionImpl containedRevision = revisionManager.getRevision(id, referenceChunk);
207
        	if (containedRevisions.get(id) == null)
207
            containedRevisions.add(containedRevision);
208
        	{
208
            collectContainedRevisions(containedRevision, referenceChunk, containedRevisions);
209
        		CDORevisionImpl containedRevision = revisionManager.getRevision(id, referenceChunk);
210
        		containedRevisions.put(id, containedRevision);
211
        		collectContainedRevisions(containedRevision, referenceChunk, containedRevisions);
212
        	}
209
          }
213
          }
210
        }
214
        }
211
      }
215
      }
(-)src/org/eclipse/emf/internal/cdo/CDOViewImpl.java (-1 / +11 lines)
Lines 15-20 Link Here
15
import org.eclipse.emf.cdo.CDOView;
15
import org.eclipse.emf.cdo.CDOView;
16
import org.eclipse.emf.cdo.CDOViewEvent;
16
import org.eclipse.emf.cdo.CDOViewEvent;
17
import org.eclipse.emf.cdo.CDOViewResourcesEvent;
17
import org.eclipse.emf.cdo.CDOViewResourcesEvent;
18
import org.eclipse.emf.cdo.analyzer.*;
18
import org.eclipse.emf.cdo.eresource.CDOResource;
19
import org.eclipse.emf.cdo.eresource.CDOResource;
19
import org.eclipse.emf.cdo.eresource.EresourceFactory;
20
import org.eclipse.emf.cdo.eresource.EresourceFactory;
20
import org.eclipse.emf.cdo.eresource.impl.CDOResourceImpl;
21
import org.eclipse.emf.cdo.eresource.impl.CDOResourceImpl;
Lines 56-62 Link Here
56
import java.util.List;
57
import java.util.List;
57
import java.util.Map;
58
import java.util.Map;
58
import java.util.Set;
59
import java.util.Set;
59
60
/**
60
/**
61
 * @author Eike Stepper
61
 * @author Eike Stepper
62
 */
62
 */
Lines 83-88 Link Here
83
83
84
  private int loadRevisionCollectionChunkSize;
84
  private int loadRevisionCollectionChunkSize;
85
85
86
  private IFeatureAnalyzer featureAnalyzer = IFeatureAnalyzer.eNOOP;
87
  
86
  public CDOViewImpl(int id, CDOSessionImpl session)
88
  public CDOViewImpl(int id, CDOSessionImpl session)
87
  {
89
  {
88
    this.viewID = id;
90
    this.viewID = id;
Lines 792-795 Link Here
792
  {
794
  {
793
    this.loadRevisionCollectionChunkSize = loadRevisionCollectionChunkSize;
795
    this.loadRevisionCollectionChunkSize = loadRevisionCollectionChunkSize;
794
  }
796
  }
797
798
public IFeatureAnalyzer getFeatureAnalyzer() {
799
	return featureAnalyzer;
800
}
801
802
public void setFeatureAnalyzer(IFeatureAnalyzer featureAnalyzer) {
803
	this.featureAnalyzer = featureAnalyzer;
804
}
795
}
805
}
(-)src/org/eclipse/emf/internal/cdo/CDOStore.java (-3 / +9 lines)
Lines 99-106 Link Here
99
99
100
  public Object get(InternalEObject eObject, EStructuralFeature eFeature, int index)
100
  public Object get(InternalEObject eObject, EStructuralFeature eFeature, int index)
101
  {
101
  {
102
	 
102
    InternalCDOObject cdoObject = getCDOObject(eObject);
103
    InternalCDOObject cdoObject = getCDOObject(eObject);
103
    CDOFeatureImpl cdoFeature = getCDOFeature(cdoObject, eFeature);
104
    CDOFeatureImpl cdoFeature = getCDOFeature(cdoObject, eFeature);
105
    
106
    view.getFeatureAnalyzer().preTraverseFeature(cdoObject.cdoRevision(), cdoFeature, index);
107
    
104
    if (TRACER.isEnabled())
108
    if (TRACER.isEnabled())
105
    {
109
    {
106
      TRACER.format("get({0}, {1}, {2})", cdoObject, cdoFeature, index);
110
      TRACER.format("get({0}, {1}, {2})", cdoObject, cdoFeature, index);
Lines 118-123 Link Here
118
122
119
      value = view.convertIDToObject(value);
123
      value = view.convertIDToObject(value);
120
    }
124
    }
125
    
126
    view.getFeatureAnalyzer().postTraverseFeature(cdoObject.cdoRevision(), cdoFeature, index);
121
127
122
    return value;
128
    return value;
123
  }
129
  }
Lines 132-141 Link Here
132
    {
138
    {
133
      MoveableList list = revision.getList(cdoFeature);
139
      MoveableList list = revision.getList(cdoFeature);
134
      int fromIndex = index;
140
      int fromIndex = index;
135
      int toIndex = Math.min(index + chunkSize - 1, list.size());
141
      int toIndex = Math.min(index + chunkSize, list.size());
136
142
137
      Set<CDOID> notRegistered = new HashSet<CDOID>();
143
      Set<CDOID> notRegistered = new HashSet<CDOID>();
138
      for (int i = fromIndex; i <= toIndex; i++)
144
      for (int i = fromIndex; i < toIndex; i++)
139
      {
145
      {
140
        Object element = list.get(i);
146
        Object element = list.get(i);
141
        if (element instanceof CDOID)
147
        if (element instanceof CDOID)
Lines 149-155 Link Here
149
          }
155
          }
150
        }
156
        }
151
      }
157
      }
152
158
      
153
      if (!notRegistered.isEmpty())
159
      if (!notRegistered.isEmpty())
154
      {
160
      {
155
        int referenceChunk = session.getReferenceChunkSize();
161
        int referenceChunk = session.getReferenceChunkSize();
(-)src/org/eclipse/emf/internal/cdo/CDORevisionManagerImpl.java (-1 / +12 lines)
Lines 11-16 Link Here
11
package org.eclipse.emf.internal.cdo;
11
package org.eclipse.emf.internal.cdo;
12
12
13
import org.eclipse.emf.cdo.CDORevisionManager;
13
import org.eclipse.emf.cdo.CDORevisionManager;
14
import org.eclipse.emf.cdo.analyzer.IFetchRuleManager;
14
import org.eclipse.emf.cdo.internal.protocol.revision.CDORevisionImpl;
15
import org.eclipse.emf.cdo.internal.protocol.revision.CDORevisionImpl;
15
import org.eclipse.emf.cdo.internal.protocol.revision.CDORevisionResolverImpl;
16
import org.eclipse.emf.cdo.internal.protocol.revision.CDORevisionResolverImpl;
16
import org.eclipse.emf.cdo.internal.protocol.revision.CDORevisionImpl.MoveableList;
17
import org.eclipse.emf.cdo.internal.protocol.revision.CDORevisionImpl.MoveableList;
Lines 37-43 Link Here
37
public class CDORevisionManagerImpl extends CDORevisionResolverImpl implements CDORevisionManager
38
public class CDORevisionManagerImpl extends CDORevisionResolverImpl implements CDORevisionManager
38
{
39
{
39
  private CDOSessionImpl session;
40
  private CDOSessionImpl session;
40
41
  
42
  private IFetchRuleManager ruleManager = IFetchRuleManager.NOOP;
43
  
41
  public CDORevisionManagerImpl(CDOSessionImpl session)
44
  public CDORevisionManagerImpl(CDOSessionImpl session)
42
  {
45
  {
43
    this.session = session;
46
    this.session = session;
Lines 247-250 Link Here
247
      throw new TransportException(ex);
250
      throw new TransportException(ex);
248
    }
251
    }
249
  }
252
  }
253
254
public IFetchRuleManager getRuleManager() {
255
	return ruleManager;
256
}
257
258
public void setRuleManager(IFetchRuleManager ruleManager) {
259
	this.ruleManager = ruleManager;
260
}
250
}
261
}
(-)src/org/eclipse/emf/internal/cdo/protocol/LoadRevisionRequest.java (-12 / +32 lines)
Lines 10-35 Link Here
10
 **************************************************************************/
10
 **************************************************************************/
11
package org.eclipse.emf.internal.cdo.protocol;
11
package org.eclipse.emf.internal.cdo.protocol;
12
12
13
import java.io.IOException;
14
import java.util.ArrayList;
15
import java.util.Collection;
16
import java.util.Collections;
17
import java.util.List;
18
19
import org.eclipse.emf.cdo.internal.analyzer.CDOFetchRule;
13
import org.eclipse.emf.cdo.internal.protocol.CDOIDImpl;
20
import org.eclipse.emf.cdo.internal.protocol.CDOIDImpl;
14
import org.eclipse.emf.cdo.internal.protocol.revision.CDORevisionImpl;
21
import org.eclipse.emf.cdo.internal.protocol.revision.CDORevisionImpl;
15
import org.eclipse.emf.cdo.protocol.CDOID;
22
import org.eclipse.emf.cdo.protocol.CDOID;
16
import org.eclipse.emf.cdo.protocol.CDOProtocolConstants;
23
import org.eclipse.emf.cdo.protocol.CDOProtocolConstants;
17
24
import org.eclipse.emf.cdo.protocol.model.CDOFeature;
18
import org.eclipse.net4j.IChannel;
19
import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
20
import org.eclipse.net4j.util.io.ExtendedDataInputStream;
21
import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
22
23
import org.eclipse.emf.internal.cdo.CDORevisionManagerImpl;
25
import org.eclipse.emf.internal.cdo.CDORevisionManagerImpl;
24
import org.eclipse.emf.internal.cdo.CDOSessionImpl;
26
import org.eclipse.emf.internal.cdo.CDOSessionImpl;
25
import org.eclipse.emf.internal.cdo.CDOSessionPackageManager;
27
import org.eclipse.emf.internal.cdo.CDOSessionPackageManager;
26
import org.eclipse.emf.internal.cdo.bundle.OM;
28
import org.eclipse.emf.internal.cdo.bundle.OM;
27
29
import org.eclipse.net4j.IChannel;
28
import java.io.IOException;
30
import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
29
import java.util.ArrayList;
31
import org.eclipse.net4j.util.io.ExtendedDataInputStream;
30
import java.util.Collection;
32
import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
31
import java.util.Collections;
32
import java.util.List;
33
33
34
/**
34
/**
35
 * @author Eike Stepper
35
 * @author Eike Stepper
Lines 74-79 Link Here
74
      if (PROTOCOL.isEnabled()) PROTOCOL.format("Writing ID: {0}", id);
74
      if (PROTOCOL.isEnabled()) PROTOCOL.format("Writing ID: {0}", id);
75
      CDOIDImpl.write(out, id);
75
      CDOIDImpl.write(out, id);
76
    }
76
    }
77
    
78
    List<CDOFetchRule> fetchRules = getSession().getRevisionManager().getRuleManager().getFetchRules(ids);
79
 	 
80
	 if (fetchRules == null || fetchRules.size() == 0)
81
	 {
82
		 out.writeInt(0);
83
	 }
84
	 else
85
	 {
86
		 CDOID cdoIdContext = getSession().getRevisionManager().getRuleManager().getContext();
87
		 
88
		 out.writeInt(fetchRules.size());
89
		 
90
		 CDOIDImpl.write(out, cdoIdContext);
91
		 
92
		 for (CDOFetchRule fetchRule : fetchRules)
93
		 {
94
			 fetchRule.write(out);
95
		 }
96
	 }    
77
  }
97
  }
78
98
79
  @Override
99
  @Override
(-)src/org/eclipse/emf/cdo/internal/protocol/revision/CDORevisionResolverImpl.java (-1 / +2 lines)
Lines 367-373 Link Here
367
        int v = r.getVersion();
367
        int v = r.getVersion();
368
        if (v == version)
368
        if (v == version)
369
        {
369
        {
370
          throw new IllegalStateException("Duplicate revision");
370
          // Could have more than 1 version of the same objects...
371
          return false;
371
        }
372
        }
372
373
373
        if (v < version)
374
        if (v < version)
(-)META-INF/MANIFEST.MF (-1 / +3 lines)
Lines 8-18 Link Here
8
Bundle-RequiredExecutionEnvironment: J2SE-1.5
8
Bundle-RequiredExecutionEnvironment: J2SE-1.5
9
Require-Bundle: org.eclipse.net4j;bundle-version="[0.8.0,0.9.0)";visibility:=reexport
9
Require-Bundle: org.eclipse.net4j;bundle-version="[0.8.0,0.9.0)";visibility:=reexport
10
Import-Package: org.osgi.framework;version="1.3.0";resolution:=optional
10
Import-Package: org.osgi.framework;version="1.3.0";resolution:=optional
11
Export-Package: org.eclipse.emf.cdo.internal.protocol;version="0.8.0",
11
Export-Package: org.eclipse.emf.cdo.internal.analyzer;version="0.8.0",
12
 org.eclipse.emf.cdo.internal.protocol;version="0.8.0",
12
 org.eclipse.emf.cdo.internal.protocol.model;version="0.8.0",
13
 org.eclipse.emf.cdo.internal.protocol.model;version="0.8.0",
13
 org.eclipse.emf.cdo.internal.protocol.model.core;version="0.8.0",
14
 org.eclipse.emf.cdo.internal.protocol.model.core;version="0.8.0",
14
 org.eclipse.emf.cdo.internal.protocol.model.resource;version="0.8.0",
15
 org.eclipse.emf.cdo.internal.protocol.model.resource;version="0.8.0",
15
 org.eclipse.emf.cdo.internal.protocol.revision;version="0.8.0",
16
 org.eclipse.emf.cdo.internal.protocol.revision;version="0.8.0",
17
 org.eclipse.emf.cdo.analyzer;version="0.8.0",
16
 org.eclipse.emf.cdo.protocol;version="0.8.0",
18
 org.eclipse.emf.cdo.protocol;version="0.8.0",
17
 org.eclipse.emf.cdo.protocol.model;version="0.8.0",
19
 org.eclipse.emf.cdo.protocol.model;version="0.8.0",
18
 org.eclipse.emf.cdo.protocol.model.core;version="0.8.0",
20
 org.eclipse.emf.cdo.protocol.model.core;version="0.8.0",
(-)src/org/eclipse/emf/cdo/analyzer/NOOPFetchRuleManager.java (+31 lines)
Added Link Here
1
package org.eclipse.emf.cdo.analyzer;
2
3
import java.util.Collection;
4
import java.util.List;
5
6
import org.eclipse.emf.cdo.internal.analyzer.CDOFetchRule;
7
import org.eclipse.emf.cdo.internal.protocol.CDOIDNull;
8
import org.eclipse.emf.cdo.protocol.CDOID;
9
/**
10
 * @author Simon McDuff 
11
 */
12
public class NOOPFetchRuleManager implements IFetchRuleManager {
13
14
	public List<CDOFetchRule> getFetchFule(CDOID id) 
15
	{
16
		// TODO Auto-generated method stub
17
		return null;
18
	}
19
20
	public List<CDOFetchRule> getFetchRules(Collection<CDOID> id) 
21
	{
22
		// TODO Auto-generated method stub
23
		return null;
24
	}
25
26
	public CDOID getContext() {
27
		// TODO Auto-generated method stub
28
		return CDOIDNull.NULL;
29
	}
30
31
}
(-)src/org/eclipse/emf/cdo/analyzer/NOOPFeatureAnalyzer.java (+25 lines)
Added Link Here
1
package org.eclipse.emf.cdo.analyzer;
2
3
import org.eclipse.emf.cdo.protocol.model.CDOClass;
4
import org.eclipse.emf.cdo.protocol.model.CDOFeature;
5
import org.eclipse.emf.cdo.protocol.revision.CDORevision;
6
/**
7
 * @author Simon McDuff 
8
 */
9
10
public class NOOPFeatureAnalyzer implements IFeatureAnalyzer 
11
{
12
13
	public void postTraverseFeature(CDORevision cdoClass, CDOFeature cdoFeature, int index) 
14
	{
15
		// TODO Auto-generated method stub
16
17
	}
18
19
	public void preTraverseFeature(CDORevision cdoClass, CDOFeature cdoFeature, int index) 
20
	{
21
		// TODO Auto-generated method stub
22
23
	}
24
25
}
(-)src/org/eclipse/emf/cdo/internal/analyzer/CDOFeatureRule.java (+125 lines)
Added Link Here
1
package org.eclipse.emf.cdo.internal.analyzer;
2
3
import java.util.HashMap;
4
import java.util.Iterator;
5
6
import org.eclipse.emf.cdo.internal.protocol.bundle.OM;
7
import org.eclipse.emf.cdo.protocol.model.CDOClass;
8
import org.eclipse.emf.cdo.protocol.model.CDOFeature;
9
import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
10
11
/**
12
 * @author Simon McDuff 
13
 */
14
public class CDOFeatureRule 
15
{
16
	private static final ContextTracer DEBUG = new ContextTracer(OM.DEBUG, CDOFeatureRule.class);
17
	
18
	private CDOClass cdoClass = null;
19
	private CDOFeature cdoFeature = null;
20
	private HashMap<CDOFeature, CDOFetchFeatureStat> featureStats = new HashMap<CDOFeature, CDOFetchFeatureStat>();
21
	private HashMap<CDOClass, CDOFetchRule> fetchRulesMap = new HashMap<CDOClass, CDOFetchRule>();
22
	
23
	
24
	/**
25
	 * 
26
	 * @param cdoClass
27
	 * @param cdoFeature
28
	 */
29
	public CDOFeatureRule(CDOClass cdoClass, CDOFeature cdoFeature)
30
	{
31
		this.cdoClass = cdoClass;
32
		this.cdoFeature = cdoFeature;
33
	}
34
	
35
	/**
36
	 * 
37
	 * @return
38
	 */
39
	public Iterator<CDOFetchRule> iterator()
40
	{
41
		return fetchRulesMap.values().iterator();
42
	}
43
	
44
	/**
45
	 * 
46
	 * @param cdoFeature
47
	 * @return
48
	 */
49
	synchronized public CDOFetchFeatureStat getFeatureStat(CDOFeature cdoFeature) 
50
	{
51
		// 
52
		CDOFetchFeatureStat featureRule = featureStats.get(cdoFeature);
53
		
54
		if (featureRule == null)
55
		{
56
			featureRule = new CDOFetchFeatureStat();
57
			featureStats.put(cdoFeature, featureRule);
58
		}
59
		
60
		return featureRule;
61
	}
62
	synchronized public CDOFetchRule addFeatureRule(CDOClass cdoClass, CDOFeature cdoFeature)
63
	{
64
		if (DEBUG.isEnabled())
65
		{
66
			DEBUG.format("Adding new fetch rule : {0}.{1} from root {2}.{3}", cdoClass.getName(),  cdoFeature.getName(), this.cdoClass.getName(),this.cdoFeature.getName());
67
		}
68
		CDOFetchRule fetchRule  = getFetchRule(cdoClass);
69
		
70
		fetchRule.addFeature( cdoFeature );
71
		
72
		return fetchRule;
73
		
74
	}
75
	synchronized public CDOFetchRule removeFeatureRule(CDOClass cdoClass, CDOFeature cdoFeature)
76
	{
77
		if (DEBUG.isEnabled())
78
		{
79
			DEBUG.format("Adding new fetch rule : {0}.{1} from root {2}.{3}", cdoClass.getName(),  cdoFeature.getName(), this.cdoClass.getName(),this.cdoFeature.getName());
80
		}
81
		
82
		CDOFetchRule fetchRule  = getFetchRule(cdoClass);
83
		
84
		fetchRule.removeFeature( cdoFeature );
85
		
86
		if (fetchRule.isEmpty())
87
		{
88
			fetchRulesMap.remove( cdoClass );
89
		}
90
		
91
		return fetchRule;
92
		
93
	}
94
	synchronized public CDOFetchRule getFetchRule(CDOClass cdoFeature) 
95
	{
96
		// 
97
		CDOFetchRule featureRule = fetchRulesMap.get(cdoFeature);
98
		
99
		if (featureRule == null)
100
		{
101
			featureRule = new CDOFetchRule(cdoFeature);
102
			fetchRulesMap.put(cdoFeature, featureRule);
103
		}
104
		
105
		return featureRule;
106
	}
107
	/**
108
	 * 
109
	 * @return
110
	 */
111
	public CDOClass getCdoClass() 
112
	{
113
		return cdoClass;
114
	}
115
	/**
116
	 * 
117
	 * @return
118
	 */
119
	public CDOFeature getCdoFeature() 
120
	{
121
		return cdoFeature;
122
	}
123
	
124
	
125
}
(-)src/org/eclipse/emf/cdo/analyzer/IFetchRuleManager.java (+19 lines)
Added Link Here
1
package org.eclipse.emf.cdo.analyzer;
2
3
import java.util.Collection;
4
import java.util.List;
5
6
import org.eclipse.emf.cdo.internal.analyzer.CDOFetchRule;
7
import org.eclipse.emf.cdo.protocol.CDOID;
8
9
/**
10
 * @author Simon McDuff 
11
 */
12
public interface IFetchRuleManager 
13
{
14
	static IFetchRuleManager NOOP = new NOOPFetchRuleManager();
15
	
16
	public CDOID getContext();
17
	
18
	public List<CDOFetchRule> getFetchRules(Collection<CDOID> id);
19
}
(-)src/org/eclipse/emf/cdo/internal/analyzer/CDOFeatureAnalyzer.java (+179 lines)
Added Link Here
1
package org.eclipse.emf.cdo.internal.analyzer;
2
3
import java.util.ArrayList;
4
import java.util.Collection;
5
import java.util.HashMap;
6
import java.util.Iterator;
7
import java.util.List;
8
9
import org.eclipse.emf.cdo.analyzer.IFeatureAnalyzer;
10
import org.eclipse.emf.cdo.analyzer.IFetchRuleManager;
11
import org.eclipse.emf.cdo.internal.protocol.bundle.OM;
12
import org.eclipse.emf.cdo.internal.protocol.model.CDOClassImpl;
13
import org.eclipse.emf.cdo.protocol.CDOID;
14
import org.eclipse.emf.cdo.protocol.model.CDOClass;
15
import org.eclipse.emf.cdo.protocol.model.CDOFeature;
16
import org.eclipse.emf.cdo.protocol.revision.CDORevision;
17
import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
18
19
20
/**
21
 * @author Simon McDuff 
22
 */
23
public class CDOFeatureAnalyzer implements IFeatureAnalyzer, IFetchRuleManager
24
{
25
	static private final ContextTracer DEBUG = new ContextTracer(OM.DEBUG, CDOFeatureAnalyzer.class);
26
	
27
	static private long ELAPSE_TIME = 400;
28
	
29
	static ThreadLocal<CDOFeatureAnalyzer> threadLocal = new ThreadLocal<CDOFeatureAnalyzer>();
30
	
31
	private HashMap<CDOFeature, CDOFeatureRule> featureRulesMap = new HashMap<CDOFeature, CDOFeatureRule>();
32
	
33
	private CDOFeatureRule lastFeatureRule = null;
34
	
35
	private long lastTimeAccess = 0;
36
	
37
	private boolean inUse = false;
38
	
39
	private CDORevision lastRevision = null;
40
	
41
	/**
42
	 * 
43
	 * @return
44
	 */
45
	public CDOFeatureRule getCurrentFeatureRule()
46
	{
47
		return lastFeatureRule;
48
	}
49
	
50
	/**
51
	 * 
52
	 */
53
	public static CDOFeatureAnalyzer getCurrent()
54
	{
55
		return threadLocal.get();
56
	}
57
	/**
58
	 * 
59
	 */
60
	public void preTraverseFeature(CDORevision cdoRevision, CDOFeature cdoFeature, int index) 
61
	{
62
		CDOClass cdoClass = cdoRevision.getCDOClass();
63
		threadLocal.set(this);
64
		lastRevision = cdoRevision;
65
		
66
		if (DEBUG.isEnabled())
67
		{
68
			DEBUG.format("preTraverseFeature : {0}.{1}", cdoClass.getName(),  cdoFeature.getName());
69
		}
70
	
71
		// Do not handle these cases
72
		if (!cdoFeature.isReference() || cdoFeature.isContainment() || (cdoFeature.isMany() && index != 0))
73
		{
74
			lastTimeAccess = System.currentTimeMillis();
75
			return;
76
		}
77
		
78
		long currentTime = System.currentTimeMillis();
79
		
80
		long elapseTimeBeforeLastRequest = currentTime - lastTimeAccess;
81
		
82
		if (elapseTimeBeforeLastRequest > ELAPSE_TIME || lastFeatureRule == null)
83
		{
84
			CDOFeatureRule featureRule = getFeatureRule(cdoClass, cdoFeature);
85
			lastFeatureRule = featureRule;
86
		}
87
		
88
		CDOFetchFeatureStat stat = lastFeatureRule.getFeatureStat(cdoFeature);
89
		
90
		if (stat.getTimeUnusedBefore() != 0)
91
		{
92
			stat.setTimeUnsedBefore((stat.getTimeUnusedBefore() + elapseTimeBeforeLastRequest) / 2);
93
		}
94
		else
95
		{
96
			stat.setTimeUnsedBefore( elapseTimeBeforeLastRequest );
97
		}
98
		
99
		if (!stat.isValid() && stat.getTimeUnusedBefore()  < CDOFeatureAnalyzer.ELAPSE_TIME)
100
		{
101
			CDOFetchRule fetchRule = lastFeatureRule.addFeatureRule(cdoClass, cdoFeature);
102
			stat.setFetchRule( fetchRule );
103
		}
104
		else if (stat.isValid() && stat.getTimeUnusedBefore() > CDOFeatureAnalyzer.ELAPSE_TIME)
105
		{
106
			// Unregister rules
107
			lastFeatureRule.removeFeatureRule(cdoClass, cdoFeature);
108
			stat.setFetchRule( null );			
109
		}
110
		
111
		
112
		lastTimeAccess = currentTime;
113
		inUse=true;
114
	}
115
	
116
	
117
	
118
	/**
119
	 * 
120
	 */
121
	public void postTraverseFeature(CDORevision cdoRevision, CDOFeature cdoFeature, int index) 
122
	{
123
		if (DEBUG.isEnabled())
124
		{
125
			DEBUG.format("postTraverseFeature : {0}.{1}", cdoRevision.getCDOClass(),  cdoFeature.getName());
126
		}
127
		
128
		// TODO Auto-generated method stub
129
		lastTimeAccess = System.currentTimeMillis();
130
		inUse = false;
131
		threadLocal.set(null);
132
	}
133
	
134
	/**
135
	 * 
136
	 */
137
	public CDOID getContext()
138
	{
139
		return lastRevision.getID();
140
	}
141
	
142
	/**
143
	 * 
144
	 * @param cdoClass
145
	 * @param cdoFeature
146
	 * @return
147
	 */
148
	synchronized public CDOFeatureRule getFeatureRule(CDOClass cdoClass, CDOFeature cdoFeature) 
149
	{
150
		CDOFeatureRule featureRule = featureRulesMap.get(cdoFeature);
151
		
152
		if (featureRule == null)
153
		{
154
			featureRule = new CDOFeatureRule(cdoClass, cdoFeature);
155
			featureRulesMap.put(cdoFeature, featureRule);
156
		}
157
		
158
		return featureRule;
159
	}
160
	
161
	/**
162
	 * 
163
	 */
164
	public List<CDOFetchRule> getFetchRules(Collection<CDOID> id) 
165
	{
166
		// TODO Auto-generated method stub
167
		if (!inUse || this.lastFeatureRule == null)
168
			return null;
169
		
170
		ArrayList<CDOFetchRule> list = new ArrayList<CDOFetchRule>();
171
		Iterator<CDOFetchRule> itr = this.lastFeatureRule.iterator();
172
		while (itr.hasNext())
173
			list.add(itr.next());
174
		 
175
		return list;
176
177
	}
178
179
}
(-)src/org/eclipse/emf/cdo/internal/analyzer/CDOFetchRuleManager.java (+27 lines)
Added Link Here
1
package org.eclipse.emf.cdo.internal.analyzer;
2
3
import java.util.Collection;
4
import java.util.List;
5
6
import org.eclipse.emf.cdo.analyzer.IFetchRuleManager;
7
import org.eclipse.emf.cdo.protocol.CDOID;
8
9
/**
10
 * @author Simon McDuff 
11
 */
12
public class CDOFetchRuleManager implements IFetchRuleManager 
13
{
14
	
15
	public CDOID getContext() 
16
	{
17
		// TODO Auto-generated method stub
18
		return CDOFeatureAnalyzer.getCurrent().getContext();
19
	}
20
21
	public List<CDOFetchRule> getFetchRules(Collection<CDOID> id) 
22
	{
23
		// TODO Auto-generated method stub
24
		return CDOFeatureAnalyzer.getCurrent().getFetchRules(id);
25
	}
26
27
}
(-)src/org/eclipse/emf/cdo/internal/analyzer/CDOFetchFeatureStat.java (+55 lines)
Added Link Here
1
package org.eclipse.emf.cdo.internal.analyzer;
2
3
4
5
/**
6
 * @author Simon McDuff 
7
 */
8
public class CDOFetchFeatureStat 
9
{
10
11
	private CDOFetchRule fetchRule;
12
	private long timeBeforeUsed;
13
	private long latencyTime;
14
	
15
	public CDOFetchFeatureStat()
16
	{
17
		this.fetchRule = null; 
18
	}
19
20
	public long getTimeUnusedBefore() 
21
	{
22
		return timeBeforeUsed;
23
	}
24
25
	public void setTimeUnsedBefore(long timeUnsedBefore) 
26
	{
27
		this.timeBeforeUsed = timeUnsedBefore;
28
	}
29
30
	public long getLatencyTime() 
31
	{
32
		return latencyTime;
33
	}
34
35
	public void setLatencyTime(long timeToFetch) 
36
	{
37
		this.latencyTime = timeToFetch;
38
	}
39
40
	public CDOFetchRule getFetchRule() 
41
	{
42
		return fetchRule;
43
	}
44
	
45
	public boolean isValid()
46
	{
47
		return fetchRule != null;
48
	}
49
	public void setFetchRule(CDOFetchRule fetchRule) 
50
	{
51
		this.fetchRule = fetchRule;
52
	}
53
	
54
	
55
}
(-)src/org/eclipse/emf/cdo/internal/analyzer/CDOFetchRule.java (+87 lines)
Added Link Here
1
package org.eclipse.emf.cdo.internal.analyzer;
2
3
import java.io.IOException;
4
import java.util.ArrayList;
5
6
import org.eclipse.emf.cdo.internal.protocol.model.CDOClassImpl;
7
import org.eclipse.emf.cdo.internal.protocol.model.CDOClassRefImpl;
8
import org.eclipse.emf.cdo.internal.protocol.model.CDOFeatureImpl;
9
import org.eclipse.emf.cdo.protocol.model.CDOClass;
10
import org.eclipse.emf.cdo.protocol.model.CDOFeature;
11
import org.eclipse.emf.cdo.protocol.model.CDOPackageManager;
12
import org.eclipse.net4j.util.io.ExtendedDataInput;
13
import org.eclipse.net4j.util.io.ExtendedDataOutput;
14
15
/**
16
 * @author Simon McDuff 
17
 */
18
public class CDOFetchRule 
19
{
20
	private CDOClass cdoClass;
21
	private ArrayList<CDOFeature> cdoFeatures = new ArrayList<CDOFeature>();
22
	
23
	public CDOFetchRule(CDOClass cdoClass )
24
	{
25
		this.cdoClass = cdoClass;
26
	}
27
	public CDOFetchRule(ExtendedDataInput in, CDOPackageManager packageManager) throws IOException
28
	{
29
		CDOClassRefImpl classRef = new CDOClassRefImpl(in, null);
30
		cdoClass = classRef.resolve(packageManager);
31
		CDOFeature[] arrayOfFeature = cdoClass.getAllFeatures();
32
		int size = in.readInt();
33
		for (int i =0; i < size;i++)
34
		{
35
			int featureIndex = in.readInt();
36
			cdoFeatures.add(arrayOfFeature[featureIndex]);
37
		}
38
	}
39
	public void addFeature(CDOFeature cdoFeature)
40
	{
41
		cdoFeatures.add(cdoFeature);
42
	}
43
	/* (non-Javadoc)
44
	 * @see org.eclipse.emf.cdo.internal.analyzer.IFetchRule#removeFeature(org.eclipse.emf.cdo.protocol.model.CDOFeature)
45
	 */
46
	public void removeFeature(CDOFeature cdoFeature)
47
	{
48
		cdoFeatures.remove(cdoFeature);
49
		
50
	}
51
	/* (non-Javadoc)
52
	 * @see org.eclipse.emf.cdo.internal.analyzer.IFetchRule#isEmpty()
53
	 */
54
	public boolean isEmpty()
55
	{
56
		return cdoFeatures.isEmpty();
57
	}
58
	
59
	/**
60
	 * 
61
	 * @param out
62
	 * @throws IOException
63
	 */
64
	public void write(ExtendedDataOutput out) throws IOException
65
	{
66
	    ((CDOClassImpl)cdoClass).createClassRef().write(out, null);
67
		out.writeInt(cdoFeatures.size());
68
		for (CDOFeature cdofeature : cdoFeatures)
69
		{
70
			out.writeInt(((CDOFeatureImpl)cdofeature).getFeatureIndex());	
71
		}
72
		
73
	}
74
	/* (non-Javadoc)
75
	 * @see org.eclipse.emf.cdo.internal.analyzer.IFetchRule#getCdoFeatures()
76
	 */
77
	public ArrayList<CDOFeature> getCdoFeatures() 
78
	{
79
		return cdoFeatures;
80
	}
81
	/* (non-Javadoc)
82
	 * @see org.eclipse.emf.cdo.internal.analyzer.IFetchRule#getCdoClass()
83
	 */
84
	public CDOClass getCdoClass() {
85
		return cdoClass;
86
	}
87
}
(-)src/org/eclipse/emf/cdo/analyzer/IFeatureAnalyzer.java (+14 lines)
Added Link Here
1
package org.eclipse.emf.cdo.analyzer;
2
3
import org.eclipse.emf.cdo.protocol.model.CDOFeature;
4
import org.eclipse.emf.cdo.protocol.revision.CDORevision;
5
6
/**
7
 * @author Simon McDuff 
8
 */
9
public interface IFeatureAnalyzer 
10
{
11
	static IFeatureAnalyzer eNOOP = new NOOPFeatureAnalyzer();
12
	public void postTraverseFeature(CDORevision cdoRevision, CDOFeature cdoFeature, int index);
13
	public void preTraverseFeature(CDORevision cdoRevision, CDOFeature cdoFeature, int index);
14
}

Return to bug 202064