Use Object.requireNonNull
[netconf.git] / netconf / netconf-netty-util / src / main / java / org / opendaylight / netconf / nettyutil / ReconnectImmediatelyStrategy.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.netconf.nettyutil;
9
10 import static com.google.common.base.Preconditions.checkArgument;
11 import static java.util.Objects.requireNonNull;
12
13 import io.netty.util.concurrent.EventExecutor;
14 import io.netty.util.concurrent.Future;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
17
18 /**
19  * Utility ReconnectStrategy singleton, which will cause the reconnect process to immediately schedule a reconnection
20  * attempt. This class is thread-safe.
21  */
22 @Deprecated
23 public final class ReconnectImmediatelyStrategy implements ReconnectStrategy {
24     private static final Logger LOG = LoggerFactory.getLogger(ReconnectImmediatelyStrategy.class);
25     private final EventExecutor executor;
26     private final int timeout;
27
28     public ReconnectImmediatelyStrategy(final EventExecutor executor, final int timeout) {
29         checkArgument(timeout >= 0);
30         this.executor = requireNonNull(executor);
31         this.timeout = timeout;
32     }
33
34     @Override
35     public Future<Void> scheduleReconnect(final Throwable cause) {
36         LOG.debug("Connection attempt failed", cause);
37         return executor.newSucceededFuture(null);
38     }
39
40     @Override
41     public void reconnectSuccessful() {
42         // Nothing to do
43     }
44
45     @Override
46     public int getConnectTimeout() {
47         return timeout;
48     }
49 }