Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 7cea690ca0eeee5a6b1c0cf1b63254c6a76c4b43 (plain) (blame)
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
/***************************************************************************
 * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
 * 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
 *    Simon McDuff - bug 226778
 *    Simon McDuff - bug 230832
 *    Simon McDuff - bug 233490
 *    Simon McDuff - bug 213402
 *    Victor Roldan Betancort - maintenance
 *    Andre Dietisheim - bug 256649
 **************************************************************************/
package org.eclipse.emf.cdo.internal.net4j;

import org.eclipse.emf.cdo.common.model.CDOPackageUnit;
import org.eclipse.emf.cdo.common.model.EMFUtil;
import org.eclipse.emf.cdo.common.revision.CDORevisionUtil;
import org.eclipse.emf.cdo.eresource.EresourcePackage;
import org.eclipse.emf.cdo.internal.common.model.CDOPackageRegistryImpl;
import org.eclipse.emf.cdo.internal.net4j.CDONet4jSessionConfigurationImpl.RepositoryInfo;
import org.eclipse.emf.cdo.internal.net4j.protocol.CDOClientProtocol;
import org.eclipse.emf.cdo.internal.net4j.protocol.CommitTransactionRequest;
import org.eclipse.emf.cdo.net4j.CDONet4jSession;
import org.eclipse.emf.cdo.spi.common.branch.CDOBranchUtil;
import org.eclipse.emf.cdo.spi.common.branch.InternalCDOBranchManager;
import org.eclipse.emf.cdo.spi.common.commit.CDOCommitInfoUtil;
import org.eclipse.emf.cdo.spi.common.commit.InternalCDOCommitInfoManager;
import org.eclipse.emf.cdo.spi.common.model.InternalCDOPackageRegistry;
import org.eclipse.emf.cdo.spi.common.model.InternalCDOPackageUnit;
import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevisionManager;

import org.eclipse.emf.internal.cdo.session.CDOSessionImpl;
import org.eclipse.emf.internal.cdo.session.DelegatingSessionProtocol;

import org.eclipse.net4j.connector.IConnector;
import org.eclipse.net4j.signal.ISignalProtocol;
import org.eclipse.net4j.signal.SignalProtocol;
import org.eclipse.net4j.util.io.IStreamWrapper;

import org.eclipse.emf.ecore.EcorePackage;
import org.eclipse.emf.spi.cdo.CDOSessionProtocol;
import org.eclipse.emf.spi.cdo.CDOSessionProtocol.OpenSessionResult;

/**
 * @author Eike Stepper
 */
@SuppressWarnings("deprecation")
public class CDONet4jSessionImpl extends CDOSessionImpl implements org.eclipse.emf.cdo.net4j.CDOSession
{
  private IStreamWrapper streamWrapper;

  private IConnector connector;

  private String repositoryName;

  private long signalTimeout = SignalProtocol.DEFAULT_TIMEOUT;

  public CDONet4jSessionImpl()
  {
  }

  public IStreamWrapper getStreamWrapper()
  {
    return streamWrapper;
  }

  public void setStreamWrapper(IStreamWrapper streamWrapper)
  {
    this.streamWrapper = streamWrapper;
  }

  public IConnector getConnector()
  {
    return connector;
  }

  public void setConnector(IConnector connector)
  {
    this.connector = connector;
  }

  public String getRepositoryName()
  {
    return repositoryName;
  }

  public void setRepositoryName(String repositoryName)
  {
    this.repositoryName = repositoryName;
  }

  public long getSignalTimeout()
  {
    return signalTimeout;
  }

  public void setSignalTimeout(long signalTimeout)
  {
    this.signalTimeout = signalTimeout;

    // Deal with the possibility that the sessionProtocol has already been created.
    CDOClientProtocol clientProtocol = getClientProtocol();
    if (clientProtocol != null)
    {
      clientProtocol.setTimeout(this.signalTimeout);
    }
  }

  @Override
  public OptionsImpl options()
  {
    return (OptionsImpl)super.options();
  }

  @Override
  protected OptionsImpl createOptions()
  {
    return new OptionsImpl();
  }

  @Override
  protected void doActivate() throws Exception
  {
    OpenSessionResult result = openSession();

    super.doActivate();

    InternalCDOPackageRegistry packageRegistry = getPackageRegistry();
    if (packageRegistry == null)
    {
      packageRegistry = new CDOPackageRegistryImpl();
      setPackageRegistry(packageRegistry);
    }

    packageRegistry.setPackageProcessor(this);
    packageRegistry.setPackageLoader(this);
    packageRegistry.activate();

    InternalCDORevisionManager revisionManager = getRevisionManager();
    if (revisionManager == null)
    {
      revisionManager = (InternalCDORevisionManager)CDORevisionUtil.createRevisionManager();
      setRevisionManager(revisionManager);
    }

    revisionManager.setSupportingAudits(getRepositoryInfo().isSupportingAudits());
    revisionManager.setSupportingBranches(getRepositoryInfo().isSupportingBranches());
    revisionManager.setRevisionLoader(getSessionProtocol());
    revisionManager.setRevisionLocker(this);
    revisionManager.activate();

    InternalCDOBranchManager branchManager = getBranchManager();
    if (branchManager == null)
    {
      branchManager = CDOBranchUtil.createBranchManager();
      setBranchManager(branchManager);
    }

    branchManager.setBranchLoader(getSessionProtocol());
    branchManager.setTimeProvider(getRepositoryInfo());
    branchManager.initMainBranch(isMainBranchLocal(), getRepositoryInfo().getCreationTime());
    branchManager.activate();

    InternalCDOCommitInfoManager commitInfoManager = getCommitInfoManager();
    if (commitInfoManager == null)
    {
      commitInfoManager = CDOCommitInfoUtil.createCommitInfoManager();
      setCommitInfoManager(commitInfoManager);
    }

    commitInfoManager.setCommitInfoLoader(getSessionProtocol());
    commitInfoManager.activate();

    for (InternalCDOPackageUnit packageUnit : result.getPackageUnits())
    {
      if (EcorePackage.eINSTANCE.getNsURI().equals(packageUnit.getID()))
      {
        EMFUtil.addAdapter(EcorePackage.eINSTANCE, packageUnit.getTopLevelPackageInfo());
        packageUnit.setState(CDOPackageUnit.State.LOADED);
      }
      else if (EresourcePackage.eINSTANCE.getNsURI().equals(packageUnit.getID()))
      {
        EMFUtil.addAdapter(EresourcePackage.eINSTANCE, packageUnit.getTopLevelPackageInfo());
        packageUnit.setState(CDOPackageUnit.State.LOADED);
      }

      getPackageRegistry().putPackageUnit(packageUnit);
    }

    getRepositoryInfo().getTimeStamp(true);
  }

  private CDOClientProtocol createProtocol()
  {
    CDOClientProtocol protocol = new CDOClientProtocol();
    protocol.setTimeout(signalTimeout);
    protocol.setInfraStructure(this);
    if (streamWrapper != null)
    {
      protocol.setStreamWrapper(streamWrapper);
    }

    protocol.open(connector);
    return protocol;
  }

  /**
   * Gets the CDOClientProtocol instance, which may be wrapped inside a DelegatingSessionProtocol
   */
  private CDOClientProtocol getClientProtocol()
  {
    CDOSessionProtocol protocol = getSessionProtocol();
    CDOClientProtocol clientProtocol;
    if (protocol instanceof DelegatingSessionProtocol)
    {
      clientProtocol = (CDOClientProtocol)((DelegatingSessionProtocol)protocol).getDelegate();
    }
    else
    {
      clientProtocol = (CDOClientProtocol)protocol;
    }

    return clientProtocol;
  }

  protected OpenSessionResult openSession()
  {
    CDOClientProtocol protocol = createProtocol();
    setSessionProtocol(protocol);
    hookSessionProtocol();

    // TODO (CD) The next call is on the CDOClientProtocol; shouldn't it be on the DelegatingSessionProtocol instead?
    OpenSessionResult result = protocol.openSession(repositoryName, options().isPassiveUpdateEnabled(), options()
        .getPassiveUpdateMode());
    setSessionID(result.getSessionID());
    setUserID(result.getUserID());
    setLastUpdateTime(result.getLastUpdateTime());
    setRepositoryInfo(new RepositoryInfo(repositoryName, result, this));
    return result;
  }

  @Override
  protected void doDeactivate() throws Exception
  {
    super.doDeactivate();

    getCommitInfoManager().deactivate();
    getRevisionManager().deactivate();
  }

  /**
   * @author Eike Stepper
   */
  protected class OptionsImpl extends org.eclipse.emf.internal.cdo.session.CDOSessionImpl.OptionsImpl implements
      org.eclipse.emf.cdo.net4j.CDOSession.Options
  {
    private int commitTimeout = CommitTransactionRequest.DEFAULT_MONITOR_TIMEOUT_SECONDS;

    private int progressInterval = CommitTransactionRequest.DEFAULT_MONITOR_PROGRESS_SECONDS;

    public OptionsImpl()
    {
    }

    @Override
    public CDONet4jSession getContainer()
    {
      return (CDONet4jSession)super.getContainer();
    }

    public ISignalProtocol<org.eclipse.emf.cdo.net4j.CDONet4jSession> getProtocol()
    {
      CDOSessionProtocol protocol = getSessionProtocol();
      if (protocol instanceof DelegatingSessionProtocol)
      {
        protocol = ((DelegatingSessionProtocol)protocol).getDelegate();
      }

      @SuppressWarnings("unchecked")
      ISignalProtocol<CDONet4jSession> signalProtocol = (ISignalProtocol<CDONet4jSession>)protocol;
      return signalProtocol;
    }

    public int getCommitTimeout()
    {
      return commitTimeout;
    }

    public synchronized void setCommitTimeout(int commitTimeout)
    {
      this.commitTimeout = commitTimeout;
    }

    public int getProgressInterval()
    {
      return progressInterval;
    }

    public synchronized void setProgressInterval(int progressInterval)
    {
      this.progressInterval = progressInterval;
    }
  }
}

Back to the top