CDS: Implement front-end support for local transactions
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / compat / PreLithiumTransactionContextImpl.java
1 /*
2  * Copyright (c) 2015 Brocade Communications 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.datastore.compat;
9
10 import akka.actor.ActorSelection;
11 import org.opendaylight.controller.cluster.datastore.DataStoreVersions;
12 import org.opendaylight.controller.cluster.datastore.OperationCompleter;
13 import org.opendaylight.controller.cluster.datastore.RemoteTransactionContext;
14 import org.opendaylight.controller.cluster.datastore.identifiers.TransactionIdentifier;
15 import org.opendaylight.controller.cluster.datastore.messages.DeleteData;
16 import org.opendaylight.controller.cluster.datastore.messages.MergeData;
17 import org.opendaylight.controller.cluster.datastore.messages.ReadyTransaction;
18 import org.opendaylight.controller.cluster.datastore.messages.WriteData;
19 import org.opendaylight.controller.cluster.datastore.utils.ActorContext;
20 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
21 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24 import scala.concurrent.Future;
25
26 /**
27  * Implementation of TransactionContextImpl used when talking to a pre-Lithium controller that doesn't
28  * support the BatchedModifications message.
29  *
30  * @author Thomas Pantelis
31  */
32 @Deprecated
33 public class PreLithiumTransactionContextImpl extends RemoteTransactionContext {
34     private static final Logger LOG = LoggerFactory.getLogger(PreLithiumTransactionContextImpl.class);
35
36     private final String transactionPath;
37
38     public PreLithiumTransactionContextImpl(String transactionPath, ActorSelection actor, TransactionIdentifier identifier,
39             ActorContext actorContext, boolean isTxActorLocal,
40             short remoteTransactionVersion, OperationCompleter operationCompleter) {
41         super(actor, identifier, actorContext, isTxActorLocal, remoteTransactionVersion, operationCompleter);
42         this.transactionPath = transactionPath;
43     }
44
45     @Override
46     public void deleteData(YangInstanceIdentifier path) {
47         executeOperationAsync(new DeleteData(path, getRemoteTransactionVersion()));
48     }
49
50     @Override
51     public void mergeData(YangInstanceIdentifier path, NormalizedNode<?, ?> data) {
52         executeOperationAsync(new MergeData(path, data, getRemoteTransactionVersion()));
53     }
54
55     @Override
56     public void writeData(YangInstanceIdentifier path, NormalizedNode<?, ?> data) {
57         executeOperationAsync(new WriteData(path, data, getRemoteTransactionVersion()));
58     }
59
60     @Override
61     public Future<ActorSelection> readyTransaction() {
62         LOG.debug("Tx {} readyTransaction called", getIdentifier());
63
64         // Send the ReadyTransaction message to the Tx actor.
65
66         Future<Object> lastReplyFuture = executeOperationAsync(ReadyTransaction.INSTANCE);
67
68         return transformReadyReply(lastReplyFuture);
69     }
70
71     @Override
72     protected Future<ActorSelection> transformReadyReply(final Future<Object> readyReplyFuture) {
73         // In base Helium we used to return the local path of the actor which represented
74         // a remote ThreePhaseCommitCohort. The local path would then be converted to
75         // a remote path using this resolvePath method. To maintain compatibility with
76         // a Helium node we need to continue to do this conversion.
77         // At some point in the future when upgrades from Helium are not supported
78         // we could remove this code to resolvePath and just use the cohortPath as the
79         // resolved cohortPath
80         if (getRemoteTransactionVersion() < DataStoreVersions.HELIUM_1_VERSION) {
81             return PreLithiumTransactionReadyReplyMapper.transform(readyReplyFuture, getActorContext(), getIdentifier(), transactionPath);
82         } else {
83             return super.transformReadyReply(readyReplyFuture);
84         }
85     }
86
87     @Override
88     public boolean supportsDirectCommit() {
89         return false;
90     }
91
92     @Override
93     public Future<Object> directCommit() {
94         throw new UnsupportedOperationException("directCommit is not supported for " + getClass());
95     }
96 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.