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