Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 97252768b8c6e3a000efce3028af14bec6248267 (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
/***************************************************************************
 * Copyright (c) 2004 - 2008 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.net4j.signal.failover;

import org.eclipse.net4j.connector.IConnector;
import org.eclipse.net4j.signal.ISignalProtocol;
import org.eclipse.net4j.util.WrappedException;

import org.eclipse.internal.net4j.bundle.OM;

/**
 * @author Eike Stepper
 */
public class RetryFailOverStrategy extends NOOPFailOverStrategy
{
  /**
   * @since 2.0
   */
  public static final int RETRY_FOREVER = Integer.MAX_VALUE;

  private int retries;

  /**
   * @since 2.0
   */
  public RetryFailOverStrategy(IConnector connector, int retries)
  {
    super(connector);
    this.retries = retries;
  }

  public RetryFailOverStrategy(IConnector connector)
  {
    this(connector, RETRY_FOREVER);
  }

  /**
   * @since 2.0
   */
  public int getRetries()
  {
    return retries;
  }

  @Override
  public void handleFailOver(ISignalProtocol<?> protocol)
  {
    Exception exception = null;
    for (int i = 0; i < retries; i++)
    {
      try
      {
        handleOpen(protocol);
        return;
      }
      catch (Exception ex)
      {
        OM.LOG.error(ex);
        exception = ex;
      }
    }

    if (exception != null)
    {
      throw WrappedException.wrap(exception);
    }
  }
}

Back to the top