2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.netconf.nettyutil;
10 import io.netty.util.concurrent.Future;
13 * Interface exposed by a reconnection strategy provider. A reconnection
14 * strategy decides whether to attempt reconnection and when to do that.
17 * The proper way of using this API is such that when a connection attempt
18 * has failed, the user will call scheduleReconnect() to obtain a future,
19 * which tracks schedule of the next connect attempt. The user should add its
20 * own listener to be get notified when the future is done. Once the
21 * the notification fires, user should examine the future to see whether
22 * it is successful or not. If it is successful, the user should immediately
23 * initiate a connection attempt. If it is unsuccessful, the user must
24 * not attempt any more connection attempts and should abort the reconnection
28 public interface ReconnectStrategy {
30 * Query the strategy for the connect timeout.
32 * @return connect try timeout in milliseconds, or
33 * 0 for infinite (or system-default) timeout
34 * @throws Exception if the connection should not be attempted
36 int getConnectTimeout() throws Exception;
39 * Schedule a connection attempt. The precise time when the connection
40 * should be attempted is signaled by successful completion of returned
43 * @param cause Cause of previous failure
44 * @return a future tracking the schedule, may not be null
45 * @throws IllegalStateException when a connection attempt is currently
48 Future<Void> scheduleReconnect(Throwable cause);
51 * Reset the strategy state. Users call this method once the reconnection
54 void reconnectSuccessful();