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/protocol/analyzer/IFetchRuleManager.java (-31 lines)
Removed Link Here
1
/***************************************************************************
2
 * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *    Simon McDuff - initial API and implementation
10
 *    Eike Stepper - maintenance
11
 **************************************************************************/
12
package org.eclipse.emf.cdo.protocol.analyzer;
13
14
import java.util.Collection;
15
import java.util.List;
16
17
import org.eclipse.emf.cdo.internal.protocol.analyzer.CDOFetchRule;
18
import org.eclipse.emf.cdo.internal.protocol.analyzer.NOOPFetchRuleManager;
19
import org.eclipse.emf.cdo.protocol.CDOID;
20
21
/**
22
 * @author Eike Stepper
23
 */
24
public interface IFetchRuleManager
25
{
26
  public static final IFetchRuleManager NOOP = new NOOPFetchRuleManager();
27
28
  public CDOID getContext();
29
30
  public List<CDOFetchRule> getFetchRules(Collection<CDOID> ids);
31
}
(-)src/org/eclipse/emf/cdo/protocol/analyzer/IFeatureAnalyzer.java (-28 lines)
Removed Link Here
1
/***************************************************************************
2
 * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *    Simon McDuff - initial API and implementation
10
 *    Eike Stepper - maintenance
11
 **************************************************************************/
12
package org.eclipse.emf.cdo.protocol.analyzer;
13
14
import org.eclipse.emf.cdo.internal.protocol.analyzer.NOOPFeatureAnalyzer;
15
import org.eclipse.emf.cdo.protocol.model.CDOFeature;
16
import org.eclipse.emf.cdo.protocol.revision.CDORevision;
17
18
/**
19
 * @author Eike Stepper
20
 */
21
public interface IFeatureAnalyzer
22
{
23
  public static final IFeatureAnalyzer NOOP = new NOOPFeatureAnalyzer();
24
25
  public void preTraverseFeature(CDORevision revision, CDOFeature feature, int index);
26
27
  public void postTraverseFeature(CDORevision revision, CDOFeature feature, int index);
28
}
(-)src/org/eclipse/emf/cdo/internal/protocol/analyzer/CDOFeatureRule.java (-115 lines)
Removed Link Here
1
/***************************************************************************
2
 * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *    Simon McDuff - initial API and implementation
10
 *    Eike Stepper - maintenance
11
 **************************************************************************/
12
package org.eclipse.emf.cdo.internal.protocol.analyzer;
13
14
import org.eclipse.emf.cdo.internal.protocol.bundle.OM;
15
import org.eclipse.emf.cdo.protocol.model.CDOClass;
16
import org.eclipse.emf.cdo.protocol.model.CDOFeature;
17
18
import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
19
20
import java.util.HashMap;
21
import java.util.Iterator;
22
import java.util.Map;
23
24
/**
25
 * @author Eike Stepper
26
 */
27
public class CDOFeatureRule
28
{
29
  private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, CDOFeatureRule.class);
30
31
  private CDOClass cdoClass;
32
33
  private CDOFeature cdoFeature;
34
35
  private Map<CDOFeature, CDOFetchFeatureStat> featureStats = new HashMap<CDOFeature, CDOFetchFeatureStat>();
36
37
  private Map<CDOClass, CDOFetchRule> fetchRules = new HashMap<CDOClass, CDOFetchRule>();
38
39
  public CDOFeatureRule(CDOClass cdoClass, CDOFeature cdoFeature)
40
  {
41
    this.cdoClass = cdoClass;
42
    this.cdoFeature = cdoFeature;
43
  }
44
45
  public CDOClass getCDOClass()
46
  {
47
    return cdoClass;
48
  }
49
50
  public CDOFeature getCDOFeature()
51
  {
52
    return cdoFeature;
53
  }
54
55
  public Iterator<CDOFetchRule> iterator()
56
  {
57
    return fetchRules.values().iterator();
58
  }
59
60
  public synchronized CDOFetchFeatureStat getFeatureStat(CDOFeature cdoFeature)
61
  {
62
    CDOFetchFeatureStat featureRule = featureStats.get(cdoFeature);
63
    if (featureRule == null)
64
    {
65
      featureRule = new CDOFetchFeatureStat();
66
      featureStats.put(cdoFeature, featureRule);
67
    }
68
69
    return featureRule;
70
  }
71
72
  public synchronized CDOFetchRule addFeatureRule(CDOClass cdoClass, CDOFeature cdoFeature)
73
  {
74
    if (TRACER.isEnabled())
75
    {
76
      TRACER.format("Adding new fetch rule : {0}.{1} from root {2}.{3}", cdoClass.getName(), cdoFeature.getName(),
77
          this.cdoClass.getName(), this.cdoFeature.getName());
78
    }
79
80
    CDOFetchRule fetchRule = getFetchRule(cdoClass);
81
    fetchRule.addFeature(cdoFeature);
82
    return fetchRule;
83
84
  }
85
86
  public synchronized CDOFetchRule removeFeatureRule(CDOClass cdoClass, CDOFeature cdoFeature)
87
  {
88
    if (TRACER.isEnabled())
89
    {
90
      TRACER.format("Adding new fetch rule : {0}.{1} from root {2}.{3}", cdoClass.getName(), cdoFeature.getName(),
91
          this.cdoClass.getName(), this.cdoFeature.getName());
92
    }
93
94
    CDOFetchRule fetchRule = getFetchRule(cdoClass);
95
    fetchRule.removeFeature(cdoFeature);
96
    if (fetchRule.isEmpty())
97
    {
98
      fetchRules.remove(cdoClass);
99
    }
100
101
    return fetchRule;
102
  }
103
104
  public synchronized CDOFetchRule getFetchRule(CDOClass cdoFeature)
105
  {
106
    CDOFetchRule featureRule = fetchRules.get(cdoFeature);
107
    if (featureRule == null)
108
    {
109
      featureRule = new CDOFetchRule(cdoFeature);
110
      fetchRules.put(cdoFeature, featureRule);
111
    }
112
113
    return featureRule;
114
  }
115
}
(-)src/org/eclipse/emf/cdo/internal/protocol/analyzer/CDOFetchRuleManager.java (-38 lines)
Removed Link Here
1
/***************************************************************************
2
 * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *    Simon McDuff - initial API and implementation
10
 *    Eike Stepper - maintenance
11
 **************************************************************************/
12
package org.eclipse.emf.cdo.internal.protocol.analyzer;
13
14
import java.util.Collection;
15
import java.util.List;
16
17
import org.eclipse.emf.cdo.protocol.CDOID;
18
import org.eclipse.emf.cdo.protocol.analyzer.IFetchRuleManager;
19
20
/**
21
 * @author Eike Stepper
22
 */
23
public class CDOFetchRuleManager implements IFetchRuleManager
24
{
25
  public CDOFetchRuleManager()
26
  {
27
  }
28
29
  public CDOID getContext()
30
  {
31
    return CDOFeatureAnalyzer.getCurrent().getContext();
32
  }
33
34
  public List<CDOFetchRule> getFetchRules(Collection<CDOID> ids)
35
  {
36
    return CDOFeatureAnalyzer.getCurrent().getFetchRules(ids);
37
  }
38
}
(-)src/org/eclipse/emf/cdo/internal/protocol/analyzer/NOOPFeatureAnalyzer.java (-34 lines)
Removed Link Here
1
/***************************************************************************
2
 * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *    Simon McDuff - initial API and implementation
10
 *    Eike Stepper - maintenance
11
 **************************************************************************/
12
package org.eclipse.emf.cdo.internal.protocol.analyzer;
13
14
import org.eclipse.emf.cdo.protocol.analyzer.IFeatureAnalyzer;
15
import org.eclipse.emf.cdo.protocol.model.CDOFeature;
16
import org.eclipse.emf.cdo.protocol.revision.CDORevision;
17
18
/**
19
 * @author Eike Stepper
20
 */
21
public class NOOPFeatureAnalyzer implements IFeatureAnalyzer
22
{
23
  public NOOPFeatureAnalyzer()
24
  {
25
  }
26
27
  public void preTraverseFeature(CDORevision cdoClass, CDOFeature feature, int index)
28
  {
29
  }
30
31
  public void postTraverseFeature(CDORevision cdoClass, CDOFeature feature, int index)
32
  {
33
  }
34
}
(-)src/org/eclipse/emf/cdo/internal/protocol/analyzer/NOOPFetchRuleManager.java (-41 lines)
Removed Link Here
1
/***************************************************************************
2
 * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *    Simon McDuff - initial API and implementation
10
 *    Eike Stepper - maintenance
11
 **************************************************************************/
12
package org.eclipse.emf.cdo.internal.protocol.analyzer;
13
14
import java.util.Collection;
15
import java.util.List;
16
17
import org.eclipse.emf.cdo.internal.protocol.CDOIDNull;
18
import org.eclipse.emf.cdo.protocol.CDOID;
19
import org.eclipse.emf.cdo.protocol.analyzer.IFetchRuleManager;
20
21
/**
22
 * @author Eike Stepper
23
 */
24
public class NOOPFetchRuleManager implements IFetchRuleManager
25
{
26
  public CDOID getContext()
27
  {
28
    return CDOIDNull.NULL;
29
  }
30
31
  public List<CDOFetchRule> getFetchRules(Collection<CDOID> ids)
32
  {
33
    return null;
34
  }
35
36
  @Deprecated
37
  public List<CDOFetchRule> getFetchRules(CDOID id)
38
  {
39
    return null;
40
  }
41
}
(-)src/org/eclipse/emf/cdo/internal/protocol/analyzer/CDOFetchFeatureStat.java (-63 lines)
Removed Link Here
1
/***************************************************************************
2
 * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *    Simon McDuff - initial API and implementation
10
 *    Eike Stepper - maintenance
11
 **************************************************************************/
12
package org.eclipse.emf.cdo.internal.protocol.analyzer;
13
14
/**
15
 * @author Eike Stepper
16
 */
17
public class CDOFetchFeatureStat
18
{
19
  private CDOFetchRule fetchRule;
20
21
  private long timeBeforeUsed;
22
23
  private long latencyTime;
24
25
  public CDOFetchFeatureStat()
26
  {
27
  }
28
29
  public boolean isValid()
30
  {
31
    return fetchRule != null;
32
  }
33
34
  public long getTimeBeforeUsed()
35
  {
36
    return timeBeforeUsed;
37
  }
38
39
  public void setTimeBeforeUsed(long timeBeforeUsed)
40
  {
41
    this.timeBeforeUsed = timeBeforeUsed;
42
  }
43
44
  public long getLatencyTime()
45
  {
46
    return latencyTime;
47
  }
48
49
  public void setLatencyTime(long latencyTime)
50
  {
51
    this.latencyTime = latencyTime;
52
  }
53
54
  public CDOFetchRule getFetchRule()
55
  {
56
    return fetchRule;
57
  }
58
59
  public void setFetchRule(CDOFetchRule fetchRule)
60
  {
61
    this.fetchRule = fetchRule;
62
  }
63
}
(-)src/org/eclipse/emf/cdo/internal/protocol/analyzer/CDOFeatureAnalyzer.java (-163 lines)
Removed Link Here
1
/***************************************************************************
2
 * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *    Simon McDuff - initial API and implementation
10
 *    Eike Stepper - maintenance
11
 **************************************************************************/
12
package org.eclipse.emf.cdo.internal.protocol.analyzer;
13
14
import org.eclipse.emf.cdo.internal.protocol.bundle.OM;
15
import org.eclipse.emf.cdo.protocol.CDOID;
16
import org.eclipse.emf.cdo.protocol.analyzer.IFeatureAnalyzer;
17
import org.eclipse.emf.cdo.protocol.analyzer.IFetchRuleManager;
18
import org.eclipse.emf.cdo.protocol.model.CDOClass;
19
import org.eclipse.emf.cdo.protocol.model.CDOFeature;
20
import org.eclipse.emf.cdo.protocol.revision.CDORevision;
21
22
import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
23
24
import java.util.ArrayList;
25
import java.util.Collection;
26
import java.util.HashMap;
27
import java.util.Iterator;
28
import java.util.List;
29
import java.util.Map;
30
31
/**
32
 * @author Eike Stepper
33
 */
34
public class CDOFeatureAnalyzer implements IFeatureAnalyzer, IFetchRuleManager
35
{
36
  private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, CDOFeatureAnalyzer.class);
37
38
  private static final long ELAPSE_TIME = 400L;
39
40
  private static final ThreadLocal<CDOFeatureAnalyzer> threadLocal = new ThreadLocal<CDOFeatureAnalyzer>();
41
42
  private Map<CDOFeature, CDOFeatureRule> featureRules = new HashMap<CDOFeature, CDOFeatureRule>();
43
44
  private CDOFeatureRule lastFeatureRule;
45
46
  private long lastAccessTime;
47
48
  private boolean inUse;
49
50
  private CDORevision lastRevision;
51
52
  public CDOFeatureAnalyzer()
53
  {
54
  }
55
56
  public CDOFeatureRule getCurrentFeatureRule()
57
  {
58
    return lastFeatureRule;
59
  }
60
61
  public static CDOFeatureAnalyzer getCurrent()
62
  {
63
    return threadLocal.get();
64
  }
65
66
  public void preTraverseFeature(CDORevision revision, CDOFeature feature, int index)
67
  {
68
    CDOClass cdoClass = revision.getCDOClass();
69
    threadLocal.set(this);
70
    lastRevision = revision;
71
72
    if (TRACER.isEnabled())
73
    {
74
      TRACER.format("preTraverseFeature : {0}.{1}", cdoClass.getName(), feature.getName());
75
    }
76
77
    // Do not handle these cases
78
    long currentTime = System.currentTimeMillis();
79
    if (!feature.isReference() || feature.isContainment() || feature.isMany() && index != 0)
80
    {
81
      lastAccessTime = currentTime;
82
      return;
83
    }
84
85
    long elapseTimeBeforeLastRequest = currentTime - lastAccessTime;
86
    if (elapseTimeBeforeLastRequest > ELAPSE_TIME || lastFeatureRule == null)
87
    {
88
      CDOFeatureRule featureRule = getFeatureRule(cdoClass, feature);
89
      lastFeatureRule = featureRule;
90
    }
91
92
    CDOFetchFeatureStat stat = lastFeatureRule.getFeatureStat(feature);
93
    if (stat.getTimeBeforeUsed() != 0)
94
    {
95
      stat.setTimeBeforeUsed((stat.getTimeBeforeUsed() + elapseTimeBeforeLastRequest) / 2);
96
    }
97
    else
98
    {
99
      stat.setTimeBeforeUsed(elapseTimeBeforeLastRequest);
100
    }
101
102
    if (!stat.isValid() && stat.getTimeBeforeUsed() < CDOFeatureAnalyzer.ELAPSE_TIME)
103
    {
104
      CDOFetchRule fetchRule = lastFeatureRule.addFeatureRule(cdoClass, feature);
105
      stat.setFetchRule(fetchRule);
106
    }
107
    else if (stat.isValid() && stat.getTimeBeforeUsed() > CDOFeatureAnalyzer.ELAPSE_TIME)
108
    {
109
      // Unregister rules
110
      lastFeatureRule.removeFeatureRule(cdoClass, feature);
111
      stat.setFetchRule(null);
112
    }
113
114
    lastAccessTime = currentTime;
115
    inUse = true;
116
  }
117
118
  public void postTraverseFeature(CDORevision revision, CDOFeature feature, int index)
119
  {
120
    if (TRACER.isEnabled())
121
    {
122
      TRACER.format("postTraverseFeature : {0}.{1}", revision.getCDOClass(), feature.getName());
123
    }
124
125
    lastAccessTime = System.currentTimeMillis();
126
    inUse = false;
127
    threadLocal.set(null);
128
  }
129
130
  public CDOID getContext()
131
  {
132
    return lastRevision.getID();
133
  }
134
135
  public synchronized CDOFeatureRule getFeatureRule(CDOClass cdoClass, CDOFeature cdoFeature)
136
  {
137
    CDOFeatureRule featureRule = featureRules.get(cdoFeature);
138
    if (featureRule == null)
139
    {
140
      featureRule = new CDOFeatureRule(cdoClass, cdoFeature);
141
      featureRules.put(cdoFeature, featureRule);
142
    }
143
144
    return featureRule;
145
  }
146
147
  public List<CDOFetchRule> getFetchRules(Collection<CDOID> ids)
148
  {
149
    if (!inUse || lastFeatureRule == null)
150
    {
151
      return null;
152
    }
153
154
    List<CDOFetchRule> list = new ArrayList<CDOFetchRule>();
155
    for (Iterator<CDOFetchRule> it = lastFeatureRule.iterator(); it.hasNext();)
156
    {
157
      CDOFetchRule fetchRule = it.next();
158
      list.add(fetchRule);
159
    }
160
161
    return list;
162
  }
163
}
(-)META-INF/MANIFEST.MF (-1 lines)
Lines 15-21 Link Here
15
 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",
16
 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.protocol;version="0.8.0",
17
 org.eclipse.emf.cdo.protocol;version="0.8.0",
18
 org.eclipse.emf.cdo.protocol.analyzer;version="0.8.0",
19
 org.eclipse.emf.cdo.protocol.model;version="0.8.0",
18
 org.eclipse.emf.cdo.protocol.model;version="0.8.0",
20
 org.eclipse.emf.cdo.protocol.model.core;version="0.8.0",
19
 org.eclipse.emf.cdo.protocol.model.core;version="0.8.0",
21
 org.eclipse.emf.cdo.protocol.model.resource;version="0.8.0",
20
 org.eclipse.emf.cdo.protocol.model.resource;version="0.8.0",
(-)src/org/eclipse/emf/cdo/internal/server/protocol/LoadRevisionIndication.java (-23 / +55 lines)
Lines 28-35 Link Here
28
import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
28
import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
29
29
30
import java.io.IOException;
30
import java.io.IOException;
31
import java.util.ArrayList;
31
import java.util.HashMap;
32
import java.util.HashMap;
32
import java.util.HashSet;
33
import java.util.HashSet;
34
import java.util.List;
33
import java.util.Map;
35
import java.util.Map;
34
import java.util.Set;
36
import java.util.Set;
35
37
Lines 79-117 Link Here
79
    if (fetchSize > 0)
81
    if (fetchSize > 0)
80
    {
82
    {
81
      contextID = CDOIDImpl.read(in);
83
      contextID = CDOIDImpl.read(in);
84
      
85
      if (PROTOCOL.isEnabled()) PROTOCOL.format("Reading fetch rules for context {0}", contextID);      
86
      
82
      for (int i = 0; i < fetchSize; i++)
87
      for (int i = 0; i < fetchSize; i++)
83
      {
88
      {
84
        CDOFetchRule fetchRule = new CDOFetchRule(in, getPackageManager());
89
        CDOFetchRule fetchRule = new CDOFetchRule(in, getPackageManager());
85
        fetchRules.put(fetchRule.getCDOClass(), fetchRule);
90
        fetchRules.put(fetchRule.getCDOClass(), fetchRule);
91
86
      }
92
      }
93
87
    }
94
    }
88
  }
95
  }
89
96
90
  @Override
97
  @Override
91
  protected void responding(ExtendedDataOutputStream out) throws IOException
98
  protected void responding(ExtendedDataOutputStream out) throws IOException
92
  {
99
  {
100
	  
93
    Session session = getSession();
101
    Session session = getSession();
94
    Map<CDOID, CDORevisionImpl> containedRevisions = new HashMap<CDOID, CDORevisionImpl>(0);
102
    
95
103
    List<CDORevisionImpl> additionalRevisions = new ArrayList<CDORevisionImpl>();
104
    
105
    HashSet<CDOID> revisions = new HashSet<CDOID>();
106
    
96
    if (PROTOCOL.isEnabled()) PROTOCOL.format("Writing {0} revisions", ids.length);
107
    if (PROTOCOL.isEnabled()) PROTOCOL.format("Writing {0} revisions", ids.length);
97
    for (CDOID id : ids)
108
    
109
    
110
    // Need to fetch the rule first.
111
    if (!contextID.isNull() && fetchRules.size() > 0)
98
    {
112
    {
99
      CDORevisionImpl revision = getRevision(id);
113
      if (PROTOCOL.isEnabled()) PROTOCOL.format("Collecting more objects based on rules");
100
      revision.write(out, session, referenceChunk);
114
      //System.out.println("Collecting more objects based on rules");
101
      session.collectContainedRevisions(revision, referenceChunk, containedRevisions);
115
      // Should be more benefits to have referenceChunk more than 1.
116
      // Hope the consumer thought about that !!! 
117
      CDORevisionImpl revisionContext = getRevision(contextID);
118
      
119
      collectRevisionsByRule(revisionContext, referenceChunk, revisions, additionalRevisions, new HashSet<CDOFetchRule>());
102
    }
120
    }
103
121
104
    if (!contextID.isNull() && fetchRules.size() > 0)
122
    
123
    
124
    for (CDOID id : ids)
105
    {
125
    {
106
      // TODO What is this good for? Why 1000?
126
      CDORevisionImpl revision = getRevision(id);
107
      int newReferenceChunk = Math.max(referenceChunk, 1000);
127
      revision.write(out, session, referenceChunk);
108
      CDORevisionImpl revisionContext = getRevision(contextID);
128
      revisions.add( revision.getID() );
109
      collectRevisionsByRule(revisionContext, newReferenceChunk, containedRevisions, new HashSet<CDOFetchRule>());
129
      session.collectContainedRevisions(revision, referenceChunk, revisions, additionalRevisions);
110
    }
130
    }
111
131
112
    out.writeInt(containedRevisions.size());
132
    
113
    if (PROTOCOL.isEnabled()) PROTOCOL.format("Writing {0} additional revisions", containedRevisions.size());
133
    out.writeInt(additionalRevisions.size());
114
    for (CDORevisionImpl revision : containedRevisions.values())
134
    
135
    if (PROTOCOL.isEnabled()) PROTOCOL.format("Writing {0} additional revisions", additionalRevisions.size());
136
    //System.out.println("ADDITIONAL REVISION" + additionalRevisions.size());
137
    for (CDORevisionImpl revision : additionalRevisions)
115
    {
138
    {
116
      revision.write(out, session, referenceChunk);
139
      revision.write(out, session, referenceChunk);
117
    }
140
    }
Lines 123-129 Link Here
123
  }
146
  }
124
147
125
  private void collectRevisionsByRule(CDORevisionImpl revision, int referenceChunk,
148
  private void collectRevisionsByRule(CDORevisionImpl revision, int referenceChunk,
126
      Map<CDOID, CDORevisionImpl> containedRevisions, Set<CDOFetchRule> workingFetchRules)
149
		  Set<CDOID> revisions, List<CDORevisionImpl> additionalRevisions, 
150
		  Set<CDOFetchRule> workingFetchRules)
127
  {
151
  {
128
    CDOFetchRule fetchRule = fetchRules.get(revision.getCDOClass());
152
    CDOFetchRule fetchRule = fetchRules.get(revision.getCDOClass());
129
    if (fetchRule == null || workingFetchRules.contains(fetchRule))
153
    if (fetchRule == null || workingFetchRules.contains(fetchRule))
Lines 132-137 Link Here
132
    }
156
    }
133
157
134
    workingFetchRules.add(fetchRule);
158
    workingFetchRules.add(fetchRule);
159
    
135
    RevisionManager revisionManager = getSessionManager().getRepository().getRevisionManager();
160
    RevisionManager revisionManager = getSessionManager().getRepository().getRevisionManager();
136
    for (CDOFeature feature : fetchRule.getFeatures())
161
    for (CDOFeature feature : fetchRule.getFeatures())
137
    {
162
    {
Lines 145-155 Link Here
145
          if (value instanceof CDOID)
170
          if (value instanceof CDOID)
146
          {
171
          {
147
            CDOID id = (CDOID)value;
172
            CDOID id = (CDOID)value;
148
            // TODO Missing here? if (!id.isNull() &&
173
            if (!id.isNull() && !revisions.contains(id))
149
            // !containedRevisions.containsKey(id))
174
            {
150
            CDORevisionImpl containedRevision = revisionManager.getRevision(id, referenceChunk);
175
            	CDORevisionImpl containedRevision = revisionManager.getRevision(id, referenceChunk);
151
            containedRevisions.put(containedRevision.getID(), containedRevision);
176
            	
152
            collectRevisionsByRule(containedRevision, referenceChunk, containedRevisions, workingFetchRules);
177
            	revisions.add(containedRevision.getID());
178
            	additionalRevisions.add(containedRevision);
179
            	
180
            	collectRevisionsByRule(containedRevision, referenceChunk, revisions, additionalRevisions, workingFetchRules);
181
            }
153
          }
182
          }
154
        }
183
        }
155
      }
184
      }
Lines 159-169 Link Here
159
        if (value instanceof CDOID)
188
        if (value instanceof CDOID)
160
        {
189
        {
161
          CDOID id = (CDOID)value;
190
          CDOID id = (CDOID)value;
162
          if (!id.isNull() && !containedRevisions.containsKey(id))
191
          if (!id.isNull() && !revisions.contains(id))
163
          {
192
          {
164
            CDORevisionImpl containedRevision = revisionManager.getRevision(id, referenceChunk);
193
            CDORevisionImpl containedRevision = revisionManager.getRevision(id, referenceChunk);
165
            containedRevisions.put(containedRevision.getID(), containedRevision);
194
        	
166
            collectRevisionsByRule(containedRevision, referenceChunk, containedRevisions, workingFetchRules);
195
            revisions.add(containedRevision.getID());
196
        	additionalRevisions.add(containedRevision);
197
        	
198
        	collectRevisionsByRule(containedRevision, referenceChunk, revisions, additionalRevisions, workingFetchRules);
167
          }
199
          }
168
        }
200
        }
169
      }
201
      }
(-)src/org/eclipse/emf/cdo/internal/server/Session.java (-9 / +10 lines)
Lines 34-39 Link Here
34
34
35
import java.text.MessageFormat;
35
import java.text.MessageFormat;
36
import java.util.HashSet;
36
import java.util.HashSet;
37
import java.util.List;
37
import java.util.Map;
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;
Lines 170-193 Link Here
170
    {
171
    {
171
      return id;
172
      return id;
172
    }
173
    }
173
174
    
174
    if (knownObjects.contains(id))
175
    if (knownObjects.contains(id))
175
    {
176
    {
176
      // TODO On client-side add a check if the id is really known!
177
      // TODO On client-side add a check if the id is really known!
177
      return id;
178
      return id;
178
    }
179
    }
179
180
    
180
    knownObjects.add(id);
181
    knownObjects.add(id);
181
    Repository repository = sessionManager.getRepository();
182
    Repository repository = sessionManager.getRepository();
182
    CDOClassRef type = repository.getTypeManager().getObjectType(StoreUtil.getReader(), id);
183
    CDOClassRef type = repository.getTypeManager().getObjectType(StoreUtil.getReader(), id);
183
    return CDOIDImpl.create(id.getValue(), type);
184
    return CDOIDImpl.create(id.getValue(), type);
185
    
184
  }
186
  }
185
187
186
  /**
188
  /**
187
   * TODO I can't see how recursion is controlled/limited
189
   * TODO I can't see how recursion is controlled/limited
188
   */
190
   */
189
  public void collectContainedRevisions(CDORevisionImpl revision, int referenceChunk,
191
  public void collectContainedRevisions(CDORevisionImpl revision, int referenceChunk,
190
      Map<CDOID, CDORevisionImpl> containedRevisions)
192
      Set<CDOID> revisions, List<CDORevisionImpl> additionalRevisions)
191
  {
193
  {
192
    RevisionManager revisionManager = getSessionManager().getRepository().getRevisionManager();
194
    RevisionManager revisionManager = getSessionManager().getRepository().getRevisionManager();
193
    CDOClassImpl cdoClass = revision.getCDOClass();
195
    CDOClassImpl cdoClass = revision.getCDOClass();
Lines 201-214 Link Here
201
        if (value instanceof CDOID)
203
        if (value instanceof CDOID)
202
        {
204
        {
203
          CDOID id = (CDOID)value;
205
          CDOID id = (CDOID)value;
204
          if (!id.isNull())
206
          if (!id.isNull() && !revisions.contains(id))
205
          {
207
          {
206
            if (containedRevisions.get(id) == null)
207
            {
208
              CDORevisionImpl containedRevision = revisionManager.getRevision(id, referenceChunk);
208
              CDORevisionImpl containedRevision = revisionManager.getRevision(id, referenceChunk);
209
              containedRevisions.put(id, containedRevision);
209
              revisions.add(id);
210
              collectContainedRevisions(containedRevision, referenceChunk, containedRevisions);
210
              additionalRevisions.add(containedRevision);
211
            }
211
              
212
              collectContainedRevisions(containedRevision, referenceChunk, revisions, additionalRevisions);
212
          }
213
          }
213
        }
214
        }
214
      }
215
      }
(-)src/org/eclipse/emf/internal/cdo/CDOViewImpl.java (-17 / +15 lines)
Lines 13-22 Link Here
13
 **************************************************************************/
13
 **************************************************************************/
14
package org.eclipse.emf.internal.cdo;
14
package org.eclipse.emf.internal.cdo;
15
15
16
import java.text.MessageFormat;
17
import java.util.ArrayList;
18
import java.util.HashMap;
19
import java.util.List;
20
import java.util.Map;
21
import java.util.Set;
22
16
import org.eclipse.emf.cdo.CDOState;
23
import org.eclipse.emf.cdo.CDOState;
17
import org.eclipse.emf.cdo.CDOView;
24
import org.eclipse.emf.cdo.CDOView;
18
import org.eclipse.emf.cdo.CDOViewEvent;
25
import org.eclipse.emf.cdo.CDOViewEvent;
19
import org.eclipse.emf.cdo.CDOViewResourcesEvent;
26
import org.eclipse.emf.cdo.CDOViewResourcesEvent;
27
import org.eclipse.emf.cdo.analyzer.CDOFeatureAnalyzer;
20
import org.eclipse.emf.cdo.eresource.CDOResource;
28
import org.eclipse.emf.cdo.eresource.CDOResource;
21
import org.eclipse.emf.cdo.eresource.EresourceFactory;
29
import org.eclipse.emf.cdo.eresource.EresourceFactory;
22
import org.eclipse.emf.cdo.eresource.impl.CDOResourceImpl;
30
import org.eclipse.emf.cdo.eresource.impl.CDOResourceImpl;
Lines 25-42 Link Here
25
import org.eclipse.emf.cdo.internal.protocol.revision.CDORevisionImpl;
33
import org.eclipse.emf.cdo.internal.protocol.revision.CDORevisionImpl;
26
import org.eclipse.emf.cdo.protocol.CDOID;
34
import org.eclipse.emf.cdo.protocol.CDOID;
27
import org.eclipse.emf.cdo.protocol.CDOIDTyped;
35
import org.eclipse.emf.cdo.protocol.CDOIDTyped;
28
import org.eclipse.emf.cdo.protocol.analyzer.IFeatureAnalyzer;
29
import org.eclipse.emf.cdo.protocol.model.CDOClass;
36
import org.eclipse.emf.cdo.protocol.model.CDOClass;
30
import org.eclipse.emf.cdo.protocol.model.CDOClassRef;
37
import org.eclipse.emf.cdo.protocol.model.CDOClassRef;
31
import org.eclipse.emf.cdo.protocol.revision.CDORevisionResolver;
38
import org.eclipse.emf.cdo.protocol.revision.CDORevisionResolver;
32
import org.eclipse.emf.cdo.protocol.util.TransportException;
39
import org.eclipse.emf.cdo.protocol.util.TransportException;
33
import org.eclipse.emf.cdo.util.CDOUtil;
40
import org.eclipse.emf.cdo.util.CDOUtil;
34
import org.eclipse.emf.cdo.util.ReadOnlyException;
41
import org.eclipse.emf.cdo.util.ReadOnlyException;
35
36
import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
37
import org.eclipse.net4j.signal.IFailOverStrategy;
38
import org.eclipse.net4j.util.ImplementationError;
39
40
import org.eclipse.emf.common.notify.Adapter;
42
import org.eclipse.emf.common.notify.Adapter;
41
import org.eclipse.emf.common.notify.Notification;
43
import org.eclipse.emf.common.notify.Notification;
42
import org.eclipse.emf.common.notify.Notifier;
44
import org.eclipse.emf.common.notify.Notifier;
Lines 52-64 Link Here
52
import org.eclipse.emf.internal.cdo.protocol.ResourcePathRequest;
54
import org.eclipse.emf.internal.cdo.protocol.ResourcePathRequest;
53
import org.eclipse.emf.internal.cdo.util.FSMUtil;
55
import org.eclipse.emf.internal.cdo.util.FSMUtil;
54
import org.eclipse.emf.internal.cdo.util.ModelUtil;
56
import org.eclipse.emf.internal.cdo.util.ModelUtil;
55
57
import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
56
import java.text.MessageFormat;
58
import org.eclipse.net4j.signal.IFailOverStrategy;
57
import java.util.ArrayList;
59
import org.eclipse.net4j.util.ImplementationError;
58
import java.util.HashMap;
59
import java.util.List;
60
import java.util.Map;
61
import java.util.Set;
62
60
63
/**
61
/**
64
 * @author Eike Stepper
62
 * @author Eike Stepper
Lines 78-84 Link Here
78
76
79
  private int loadRevisionCollectionChunkSize = 1;
77
  private int loadRevisionCollectionChunkSize = 1;
80
78
81
  private IFeatureAnalyzer featureAnalyzer = IFeatureAnalyzer.NOOP;
79
  private CDOFeatureAnalyzer featureAnalyzer = CDOFeatureAnalyzer.NOOP;
82
80
83
  private Map<CDOID, InternalCDOObject> objects = new HashMap<CDOID, InternalCDOObject>();
81
  private Map<CDOID, InternalCDOObject> objects = new HashMap<CDOID, InternalCDOObject>();
84
82
Lines 144-157 Link Here
144
    this.loadRevisionCollectionChunkSize = loadRevisionCollectionChunkSize;
142
    this.loadRevisionCollectionChunkSize = loadRevisionCollectionChunkSize;
145
  }
143
  }
146
144
147
  public IFeatureAnalyzer getFeatureAnalyzer()
145
  public CDOFeatureAnalyzer getFeatureAnalyzer()
148
  {
146
  {
149
    return featureAnalyzer;
147
    return featureAnalyzer;
150
  }
148
  }
151
149
152
  public void setFeatureAnalyzer(IFeatureAnalyzer featureAnalyzer)
150
  public void setFeatureAnalyzer(CDOFeatureAnalyzer featureAnalyzer)
153
  {
151
  {
154
    this.featureAnalyzer = featureAnalyzer == null ? IFeatureAnalyzer.NOOP : featureAnalyzer;
152
    this.featureAnalyzer = featureAnalyzer == null ? CDOFeatureAnalyzer.NOOP : featureAnalyzer;
155
  }
153
  }
156
154
157
  public CDOTransactionImpl toTransaction()
155
  public CDOTransactionImpl toTransaction()
(-)src/org/eclipse/emf/internal/cdo/CDOStore.java (-11 / +9 lines)
Lines 10-24 Link Here
10
 **************************************************************************/
10
 **************************************************************************/
11
package org.eclipse.emf.internal.cdo;
11
package org.eclipse.emf.internal.cdo;
12
12
13
import java.text.MessageFormat;
14
import java.util.HashSet;
15
import java.util.Set;
16
13
import org.eclipse.emf.cdo.internal.protocol.model.CDOFeatureImpl;
17
import org.eclipse.emf.cdo.internal.protocol.model.CDOFeatureImpl;
14
import org.eclipse.emf.cdo.internal.protocol.revision.CDORevisionImpl;
18
import org.eclipse.emf.cdo.internal.protocol.revision.CDORevisionImpl;
15
import org.eclipse.emf.cdo.internal.protocol.revision.CDORevisionImpl.MoveableList;
19
import org.eclipse.emf.cdo.internal.protocol.revision.CDORevisionImpl.MoveableList;
16
import org.eclipse.emf.cdo.protocol.CDOID;
20
import org.eclipse.emf.cdo.protocol.CDOID;
17
import org.eclipse.emf.cdo.protocol.model.CDOFeature;
21
import org.eclipse.emf.cdo.protocol.model.CDOFeature;
18
import org.eclipse.emf.cdo.protocol.revision.CDOReferenceProxy;
22
import org.eclipse.emf.cdo.protocol.revision.CDOReferenceProxy;
19
20
import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
21
22
import org.eclipse.emf.ecore.EClass;
23
import org.eclipse.emf.ecore.EClass;
23
import org.eclipse.emf.ecore.EObject;
24
import org.eclipse.emf.ecore.EObject;
24
import org.eclipse.emf.ecore.EStructuralFeature;
25
import org.eclipse.emf.ecore.EStructuralFeature;
Lines 27-36 Link Here
27
import org.eclipse.emf.internal.cdo.bundle.OM;
28
import org.eclipse.emf.internal.cdo.bundle.OM;
28
import org.eclipse.emf.internal.cdo.util.FSMUtil;
29
import org.eclipse.emf.internal.cdo.util.FSMUtil;
29
import org.eclipse.emf.internal.cdo.util.ModelUtil;
30
import org.eclipse.emf.internal.cdo.util.ModelUtil;
30
31
import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
31
import java.text.MessageFormat;
32
import java.util.HashSet;
33
import java.util.Set;
34
32
35
/**
33
/**
36
 * @author Eike Stepper
34
 * @author Eike Stepper
Lines 106-112 Link Here
106
      TRACER.format("get({0}, {1}, {2})", cdoObject, cdoFeature, index);
104
      TRACER.format("get({0}, {1}, {2})", cdoObject, cdoFeature, index);
107
    }
105
    }
108
106
109
    view.getFeatureAnalyzer().preTraverseFeature(cdoObject.cdoRevision(), cdoFeature, index);
107
    view.getFeatureAnalyzer().preTraverseFeature(cdoObject, cdoFeature, index);
110
    CDORevisionImpl revision = getRevisionForReading(cdoObject);
108
    CDORevisionImpl revision = getRevisionForReading(cdoObject);
111
    Object value = get(revision, cdoFeature, index);
109
    Object value = get(revision, cdoFeature, index);
112
    if (cdoFeature.isReference())
110
    if (cdoFeature.isReference())
Lines 116-126 Link Here
116
        CDOID id = (CDOID)value;
114
        CDOID id = (CDOID)value;
117
        loadAhead(revision, cdoFeature, id, index);
115
        loadAhead(revision, cdoFeature, id, index);
118
      }
116
      }
119
117
      
120
      value = view.convertIDToObject(value);
118
      value = view.convertIDToObject(value);
121
    }
119
    }
122
120
    
123
    view.getFeatureAnalyzer().postTraverseFeature(cdoObject.cdoRevision(), cdoFeature, index);
121
    view.getFeatureAnalyzer().postTraverseFeature(cdoObject, cdoFeature, index, value);
124
    return value;
122
    return value;
125
  }
123
  }
126
124
(-)src/org/eclipse/emf/internal/cdo/CDORevisionManagerImpl.java (-4 / +4 lines)
Lines 15-21 Link Here
15
import org.eclipse.emf.cdo.internal.protocol.revision.CDORevisionResolverImpl;
15
import org.eclipse.emf.cdo.internal.protocol.revision.CDORevisionResolverImpl;
16
import org.eclipse.emf.cdo.internal.protocol.revision.CDORevisionImpl.MoveableList;
16
import org.eclipse.emf.cdo.internal.protocol.revision.CDORevisionImpl.MoveableList;
17
import org.eclipse.emf.cdo.protocol.CDOID;
17
import org.eclipse.emf.cdo.protocol.CDOID;
18
import org.eclipse.emf.cdo.protocol.analyzer.IFetchRuleManager;
18
import org.eclipse.emf.cdo.analyzer.CDOFetchRuleManager;
19
import org.eclipse.emf.cdo.protocol.model.CDOFeature;
19
import org.eclipse.emf.cdo.protocol.model.CDOFeature;
20
import org.eclipse.emf.cdo.protocol.revision.CDOReferenceProxy;
20
import org.eclipse.emf.cdo.protocol.revision.CDOReferenceProxy;
21
import org.eclipse.emf.cdo.protocol.util.TransportException;
21
import org.eclipse.emf.cdo.protocol.util.TransportException;
Lines 39-45 Link Here
39
{
39
{
40
  private CDOSessionImpl session;
40
  private CDOSessionImpl session;
41
41
42
  private IFetchRuleManager ruleManager = IFetchRuleManager.NOOP;
42
  private CDOFetchRuleManager ruleManager = CDOFetchRuleManager.NOOP;
43
43
44
  public CDORevisionManagerImpl(CDOSessionImpl session)
44
  public CDORevisionManagerImpl(CDOSessionImpl session)
45
  {
45
  {
Lines 251-262 Link Here
251
    }
251
    }
252
  }
252
  }
253
253
254
  public IFetchRuleManager getRuleManager()
254
  public CDOFetchRuleManager getRuleManager()
255
  {
255
  {
256
    return ruleManager;
256
    return ruleManager;
257
  }
257
  }
258
258
259
  public void setRuleManager(IFetchRuleManager ruleManager)
259
  public void setRuleManager(CDOFetchRuleManager ruleManager)
260
  {
260
  {
261
    this.ruleManager = ruleManager;
261
    this.ruleManager = ruleManager;
262
  }
262
  }
(-)src/org/eclipse/emf/internal/cdo/protocol/LoadRevisionRequest.java (-22 / +18 lines)
Lines 10-37 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.analyzer.CDOFetchRuleManager;
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.analyzer.CDOFetchRule;
21
import org.eclipse.emf.cdo.internal.protocol.analyzer.CDOFetchRule;
15
import org.eclipse.emf.cdo.internal.protocol.revision.CDORevisionImpl;
22
import org.eclipse.emf.cdo.internal.protocol.revision.CDORevisionImpl;
16
import org.eclipse.emf.cdo.protocol.CDOID;
23
import org.eclipse.emf.cdo.protocol.CDOID;
17
import org.eclipse.emf.cdo.protocol.CDOProtocolConstants;
24
import org.eclipse.emf.cdo.protocol.CDOProtocolConstants;
18
import org.eclipse.emf.cdo.protocol.analyzer.IFetchRuleManager;
19
20
import org.eclipse.net4j.IChannel;
21
import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
22
import org.eclipse.net4j.util.io.ExtendedDataInputStream;
23
import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
24
25
import org.eclipse.emf.internal.cdo.CDORevisionManagerImpl;
25
import org.eclipse.emf.internal.cdo.CDORevisionManagerImpl;
26
import org.eclipse.emf.internal.cdo.CDOSessionImpl;
26
import org.eclipse.emf.internal.cdo.CDOSessionImpl;
27
import org.eclipse.emf.internal.cdo.CDOSessionPackageManager;
27
import org.eclipse.emf.internal.cdo.CDOSessionPackageManager;
28
import org.eclipse.emf.internal.cdo.bundle.OM;
28
import org.eclipse.emf.internal.cdo.bundle.OM;
29
29
import org.eclipse.net4j.IChannel;
30
import java.io.IOException;
30
import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
31
import java.util.ArrayList;
31
import org.eclipse.net4j.util.io.ExtendedDataInputStream;
32
import java.util.Collection;
32
import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
33
import java.util.Collections;
34
import java.util.List;
35
33
36
/**
34
/**
37
 * @author Eike Stepper
35
 * @author Eike Stepper
Lines 77-100 Link Here
77
      CDOIDImpl.write(out, id);
75
      CDOIDImpl.write(out, id);
78
    }
76
    }
79
77
80
    IFetchRuleManager ruleManager = getSession().getRevisionManager().getRuleManager();
78
    CDOFetchRuleManager ruleManager = getSession().getRevisionManager().getRuleManager();
81
    List<CDOFetchRule> fetchRules = ruleManager.getFetchRules(ids);
79
    List<CDOFetchRule> fetchRules = ruleManager.getFetchRules(ids);
82
    if (fetchRules == null || fetchRules.size() == 0)
80
    if (fetchRules == null || fetchRules.size() <= 0)
83
    {
81
    {
84
      out.writeInt(0);
82
      out.writeInt(0);
85
    }
83
    }
86
    else
84
    else
87
    {
85
    {
86
      // At this point, fetch size is more than one.    
88
      int fetchSize = fetchRules.size();
87
      int fetchSize = fetchRules.size();
89
      out.writeInt(fetchSize);
88
      out.writeInt(fetchSize);
90
      if (fetchSize > 0)
89
      CDOID contextID = ruleManager.getContext();
90
      CDOIDImpl.write(out, contextID);
91
      for (CDOFetchRule fetchRule : fetchRules)
91
      {
92
      {
92
        CDOID contextID = ruleManager.getContext();
93
        fetchRule.write(out);
93
        CDOIDImpl.write(out, contextID);
94
        for (CDOFetchRule fetchRule : fetchRules)
95
        {
96
          fetchRule.write(out);
97
        }
98
      }
94
      }
99
    }
95
    }
100
  }
96
  }
(-)META-INF/MANIFEST.MF (+2 lines)
Lines 13-23 Link Here
13
 org.eclipse.emf.ecore.xmi;bundle-version="[2.3.0,3.0.0)",
13
 org.eclipse.emf.ecore.xmi;bundle-version="[2.3.0,3.0.0)",
14
 org.eclipse.emf.cdo.protocol;bundle-version="[0.8.0,0.9.0)";visibility:=reexport
14
 org.eclipse.emf.cdo.protocol;bundle-version="[0.8.0,0.9.0)";visibility:=reexport
15
Export-Package: org.eclipse.emf.cdo;version="0.8.0",
15
Export-Package: org.eclipse.emf.cdo;version="0.8.0",
16
 org.eclipse.emf.cdo.analyzer;version="0.8.0",
16
 org.eclipse.emf.cdo.eresource;version="0.8.0",
17
 org.eclipse.emf.cdo.eresource;version="0.8.0",
17
 org.eclipse.emf.cdo.eresource.impl;version="0.8.0",
18
 org.eclipse.emf.cdo.eresource.impl;version="0.8.0",
18
 org.eclipse.emf.cdo.eresource.util;version="0.8.0",
19
 org.eclipse.emf.cdo.eresource.util;version="0.8.0",
19
 org.eclipse.emf.cdo.util;version="0.8.0",
20
 org.eclipse.emf.cdo.util;version="0.8.0",
20
 org.eclipse.emf.internal.cdo;version="0.8.0",
21
 org.eclipse.emf.internal.cdo;version="0.8.0",
22
 org.eclipse.emf.internal.cdo.analyzer;version="0.8.0",
21
 org.eclipse.emf.internal.cdo.protocol;version="0.8.0",
23
 org.eclipse.emf.internal.cdo.protocol;version="0.8.0",
22
 org.eclipse.emf.internal.cdo.util;version="0.8.0"
24
 org.eclipse.emf.internal.cdo.util;version="0.8.0"
23
Eclipse-LazyStart: true
25
Eclipse-LazyStart: true
(-)src/org/eclipse/emf/internal/cdo/analyzer/CDOFetchFeatureInfo.java (+95 lines)
Added Link Here
1
/***************************************************************************
2
 * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *    Simon McDuff - initial API and implementation
10
 *    Eike Stepper - maintenance
11
 **************************************************************************/
12
package org.eclipse.emf.internal.cdo.analyzer;
13
14
import org.eclipse.emf.cdo.internal.protocol.analyzer.CDOFetchRule;
15
import org.eclipse.emf.internal.cdo.bundle.OM;
16
import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
17
18
/**
19
 * @author Eike Stepper
20
 */
21
public class CDOFetchFeatureInfo
22
{
23
  private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, CDOFetchFeatureInfo.class);
24
  
25
  private long timeBeforeUsed;
26
27
  private long latencyTime;
28
  
29
  private boolean active;
30
31
  public CDOFetchFeatureInfo()
32
  {
33
	  active = false;
34
	  latencyTime = -1;
35
  }
36
37
  public boolean isActive()
38
  {
39
    return active;
40
  }
41
  public void setActive(boolean isActive)
42
  {
43
    active = isActive;
44
  }
45
46
  public long getTimeBeforeUsed()
47
  {
48
    return timeBeforeUsed;
49
  }
50
51
  public void setTimeBeforeUsed(long timeBeforeUsed)
52
  {
53
    this.timeBeforeUsed = timeBeforeUsed;
54
  }
55
56
  public long getLatencyTime()
57
  {
58
    return latencyTime;
59
  }
60
  /**
61
   * 
62
   * @param latencyTime
63
   */
64
  public void updateLatencyTime(long latencyTime)
65
  {
66
	  if (this.latencyTime == -1)
67
		  this.latencyTime = latencyTime;
68
	  else
69
		  this.latencyTime = (latencyTime + this.latencyTime) / 2;
70
  }
71
  /**
72
   * 
73
   * @param latencyTime
74
   */
75
  public void setLatencyTime(long latencyTime)
76
  {
77
    this.latencyTime = latencyTime;
78
  }
79
  /**
80
   * 
81
   * @param elapseTimeBeforeLastRequest
82
   */
83
  public void updateTimeInfo(long elapseTimeBeforeLastRequest)
84
  {
85
	  if (this.getTimeBeforeUsed() != 0)
86
	  {
87
		  this.setTimeBeforeUsed((this.getTimeBeforeUsed() + elapseTimeBeforeLastRequest) / 2);
88
	  }
89
	  else
90
	  {
91
		  this.setTimeBeforeUsed(elapseTimeBeforeLastRequest);
92
	  }
93
  }
94
95
}
(-)src/org/eclipse/emf/internal/cdo/analyzer/CDODynamicFetchRuleAnalyzer.java (+238 lines)
Added Link Here
1
/***************************************************************************
2
 * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *    Simon McDuff - initial API and implementation
10
 *    Eike Stepper - maintenance
11
 **************************************************************************/
12
package org.eclipse.emf.internal.cdo.analyzer;
13
14
import java.util.ArrayList;
15
import java.util.Collection;
16
import java.util.HashMap;
17
import java.util.Iterator;
18
import java.util.List;
19
import java.util.Map;
20
21
import org.eclipse.emf.cdo.CDOView;
22
import org.eclipse.emf.cdo.analyzer.CDOFeatureAnalyzer;
23
import org.eclipse.emf.cdo.analyzer.CDOFetchRuleManager;
24
import org.eclipse.emf.cdo.internal.protocol.analyzer.CDOFetchRule;
25
import org.eclipse.emf.cdo.protocol.CDOID;
26
import org.eclipse.emf.cdo.protocol.model.CDOClass;
27
import org.eclipse.emf.cdo.protocol.model.CDOFeature;
28
import org.eclipse.emf.internal.cdo.InternalCDOObject;
29
import org.eclipse.emf.internal.cdo.bundle.OM;
30
import org.eclipse.emf.internal.cdo.util.FSMUtil;
31
import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
32
33
/**
34
 * @author Eike Stepper
35
 */
36
public class CDODynamicFetchRuleAnalyzer implements CDOFeatureAnalyzer, CDOFetchRuleManager
37
{
38
  private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, CDODynamicFetchRuleAnalyzer.class);
39
40
  private static final long ELAPSE_TIME = 400L;
41
42
  private Map<CDOFeature, CDOClusterOfFetchRule> featureRules = new HashMap<CDOFeature, CDOClusterOfFetchRule>();
43
  
44
  private CDOGraphAnalyzer graphAnalyzer = new CDOGraphAnalyzer();
45
46
  private CDOGraph currentGraph;
47
48
  private long lastAccessTime;
49
50
  private boolean inUse;
51
  
52
  private InternalCDOObject lastRevision;
53
  
54
  private CDOView cdoView;
55
  
56
  private boolean doesFetch;
57
  
58
  
59
  /**
60
   * 
61
   * @param view
62
   */
63
  public CDODynamicFetchRuleAnalyzer(CDOView view)
64
  {
65
	  cdoView = view;
66
  }
67
  
68
  /**
69
   * 
70
   * @return
71
   */
72
  public CDOClusterOfFetchRule getCurrentFeatureRule()
73
  {
74
    return currentGraph.getFeatureRule();
75
  }
76
  
77
  
78
  public CDOGraph getCurrentGraph()
79
  {
80
	  return this.currentGraph;
81
  }
82
  /**
83
   * 
84
   */
85
  public void preTraverseFeature(InternalCDOObject cdoObject, CDOFeature feature, int index)
86
  {
87
    CDOClass cdoClass = cdoObject.cdoClass();
88
    
89
    doesFetch = false;
90
    
91
    CDODynamicFetchRuleManager.join(this);
92
    
93
    lastRevision = cdoObject;
94
95
    if (TRACER.isEnabled())
96
    {
97
      TRACER.format("preTraverseFeature : {0}.{1}", cdoClass.getName(), feature.getName());
98
    }
99
    
100
    // Do not handle these cases
101
    long currentTime = System.currentTimeMillis();
102
    long elapseTimeBeforeLastRequest = currentTime - lastAccessTime;
103
    lastAccessTime = currentTime;
104
    
105
    // Don`t handle containment relationship
106
    if (!feature.isReference()) //|| feature.isContainment())
107
      return;
108
    
109
    
110
    if (elapseTimeBeforeLastRequest > ELAPSE_TIME)
111
    {
112
    	graphAnalyzer.clear();
113
    }
114
    
115
    // Purge old graph that we didn't update for specific elapse time
116
    graphAnalyzer.purge(ELAPSE_TIME * 2, ELAPSE_TIME * 2);
117
    
118
    CDOClusterOfFetchRule featureRule = this.getFeatureRule(cdoClass, feature);
119
    
120
    // Get the graph <cdoObject> belongs to
121
    this.currentGraph = graphAnalyzer.getGraph(cdoObject.cdoID(), featureRule);
122
    lastAccessTime = System.currentTimeMillis();
123
124
    if (currentGraph.getFeatureRule().getRootFeature() == feature)
125
    {
126
    	if (graphAnalyzer.isTimeToRemove(currentGraph, lastAccessTime, ELAPSE_TIME))
127
    	{
128
    		// Clean it!! 
129
    		currentGraph.clean();
130
    		return;
131
    	}
132
    }
133
 
134
	// need to calculate currentFeature to calculate the connected graph
135
    if ( feature.isMany() && index != 0)
136
    {
137
    	return;
138
    }
139
140
    // Get the cluster of rule for that feature
141
    CDOClusterOfFetchRule currentFeatureRule = currentGraph.getFeatureRule();
142
    
143
    CDOFetchFeatureInfo infoOfFeature = currentFeatureRule.getFeatureStat(feature);
144
    
145
    infoOfFeature.updateTimeInfo(elapseTimeBeforeLastRequest);
146
147
    // Detect a new rule
148
    if (!infoOfFeature.isActive() && infoOfFeature.getTimeBeforeUsed() < CDODynamicFetchRuleAnalyzer.ELAPSE_TIME)
149
    {
150
      currentFeatureRule.addFeatureRule(cdoClass, feature);
151
      infoOfFeature.setActive(true);
152
    }
153
    // Detect if the rule is still good!
154
    else if (infoOfFeature.isActive() && infoOfFeature.getTimeBeforeUsed() > CDODynamicFetchRuleAnalyzer.ELAPSE_TIME)
155
    {
156
      // Unregister rules
157
       currentFeatureRule.removeFeatureRule(cdoClass, feature);
158
       infoOfFeature.setActive(false);
159
    }
160
161
    lastAccessTime = currentTime;
162
    inUse = true;
163
  }
164
165
  public void postTraverseFeature(InternalCDOObject cdoObject, CDOFeature feature, int index, Object object)
166
  {
167
	
168
    if (TRACER.isEnabled())
169
    {
170
      TRACER.format("postTraverseFeature : {0}.{1}", cdoObject.cdoClass(), feature.getName());
171
    }
172
    if (currentGraph != null)
173
    {
174
    	// Adding return object to the link graph
175
    	InternalCDOObject dstCdoObject = FSMUtil.adapt(object, cdoView);
176
    	currentGraph.add(cdoObject.cdoID(), feature, dstCdoObject.cdoID());
177
    	
178
    	// calculate latency time
179
        if (doesFetch == true)
180
        {
181
        	 CDOClusterOfFetchRule currentFeatureRule = currentGraph.getFeatureRule();    	    
182
        	 CDOFetchFeatureInfo infoOfFeature = currentFeatureRule.getFeatureStat(feature);
183
        	 infoOfFeature.updateLatencyTime( System.currentTimeMillis() - lastAccessTime);
184
        }
185
    }
186
    
187
    lastAccessTime = System.currentTimeMillis();
188
    inUse = false;
189
    
190
    CDODynamicFetchRuleManager.leave();
191
  }
192
193
  public CDOID getContext()
194
  {
195
    return lastRevision.cdoID();
196
  }
197
  
198
  /**
199
   * 
200
   * @param cdoClass
201
   * @param cdoFeature
202
   * @return
203
   */
204
  public synchronized CDOClusterOfFetchRule getFeatureRule(CDOClass cdoClass, CDOFeature cdoFeature)
205
  {
206
    CDOClusterOfFetchRule featureRule = featureRules.get(cdoFeature);
207
    if (featureRule == null)
208
    {
209
      featureRule = new CDOClusterOfFetchRule(cdoFeature);
210
      featureRules.put(cdoFeature, featureRule);
211
    }
212
213
    return featureRule;
214
  }
215
  
216
  /**
217
   * Called when from LoadRevisionRequest
218
   */
219
  public List<CDOFetchRule> getFetchRules(Collection<CDOID> ids)
220
  {
221
	doesFetch = true;
222
	
223
    if (!inUse || currentGraph == null)
224
    {
225
      return null;
226
    }
227
228
    List<CDOFetchRule> list = new ArrayList<CDOFetchRule>();
229
    
230
    for (Iterator<CDOFetchRule> it = currentGraph.getFeatureRule().iterator(); it.hasNext();)
231
    {
232
      CDOFetchRule fetchRule = it.next();
233
      list.add(fetchRule);
234
    }
235
   
236
    return list;
237
  }
238
}
(-)src/org/eclipse/emf/internal/cdo/analyzer/NOOPFetchRuleManager.java (+36 lines)
Added Link Here
1
/***************************************************************************
2
 * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *    Simon McDuff - initial API and implementation
10
 *    Eike Stepper - maintenance
11
 **************************************************************************/
12
package org.eclipse.emf.internal.cdo.analyzer;
13
14
import java.util.Collection;
15
import java.util.List;
16
17
import org.eclipse.emf.cdo.analyzer.CDOFetchRuleManager;
18
import org.eclipse.emf.cdo.internal.protocol.CDOIDNull;
19
import org.eclipse.emf.cdo.internal.protocol.analyzer.CDOFetchRule;
20
import org.eclipse.emf.cdo.protocol.CDOID;
21
22
/**
23
 * @author Eike Stepper
24
 */
25
public class NOOPFetchRuleManager implements CDOFetchRuleManager
26
{
27
  public CDOID getContext()
28
  {
29
    return CDOIDNull.NULL;
30
  }
31
32
  public List<CDOFetchRule> getFetchRules(Collection<CDOID> ids)
33
  {
34
    return null;
35
  }
36
}
(-)src/org/eclipse/emf/internal/cdo/analyzer/CDODynamicFetchRuleManager.java (+72 lines)
Added Link Here
1
/***************************************************************************
2
 * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *    Simon McDuff - initial API and implementation
10
 *    Eike Stepper - maintenance
11
 **************************************************************************/
12
package org.eclipse.emf.internal.cdo.analyzer;
13
14
import java.util.Collection;
15
import java.util.List;
16
17
import org.eclipse.emf.cdo.analyzer.CDOFetchRuleManager;
18
import org.eclipse.emf.cdo.internal.protocol.analyzer.CDOFetchRule;
19
import org.eclipse.emf.cdo.protocol.CDOID;
20
import org.eclipse.emf.internal.cdo.bundle.OM;
21
import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
22
23
/**
24
 * @author Eike Stepper
25
 */
26
public class CDODynamicFetchRuleManager implements CDOFetchRuleManager
27
{
28
  private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, CDODynamicFetchRuleManager.class);
29
  
30
  private static final ThreadLocal<CDOFetchRuleManager> threadLocal = new ThreadLocal<CDOFetchRuleManager>();
31
  
32
  public CDODynamicFetchRuleManager()
33
  {
34
	  
35
  }
36
  
37
  /**
38
   * 
39
   * @param fetchRulemanager
40
   */
41
  public static void join(CDOFetchRuleManager fetchRulemanager)
42
  {
43
	  threadLocal.set(fetchRulemanager);
44
  }
45
  /**
46
   * 
47
   * @return
48
   */
49
  public static CDOFetchRuleManager getCurrent()
50
  {
51
	  return threadLocal.get();
52
  }
53
  /**
54
   * 
55
   */
56
  public static void leave()
57
  {
58
	  threadLocal.set(null);
59
  }
60
  
61
  public CDOID getContext()
62
  {
63
	  CDOFetchRuleManager analyzer = CDODynamicFetchRuleManager.getCurrent();
64
	  return analyzer != null? analyzer.getContext() : null; 
65
  }
66
67
  public List<CDOFetchRule> getFetchRules(Collection<CDOID> ids)
68
  {
69
	CDOFetchRuleManager analyzer = CDODynamicFetchRuleManager.getCurrent();
70
	return analyzer != null ? analyzer.getFetchRules(ids) : null;
71
  }
72
}
(-)src/org/eclipse/emf/cdo/analyzer/CDOFetchRuleManager.java (+31 lines)
Added Link Here
1
/***************************************************************************
2
 * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *    Simon McDuff - initial API and implementation
10
 *    Eike Stepper - maintenance
11
 **************************************************************************/
12
package org.eclipse.emf.cdo.analyzer;
13
14
import java.util.Collection;
15
import java.util.List;
16
17
import org.eclipse.emf.cdo.internal.protocol.analyzer.CDOFetchRule;
18
import org.eclipse.emf.cdo.protocol.CDOID;
19
import org.eclipse.emf.internal.cdo.analyzer.NOOPFetchRuleManager;
20
21
/**
22
 * @author Eike Stepper
23
 */
24
public interface CDOFetchRuleManager
25
{
26
  public static final CDOFetchRuleManager NOOP = new NOOPFetchRuleManager();
27
28
  public CDOID getContext();
29
30
  public List<CDOFetchRule> getFetchRules(Collection<CDOID> ids);
31
}
(-)src/org/eclipse/emf/internal/cdo/analyzer/CDOClusterOfFetchRule.java (+156 lines)
Added Link Here
1
/***************************************************************************
2
 * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *    Simon McDuff - initial API and implementation
10
 *    Eike Stepper - maintenance
11
 **************************************************************************/
12
package org.eclipse.emf.internal.cdo.analyzer;
13
14
import java.util.HashMap;
15
import java.util.Iterator;
16
import java.util.Map;
17
18
import org.eclipse.emf.cdo.internal.protocol.analyzer.CDOFetchRule;
19
import org.eclipse.emf.cdo.protocol.model.CDOClass;
20
import org.eclipse.emf.cdo.protocol.model.CDOFeature;
21
import org.eclipse.emf.internal.cdo.bundle.OM;
22
import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
23
24
/**
25
 * @author Eike Stepper
26
 */
27
public class CDOClusterOfFetchRule
28
{
29
  public static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, CDOClusterOfFetchRule.class);
30
31
  private Map<CDOFeature, CDOFetchFeatureInfo> featureStats = new HashMap<CDOFeature, CDOFetchFeatureInfo>();
32
33
  private Map<CDOClass, CDOFetchRule> fetchRules = new HashMap<CDOClass, CDOFetchRule>();
34
  
35
  private long lastUpdate;
36
37
  private CDOFeature rootFeature;
38
  /**
39
   * 
40
   * @param cdoClass
41
   * @param cdoFeature
42
   */
43
  public CDOClusterOfFetchRule(CDOFeature rootFeature)
44
  {
45
    lastUpdate = System.currentTimeMillis();
46
    this.rootFeature = rootFeature;
47
  }
48
  
49
  public boolean isActive()
50
  {
51
	  return !fetchRules.isEmpty();
52
  }
53
  /**
54
   * 
55
   * @return
56
   */
57
  public Iterator<CDOFetchRule> iterator()
58
  {
59
    return fetchRules.values().iterator();
60
  }
61
62
  /**
63
   * 
64
   * @param cdoFeature
65
   * @return
66
   */
67
  public synchronized CDOFetchFeatureInfo getFeatureStat(CDOFeature cdoFeature)
68
  {
69
    CDOFetchFeatureInfo featureRule = featureStats.get(cdoFeature);
70
    if (featureRule == null)
71
    {
72
      featureRule = new CDOFetchFeatureInfo();
73
      featureStats.put(cdoFeature, featureRule);
74
    }
75
76
    return featureRule;
77
  }
78
79
  /**
80
   * 
81
   * @param cdoClass
82
   * @param cdoFeature
83
   * @return
84
   */
85
  public synchronized CDOFetchRule addFeatureRule(CDOClass cdoClass, CDOFeature cdoFeature)
86
  {
87
    if (TRACER.isEnabled())
88
    {
89
      TRACER.format("Adding new fetch rule : {0}.{1} from root feature {2}", cdoClass.getName(), cdoFeature.getName(), rootFeature);
90
    }
91
    lastUpdate = System.currentTimeMillis();
92
    CDOFetchRule fetchRule = getFetchRule(cdoClass);
93
    fetchRule.addFeature(cdoFeature);
94
    return fetchRule;
95
96
  }
97
98
  /**
99
   * 
100
   * @param cdoClass
101
   * @param cdoFeature
102
   * @return
103
   */
104
  public synchronized CDOFetchRule removeFeatureRule(CDOClass cdoClass, CDOFeature cdoFeature)
105
  {
106
    if (TRACER.isEnabled())
107
    {
108
      TRACER.format("Removing fetch rule : {0}.{1} from root feature {2}", cdoClass.getName(), cdoFeature.getName(),rootFeature);
109
    }
110
    
111
    lastUpdate = System.currentTimeMillis();
112
    
113
    CDOFetchRule fetchRule = getFetchRule(cdoClass);
114
    fetchRule.removeFeature(cdoFeature);
115
    if (fetchRule.isEmpty())
116
    {
117
      fetchRules.remove(cdoClass);
118
    }
119
    return fetchRule;
120
  }
121
122
  /**
123
   * 
124
   * @param cdoFeature
125
   * @return
126
   */
127
  public synchronized CDOFetchRule getFetchRule(CDOClass cdoFeature)
128
  {
129
    CDOFetchRule featureRule = fetchRules.get(cdoFeature);
130
    if (featureRule == null)
131
    {
132
      featureRule = new CDOFetchRule(cdoFeature);
133
      fetchRules.put(cdoFeature, featureRule);
134
    }
135
136
    return featureRule;
137
  }
138
  
139
  /**
140
   * 
141
   * @return
142
   */
143
  public long getLastUpdate() 
144
  {
145
	return lastUpdate;
146
  }
147
  
148
  /**
149
   * 
150
   * @return
151
   */
152
  public CDOFeature getRootFeature() 
153
  {
154
	return rootFeature;
155
  }
156
}
(-)src/org/eclipse/emf/internal/cdo/analyzer/NOOPFeatureAnalyzer.java (+35 lines)
Added Link Here
1
/***************************************************************************
2
 * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *    Simon McDuff - initial API and implementation
10
 *    Eike Stepper - maintenance
11
 **************************************************************************/
12
package org.eclipse.emf.internal.cdo.analyzer;
13
14
import org.eclipse.emf.cdo.analyzer.CDOFeatureAnalyzer;
15
import org.eclipse.emf.cdo.protocol.model.CDOFeature;
16
import org.eclipse.emf.internal.cdo.InternalCDOObject;
17
18
19
/**
20
 * @author Eike Stepper
21
 */
22
public class NOOPFeatureAnalyzer implements CDOFeatureAnalyzer
23
{
24
  public NOOPFeatureAnalyzer()
25
  {
26
  }
27
28
  public void preTraverseFeature(InternalCDOObject cdoClass, CDOFeature feature, int index)
29
  {
30
  }
31
32
  public void postTraverseFeature(InternalCDOObject cdoClass, CDOFeature feature, int index, Object value)
33
  {
34
  }
35
}
(-)src/org/eclipse/emf/internal/cdo/analyzer/CDOGraph.java (+137 lines)
Added Link Here
1
/***************************************************************************
2
 * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *    Simon McDuff - initial API and implementation
10
 *    
11
 **************************************************************************/
12
package org.eclipse.emf.internal.cdo.analyzer;
13
14
import java.util.ArrayList;
15
import java.util.Iterator;
16
import java.util.List;
17
18
import org.eclipse.emf.cdo.protocol.CDOID;
19
import org.eclipse.emf.cdo.protocol.model.CDOFeature;
20
import org.eclipse.emf.internal.cdo.bundle.OM;
21
import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
22
23
/**
24
 * 
25
 * @author Eike Stepper
26
 *
27
 */
28
public class CDOGraph 
29
{
30
	private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, CDOGraph.class);
31
	
32
	private CDOClusterOfFetchRule featureRule;
33
	  
34
	  private List<CDOID> clusterOfObjects = new ArrayList<CDOID>();
35
	  
36
	  private long lastUpdated;
37
	  
38
	  private long creationTime;
39
	  
40
	  private CDOGraphAnalyzer analyzer;
41
	  
42
	  /**
43
	   * 
44
	   * @param analyzer
45
	   * @param rootID
46
	   * @param featureRule
47
	   */
48
	  public CDOGraph(CDOGraphAnalyzer analyzer, CDOID rootID, CDOClusterOfFetchRule featureRule)
49
	  {
50
		  this.featureRule = featureRule;
51
		  this.analyzer = analyzer;
52
		  // Adding the root element
53
		  add(rootID, null, rootID);
54
		  creationTime = System.currentTimeMillis();
55
	  }
56
	  
57
	  /**
58
	   * 
59
	   */
60
	  public void clean()
61
	  {
62
		  Iterator<CDOID> itr = clusterOfObjects.iterator();
63
		  itr.next(); // Skip the Root!
64
		  while(itr.hasNext())
65
		  {
66
			  analyzer.removeTrackingID(itr.next());
67
		  }		  		  
68
		  creationTime =  System.currentTimeMillis();
69
	  }
70
71
	  /**
72
	   * 
73
	   */
74
	  public void update()
75
	  {
76
		  lastUpdated = System.currentTimeMillis();
77
	  }
78
	  /**
79
	   * 
80
	   * @param cdoID
81
	   */
82
	  public void add(CDOID fromId,  CDOFeature feature, CDOID cdoID)
83
	  {
84
		  // For now .. we do not need to calculate the path.. later we will do!!
85
		  clusterOfObjects.add(cdoID);
86
		  analyzer.addTrackingID(cdoID, this);
87
	  }
88
	  public CDOID getRoot()
89
	  {
90
		  return getObjects().get(0);
91
	  }
92
	  /**
93
	   * 
94
	   * @return
95
	   */
96
	  public List<CDOID> getObjects()
97
	  {
98
		return this.clusterOfObjects;  
99
	  }
100
	  /***
101
	   * 
102
	   * @return
103
	   */
104
	  public CDOClusterOfFetchRule getFeatureRule() 
105
	  {
106
		return featureRule;
107
	  }
108
	  
109
	  /**
110
	   * 
111
	   */
112
	  public void remove()
113
	  {
114
		  if (TRACER.isEnabled())
115
		  {
116
			  TRACER.format("Removing CDOGraph {0}", this);
117
		  }
118
		  
119
		  for (CDOID cdoId : this.clusterOfObjects)
120
		  {
121
			  analyzer.removeTrackingID(cdoId);
122
		  }
123
		  analyzer.removeTracking(this);
124
	  }
125
      /**
126
       * 
127
       * @return
128
       */
129
	  public long getLastUpdated() 
130
	  {
131
		return lastUpdated;
132
	  }
133
134
	public long getCreationTime() {
135
		return creationTime;
136
	}
137
};
(-)src/org/eclipse/emf/cdo/analyzer/CDOFeatureAnalyzer.java (+29 lines)
Added Link Here
1
/***************************************************************************
2
 * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *    Simon McDuff - initial API and implementation
10
 *    Eike Stepper - maintenance
11
 **************************************************************************/
12
package org.eclipse.emf.cdo.analyzer;
13
14
import org.eclipse.emf.cdo.protocol.model.CDOFeature;
15
import org.eclipse.emf.internal.cdo.InternalCDOObject;
16
import org.eclipse.emf.internal.cdo.analyzer.NOOPFeatureAnalyzer;
17
18
19
/**
20
 * @author Eike Stepper
21
 */
22
public interface CDOFeatureAnalyzer
23
{
24
  public static final CDOFeatureAnalyzer NOOP = new NOOPFeatureAnalyzer();
25
26
  public void preTraverseFeature(InternalCDOObject revision, CDOFeature feature, int index);
27
28
  public void postTraverseFeature(InternalCDOObject revision, CDOFeature feature, int index, Object value);
29
}
(-)src/org/eclipse/emf/internal/cdo/analyzer/CDOReadAhead.java (+99 lines)
Added Link Here
1
package org.eclipse.emf.internal.cdo.analyzer;
2
3
import java.util.ArrayList;
4
import java.util.Collection;
5
import java.util.Iterator;
6
import java.util.List;
7
import java.util.Set;
8
9
import org.eclipse.emf.cdo.analyzer.CDOFetchRuleManager;
10
import org.eclipse.emf.cdo.internal.protocol.analyzer.CDOFetchRule;
11
import org.eclipse.emf.cdo.protocol.CDOID;
12
import org.eclipse.emf.internal.cdo.CDOSessionImpl;
13
import org.eclipse.emf.internal.cdo.CDOViewImpl;
14
import org.eclipse.net4j.internal.util.concurrent.QueueWorkerWorkSerializer;
15
16
public class CDOReadAhead 
17
{
18
	 QueueWorkerWorkSerializer workerWork = new QueueWorkerWorkSerializer();
19
	 CDOViewImpl session;
20
	 
21
	 public CDOReadAhead(CDOViewImpl session)
22
	 {
23
		 this.session = session;
24
	 }
25
	 
26
	 /**
27
	  * 
28
	  * @return
29
	  */
30
	 public CDOViewImpl getSession()
31
	 {
32
		 return session;
33
	 }
34
	 
35
	 /**
36
	  * 
37
	  * @param cdoID
38
	  */
39
	 public void addID(Set<CDOID> cdoID)
40
	 {
41
		 CDODynamicFetchRuleAnalyzer  dynamic = ((CDODynamicFetchRuleAnalyzer)getSession().getFeatureAnalyzer()); 
42
		 
43
    	 if ( dynamic.getCurrentGraph().getFeatureRule().isActive())
44
    	 {
45
    		 workerWork.addWork( new ReceiverWork(cdoID));	 
46
    	 }
47
		 
48
	 }
49
	 
50
	
51
	 /**
52
	  * 
53
	  * @author Simon McDuff
54
	  *
55
	  */
56
	 private final class ReceiverWork implements Runnable
57
	 {
58
		 private final class Test implements CDOFetchRuleManager
59
		 {
60
61
			public CDOID getContext() 
62
			{
63
				// TODO Auto-generated method stub
64
				return context;
65
			}
66
67
			public List<CDOFetchRule> getFetchRules(Collection<CDOID> ids) 
68
			{
69
				// TODO Auto-generated method stub
70
			    List<CDOFetchRule> list = new ArrayList<CDOFetchRule>();
71
			    
72
			    for (Iterator<CDOFetchRule> it = graph.getFeatureRule().iterator(); it.hasNext();)
73
			    {
74
			      CDOFetchRule fetchRule = it.next();
75
			      list.add(fetchRule);
76
			    }
77
			    return list;
78
			}
79
		 }		 
80
		private Set<CDOID> cdoID;
81
		private CDODynamicFetchRuleAnalyzer dynamic;
82
		private CDOGraph graph;
83
		private CDOID context;
84
		private Test test = new Test();
85
	    private ReceiverWork(Set<CDOID> cdoID)
86
	    {
87
	    	 this.cdoID = cdoID;
88
	    	 dynamic = ((CDODynamicFetchRuleAnalyzer)getSession().getFeatureAnalyzer()); 
89
	    	 graph = dynamic.getCurrentGraph();
90
	    	 this.context = ((CDODynamicFetchRuleAnalyzer)getSession().getFeatureAnalyzer()).getContext();
91
	    }
92
	    public void run()
93
	    {
94
	    	CDODynamicFetchRuleManager.join(test);
95
	    	getSession().getSession().getRevisionManager().getRevisions(cdoID, getSession().getSession().getReferenceChunkSize());
96
	    }
97
	  }
98
	
99
}
(-)src/org/eclipse/emf/internal/cdo/analyzer/CDOGraphAnalyzer.java (+126 lines)
Added Link Here
1
/***************************************************************************
2
 * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *    Simon McDuff - initial API and implementation
10
 *    
11
 **************************************************************************/
12
13
package org.eclipse.emf.internal.cdo.analyzer;
14
15
import java.util.ArrayList;
16
import java.util.HashMap;
17
import java.util.HashSet;
18
import java.util.Map;
19
20
import org.eclipse.emf.cdo.protocol.CDOID;
21
import org.eclipse.emf.internal.cdo.bundle.OM;
22
import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
23
/**
24
 * @author Eike Stepper
25
 */
26
public class CDOGraphAnalyzer 
27
{
28
	private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, CDOGraphAnalyzer.class);
29
	
30
	private Map<CDOID, CDOGraph> fromIdToGraphMaps = new HashMap<CDOID, CDOGraph>();
31
	
32
	private HashSet<CDOGraph> uniqueGraphSet = new HashSet<CDOGraph>();
33
	private long lastPurgeOperation;
34
	
35
	public CDOGraphAnalyzer()
36
	{
37
		lastPurgeOperation = System.currentTimeMillis();
38
	}
39
	/**
40
	 * 
41
	 * @param fromID
42
	 * @return
43
	 */
44
	public CDOGraph getGraph(CDOID fromID, CDOClusterOfFetchRule featureRule)
45
	{
46
		CDOGraph graph = fromIdToGraphMaps.get(fromID);
47
		  
48
		if (graph == null)
49
		{		    		  
50
		  graph = new CDOGraph(this, fromID, featureRule);
51
		  uniqueGraphSet.add( graph );
52
		}
53
		
54
		// Update is time value
55
		graph.update();
56
		
57
		return graph;	  
58
	}
59
	
60
61
	/**
62
	 * 
63
	 * @param elapseTimeForPurging
64
	 * @param elapseTimeToClear
65
	 */
66
	public void purge(long elapseTimeForPurging, long elapseTimeToClear)
67
	{
68
		  long  time = System.currentTimeMillis();
69
		  if (time - lastPurgeOperation > elapseTimeForPurging)
70
		  {
71
			  if (TRACER.isEnabled())
72
			  {
73
				  TRACER.format("Purging graph {0}", this);
74
			  }
75
			  ArrayList<CDOGraph> listToRemove = new ArrayList<CDOGraph>();
76
			  for (CDOGraph graph : this.uniqueGraphSet)
77
			  {
78
				  if (isTimeToRemove(graph, time, elapseTimeToClear))
79
					  listToRemove.add(graph);
80
			  }
81
			  
82
			  for (CDOGraph graph : listToRemove)
83
			  {
84
				  graph.remove();
85
			  }
86
			  
87
			  lastPurgeOperation = System.currentTimeMillis();
88
		  }
89
	  }
90
	public boolean isTimeToRemove(CDOGraph cdoGraph, long currentTimestamp, long elapseTimeToClear)
91
	{
92
		  return (currentTimestamp - cdoGraph.getLastUpdated() > elapseTimeToClear || 
93
				  (currentTimestamp - cdoGraph.getFeatureRule().getLastUpdate() > elapseTimeToClear &&
94
						  currentTimestamp - cdoGraph.getCreationTime() > elapseTimeToClear));
95
	}
96
	/**
97
	 * 
98
	 * @param cdoID
99
	 */
100
	public void addTrackingID(CDOID cdoID, CDOGraph cdoGraph)
101
	{
102
		fromIdToGraphMaps.put(cdoID, cdoGraph);
103
		cdoGraph.update();
104
	}  
105
	/**
106
	 * 
107
	 * @param cdoID
108
	 */
109
	public void removeTrackingID(CDOID cdoID)
110
	{
111
		fromIdToGraphMaps.remove(cdoID);
112
	}
113
	/**
114
	 * 
115
	 * @param graph
116
	 */
117
	public void removeTracking(CDOGraph graph )
118
	{
119
		uniqueGraphSet.remove(graph);
120
	}
121
	public void clear()
122
	{
123
		fromIdToGraphMaps.clear();
124
		uniqueGraphSet.clear();
125
	}
126
}

Return to bug 202064