BUG-5280: refactor AbstractClientConnection
[controller.git] / opendaylight / md-sal / cds-access-client / src / main / java / org / opendaylight / controller / cluster / access / client / AbstractReceivingClientConnection.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 java.util.Optional;
12
13 /**
14  * Implementation-internal intermediate subclass between {@link AbstractClientConnection} and two-out of three of its
15  * sublcasses. It allows us to share some code.
16  *
17  * @author Robert Varga
18  *
19  * @param <T> Concrete {@link BackendInfo} type
20  */
21 abstract class AbstractReceivingClientConnection<T extends BackendInfo> extends AbstractClientConnection<T> {
22     private final T backend;
23     private long nextTxSequence;
24
25     AbstractReceivingClientConnection(final ClientActorContext context, final Long cookie, final T backend) {
26         super(context, cookie);
27         this.backend = Preconditions.checkNotNull(backend);
28     }
29
30     AbstractReceivingClientConnection(final AbstractReceivingClientConnection<T> oldConnection) {
31         super(oldConnection);
32         this.backend = oldConnection.backend;
33         this.nextTxSequence = oldConnection.nextTxSequence;
34     }
35
36     @Override
37     public final Optional<T> getBackendInfo() {
38         return Optional.of(backend);
39     }
40
41     final T backend() {
42         return backend;
43     }
44
45     final long nextTxSequence() {
46         return nextTxSequence++;
47     }
48 }