Fix remaining CS warnings in sal-distributed-datastore
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / databroker / actors / dds / AbstractProxyHistory.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.databroker.actors.dds;
9
10 import akka.actor.ActorRef;
11 import com.google.common.base.Preconditions;
12 import java.util.Optional;
13 import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier;
14 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
15 import org.opendaylight.yangtools.concepts.Identifiable;
16 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
17
18 /**
19  * Per-connection representation of a local history.
20  *
21  * @author Robert Varga
22  */
23 abstract class AbstractProxyHistory implements Identifiable<LocalHistoryIdentifier> {
24     // FIXME: this should really be ClientConnection
25     private final DistributedDataStoreClientBehavior client;
26     private final LocalHistoryIdentifier identifier;
27
28     AbstractProxyHistory(final DistributedDataStoreClientBehavior client, final LocalHistoryIdentifier identifier) {
29         this.client = Preconditions.checkNotNull(client);
30         this.identifier = Preconditions.checkNotNull(identifier);
31     }
32
33     static AbstractProxyHistory create(final DistributedDataStoreClientBehavior client,
34             final Optional<ShardBackendInfo> backendInfo, final LocalHistoryIdentifier identifier) {
35         final Optional<DataTree> dataTree = backendInfo.flatMap(ShardBackendInfo::getDataTree);
36         return dataTree.isPresent() ? new LocalProxyHistory(client, identifier, dataTree.get())
37                 : new RemoteProxyHistory(client, identifier);
38     }
39
40     @Override
41     public LocalHistoryIdentifier getIdentifier() {
42         return identifier;
43     }
44
45     final ActorRef localActor() {
46         return client.self();
47     }
48
49     final AbstractProxyTransaction createTransactionProxy(final TransactionIdentifier txId) {
50         return doCreateTransactionProxy(client, new TransactionIdentifier(identifier, txId.getTransactionId()));
51     }
52
53     abstract AbstractProxyTransaction doCreateTransactionProxy(DistributedDataStoreClientBehavior clientBehavior,
54             TransactionIdentifier txId);
55 }