X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fcommons%2Fprotocol-framework%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fprotocol%2Fframework%2FReconnectStrategy.java;fp=opendaylight%2Fcommons%2Fprotocol-framework%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fprotocol%2Fframework%2FReconnectStrategy.java;h=24ff84b6ab3466a8815d1afb4a4bf972480c7495;hb=391180fcde6a7a2336182e346e24a1ff9f754062;hp=0000000000000000000000000000000000000000;hpb=1208cf638d47c7908604ab04eaf0e1dbaa67c9cb;p=controller.git diff --git a/opendaylight/commons/protocol-framework/src/main/java/org/opendaylight/protocol/framework/ReconnectStrategy.java b/opendaylight/commons/protocol-framework/src/main/java/org/opendaylight/protocol/framework/ReconnectStrategy.java new file mode 100644 index 0000000000..24ff84b6ab --- /dev/null +++ b/opendaylight/commons/protocol-framework/src/main/java/org/opendaylight/protocol/framework/ReconnectStrategy.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2013 Cisco Systems, Inc. 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 + */ +package org.opendaylight.protocol.framework; + +import io.netty.util.concurrent.Future; + +/** + * Interface exposed by a reconnection strategy provider. A reconnection + * strategy decides whether to attempt reconnection and when to do that. + * + * The proper way of using this API is such that when a connection attempt + * has failed, the user will call scheduleReconnect() to obtain a future, + * which tracks schedule of the next connect attempt. The user should add its + * own listener to be get notified when the future is done. Once the + * the notification fires, user should examine the future to see whether + * it is successful or not. If it is successful, the user should immediately + * initiate a connection attempt. If it is unsuccessful, the user must + * not attempt any more connection attempts and should abort the reconnection + * process. + */ +public interface ReconnectStrategy { + /** + * Query the strategy for the connect timeout. + * + * @return connect try timeout in milliseconds, or + * 0 for infinite (or system-default) timeout + * @throws Exception if the connection should not be attempted + */ + int getConnectTimeout() throws Exception; + + /** + * Schedule a connection attempt. The precise time when the connection + * should be attempted is signaled by successful completion of returned + * future. + * + * @param cause Cause of previous failure + * @return a future tracking the schedule, may not be null + * @throws IllegalStateException when a connection attempt is currently + * scheduled. + */ + Future scheduleReconnect(Throwable cause); + + /** + * Reset the strategy state. Users call this method once the reconnection + * process succeeds. + */ + void reconnectSuccessful(); +}