9793e848e83060c28d52dbf554c7aa4eb67f7148
[bgpcep.git] / framework / src / main / java / org / opendaylight / protocol / framework / ReconnectImmediatelyStrategy.java
1 package org.opendaylight.protocol.framework;
2
3 import io.netty.util.concurrent.EventExecutor;
4 import io.netty.util.concurrent.Future;
5
6 import javax.annotation.concurrent.ThreadSafe;
7
8 import com.google.common.base.Preconditions;
9
10 /**
11  * Utility ReconnectStrategy singleton, which will cause the reconnect process
12  * to immediately schedule a reconnection attempt.
13  */
14 @ThreadSafe
15 public final class ReconnectImmediatelyStrategy implements ReconnectStrategy {
16         private final EventExecutor executor;
17         private final int timeout;
18
19         public ReconnectImmediatelyStrategy(final EventExecutor executor, final int timeout) {
20                 Preconditions.checkArgument(timeout >= 0);
21                 this.executor = Preconditions.checkNotNull(executor);
22                 this.timeout = timeout;
23         }
24
25         @Override
26         public Future<Void> scheduleReconnect() {
27                 return executor.newSucceededFuture(null);
28         }
29
30         @Override
31         public void reconnectSuccessful() {
32                 // Nothing to do
33         }
34
35         @Override
36         public int getConnectTimeout() {
37                 return timeout;
38         }
39 }