Merge "Move protocol framework from BGPCEP project"
[controller.git] / opendaylight / commons / protocol-framework / src / main / java / org / opendaylight / protocol / framework / NeverReconnectStrategy.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.EventExecutor;
11 import io.netty.util.concurrent.Future;
12
13 import javax.annotation.concurrent.ThreadSafe;
14
15 import com.google.common.base.Preconditions;
16
17 /**
18  * Utility ReconnectStrategy singleton, which will cause the reconnect process
19  * to always fail.
20  */
21 @ThreadSafe
22 public final class NeverReconnectStrategy implements ReconnectStrategy {
23     private final EventExecutor executor;
24     private final int timeout;
25
26     public NeverReconnectStrategy(final EventExecutor executor, final int timeout) {
27         Preconditions.checkArgument(timeout >= 0);
28         this.executor = Preconditions.checkNotNull(executor);
29         this.timeout = timeout;
30     }
31
32     @Override
33     public Future<Void> scheduleReconnect(final Throwable cause) {
34         return executor.newFailedFuture(new Throwable());
35     }
36
37     @Override
38     public void reconnectSuccessful() {
39         // Nothing to do
40     }
41
42     @Override
43     public int getConnectTimeout() {
44         return timeout;
45     }
46 }