Fix modernization issues
[controller.git] / opendaylight / md-sal / cds-access-client / src / main / java / org / opendaylight / controller / cluster / access / client / ReconnectingClientConnection.java
1 /*
2  * Copyright (c) 2016 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.controller.cluster.access.client;
9
10 import static java.util.Objects.requireNonNull;
11
12 import org.opendaylight.controller.cluster.access.concepts.RequestException;
13 import org.slf4j.Logger;
14 import org.slf4j.LoggerFactory;
15
16 /**
17  * An {@link AbstractClientConnection} which is being reconnected after having timed out.
18  *
19  * @author Robert Varga
20  *
21  * @param <T> {@link BackendInfo} type
22  */
23 public final class ReconnectingClientConnection<T extends BackendInfo> extends AbstractReceivingClientConnection<T> {
24     private static final Logger LOG = LoggerFactory.getLogger(ReconnectingClientConnection.class);
25
26     private RequestException cause;
27
28     ReconnectingClientConnection(final ConnectedClientConnection<T> oldConnection, final RequestException cause) {
29         super(oldConnection);
30         this.cause = requireNonNull(cause);
31     }
32
33     @Override
34     long backendSilentTicks(final long now) {
35         // We do not want to reconnect this connection, as we need the timer to to keep running
36         return 0;
37     }
38
39     @Override
40     @SuppressWarnings("checkstyle:hiddenField")
41     ClientActorBehavior<T> lockedReconnect(final ClientActorBehavior<T> current, final RequestException cause) {
42         this.cause = requireNonNull(cause);
43         LOG.warn("Skipping reconnect of already-reconnecting connection {}", this);
44         return current;
45     }
46
47     @Override
48     RequestException enrichPoison(final RequestException ex) {
49         if (ex.getCause() != null) {
50             ex.addSuppressed(cause);
51         } else {
52             ex.initCause(cause);
53         }
54
55         return ex;
56     }
57
58 }