Skip to main content
summaryrefslogtreecommitdiffstats
blob: bd68dd0d126017fc6fc9bae7731a92630d89fcd6 (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
/*
 * Copyright (c) 2004 - 2012 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:
 *    Caspar De Groot - initial API and implementation
 */
package org.eclipse.emf.cdo.internal.net4j;

import org.eclipse.emf.cdo.net4j.ReconnectingCDOSessionConfiguration;
import org.eclipse.emf.cdo.session.CDOSession.ExceptionHandler;

import org.eclipse.net4j.util.container.IManagedContainer;

import org.eclipse.emf.spi.cdo.InternalCDOSession;

/**
 * @author Caspar De Groot
 */
public class ReconnectingCDOSessionConfigurationImpl extends RecoveringCDOSessionConfigurationImpl implements
    ReconnectingCDOSessionConfiguration
{
  private String hostAndPort;

  private long reconnectInterval = 0;

  private int maxReconnectAttempts = Integer.MAX_VALUE;

  public ReconnectingCDOSessionConfigurationImpl(String hostAndPort, String repositoryName, IManagedContainer container)
  {
    super(container);

    this.hostAndPort = hostAndPort;
    setRepositoryName(repositoryName);
  }

  public long getReconnectInterval()
  {
    return reconnectInterval;
  }

  public void setReconnectInterval(long reconnectInterval)
  {
    this.reconnectInterval = reconnectInterval;
  }

  public int getMaxReconnectAttempts()
  {
    return maxReconnectAttempts;
  }

  public void setMaxReconnectAttempts(int maxReconnectAttempts)
  {
    this.maxReconnectAttempts = maxReconnectAttempts;
  }

  @Override
  public void setExceptionHandler(ExceptionHandler handler)
  {
    throw new UnsupportedOperationException();
  }

  @Override
  public InternalCDOSession createSession()
  {
    ReconnectingCDOSessionImpl session = new ReconnectingCDOSessionImpl();

    // A ReconnectingCDOSessionImpl has its own exceptionHandler; but the configuration mechanism
    // expects the configuration object (i.e. *this*) to hold a reference to the desired handler.
    // We therefore fetch the handler from the session and plug it into *this*, so that the
    // config mechanism can proceed normally. (It will "set" the same handler again.)
    //
    super.setExceptionHandler(session.getExceptionHandler());
    return session;
  }

  @Override
  protected void configureSession(InternalCDOSession session)
  {
    super.configureSession(session);

    ReconnectingCDOSessionImpl sessionImpl = (ReconnectingCDOSessionImpl)session;
    sessionImpl.setRepositoryConnectorDescription(hostAndPort);
    sessionImpl.setReconnectInterval(reconnectInterval);
    sessionImpl.setMaxReconnectAttempts(maxReconnectAttempts);
  }
}

Back to the top