2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.cluster.databroker.actors.dds;
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;
19 * Per-connection representation of a local history. This class handles state replication across a single connection.
21 * @author Robert Varga
23 abstract class AbstractProxyHistory implements Identifiable<LocalHistoryIdentifier> {
24 // FIXME: this should really be ClientConnection
25 private final DistributedDataStoreClientBehavior client;
26 private final LocalHistoryIdentifier identifier;
28 AbstractProxyHistory(final DistributedDataStoreClientBehavior client, final LocalHistoryIdentifier identifier) {
29 this.client = Preconditions.checkNotNull(client);
30 this.identifier = Preconditions.checkNotNull(identifier);
33 static AbstractProxyHistory createClient(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 ClientLocalProxyHistory(client, identifier, dataTree.get())
37 : new RemoteProxyHistory(client, identifier);
40 static AbstractProxyHistory createSingle(final DistributedDataStoreClientBehavior client,
41 final Optional<ShardBackendInfo> backendInfo, final LocalHistoryIdentifier identifier) {
42 final Optional<DataTree> dataTree = backendInfo.flatMap(ShardBackendInfo::getDataTree);
43 return dataTree.isPresent() ? new SingleLocalProxyHistory(client, identifier, dataTree.get())
44 : new RemoteProxyHistory(client, identifier);
48 public LocalHistoryIdentifier getIdentifier() {
52 final ActorRef localActor() {
56 final AbstractProxyTransaction createTransactionProxy(final TransactionIdentifier txId) {
57 return doCreateTransactionProxy(client, new TransactionIdentifier(identifier, txId.getTransactionId()));
60 abstract AbstractProxyTransaction doCreateTransactionProxy(DistributedDataStoreClientBehavior clientBehavior,
61 TransactionIdentifier txId);