Merge "Fix for Bug 2727 - Upgrade Akka from 2.3.4 to 2.3.9"
[controller.git] / opendaylight / commons / protocol-framework / src / main / java / org / opendaylight / protocol / framework / ReconnectStrategy.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.protocol.framework;
9
10 import io.netty.util.concurrent.Future;
11
12 /**
13  * Interface exposed by a reconnection strategy provider. A reconnection
14  * strategy decides whether to attempt reconnection and when to do that.
15  *
16  * The proper way of using this API is such that when a connection attempt
17  * has failed, the user will call scheduleReconnect() to obtain a future,
18  * which tracks schedule of the next connect attempt. The user should add its
19  * own listener to be get notified when the future is done. Once the
20  * the notification fires, user should examine the future to see whether
21  * it is successful or not. If it is successful, the user should immediately
22  * initiate a connection attempt. If it is unsuccessful, the user must
23  * not attempt any more connection attempts and should abort the reconnection
24  * process.
25  */
26 @Deprecated
27 public interface ReconnectStrategy {
28     /**
29      * Query the strategy for the connect timeout.
30      *
31      * @return connect try timeout in milliseconds, or
32      *         0 for infinite (or system-default) timeout
33      * @throws Exception if the connection should not be attempted
34      */
35     int getConnectTimeout() throws Exception;
36
37     /**
38      * Schedule a connection attempt. The precise time when the connection
39      * should be attempted is signaled by successful completion of returned
40      * future.
41      *
42      * @param cause Cause of previous failure
43      * @return a future tracking the schedule, may not be null
44      * @throws IllegalStateException when a connection attempt is currently
45      *         scheduled.
46      */
47     Future<Void> scheduleReconnect(Throwable cause);
48
49     /**
50      * Reset the strategy state. Users call this method once the reconnection
51      * process succeeds.
52      */
53     void reconnectSuccessful();
54 }