1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
/***************************************************************************
* Copyright (c) 2004 - 2007 Eike Stepper, Germany.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Eike Stepper - initial API and implementation
**************************************************************************/
package org.eclipse.emf.internal.cdo.protocol;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.eclipse.emf.cdo.analyzer.CDOFetchRuleManager;
import org.eclipse.emf.cdo.internal.protocol.CDOIDImpl;
import org.eclipse.emf.cdo.internal.protocol.analyzer.CDOFetchRule;
import org.eclipse.emf.cdo.internal.protocol.revision.CDORevisionImpl;
import org.eclipse.emf.cdo.protocol.CDOID;
import org.eclipse.emf.cdo.protocol.CDOProtocolConstants;
import org.eclipse.emf.internal.cdo.CDORevisionManagerImpl;
import org.eclipse.emf.internal.cdo.CDOSessionImpl;
import org.eclipse.emf.internal.cdo.CDOSessionPackageManager;
import org.eclipse.emf.internal.cdo.bundle.OM;
import org.eclipse.net4j.IChannel;
import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
import org.eclipse.net4j.util.io.ExtendedDataInputStream;
import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
/**
* @author Eike Stepper
*/
public class LoadRevisionRequest extends CDOClientRequest<List<CDORevisionImpl>>
{
private static final ContextTracer PROTOCOL = new ContextTracer(OM.DEBUG_PROTOCOL, LoadRevisionRequest.class);
private Collection<CDOID> ids;
private int referenceChunk;
public LoadRevisionRequest(IChannel channel, Collection<CDOID> ids, int referenceChunk)
{
super(channel);
this.ids = ids;
this.referenceChunk = referenceChunk;
}
public LoadRevisionRequest(IChannel channel, CDOID id, int referenceChunk)
{
this(channel, Collections.singleton(id), referenceChunk);
}
@Override
protected short getSignalID()
{
return CDOProtocolConstants.SIGNAL_LOAD_REVISION;
}
@Override
protected void requesting(ExtendedDataOutputStream out) throws IOException
{
if (PROTOCOL.isEnabled()) PROTOCOL.format("Writing referenceChunk: {0}", referenceChunk);
out.writeInt(referenceChunk);
if (PROTOCOL.isEnabled()) PROTOCOL.format("Writing {0} IDs", ids.size());
out.writeInt(ids.size());
for (CDOID id : ids)
{
if (PROTOCOL.isEnabled()) PROTOCOL.format("Writing ID: {0}", id);
CDOIDImpl.write(out, id);
}
CDOFetchRuleManager ruleManager = getSession().getRevisionManager().getRuleManager();
List<CDOFetchRule> fetchRules = ruleManager.getFetchRules(ids);
if (fetchRules == null || fetchRules.size() <= 0)
{
out.writeInt(0);
}
else
{
// At this point, fetch size is more than one.
int fetchSize = fetchRules.size();
out.writeInt(fetchSize);
CDOID contextID = ruleManager.getContext();
CDOIDImpl.write(out, contextID);
for (CDOFetchRule fetchRule : fetchRules)
{
fetchRule.write(out);
}
}
}
@Override
public List<CDORevisionImpl> confirming(ExtendedDataInputStream in) throws IOException
{
CDOSessionImpl session = getSession();
CDORevisionManagerImpl revisionManager = session.getRevisionManager();
CDOSessionPackageManager packageManager = session.getPackageManager();
ArrayList<CDORevisionImpl> revisions = new ArrayList<CDORevisionImpl>(ids.size());
if (PROTOCOL.isEnabled()) PROTOCOL.format("Reading {0} revisions", ids.size());
for (int i = 0; i < ids.size(); i++)
{
CDORevisionImpl revision = new CDORevisionImpl(in, revisionManager, packageManager);
revisions.add(revision);
}
int size = in.readInt();
if (size != 0)
{
if (PROTOCOL.isEnabled()) PROTOCOL.format("Reading {0} additional revisions", size);
for (int i = 0; i < size; i++)
{
CDORevisionImpl revision = new CDORevisionImpl(in, revisionManager, packageManager);
revisionManager.addRevision(revision);
}
}
return revisions;
}
}
|