2 * Copyright (c) 2015 Brocade Communications 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.datastore.compat;
10 import akka.actor.ActorSelection;
11 import org.opendaylight.controller.cluster.datastore.DataStoreVersions;
12 import org.opendaylight.controller.cluster.datastore.OperationLimiter;
13 import org.opendaylight.controller.cluster.datastore.RemoteTransactionContext;
14 import org.opendaylight.controller.cluster.datastore.messages.DeleteData;
15 import org.opendaylight.controller.cluster.datastore.messages.MergeData;
16 import org.opendaylight.controller.cluster.datastore.messages.ReadyTransaction;
17 import org.opendaylight.controller.cluster.datastore.messages.WriteData;
18 import org.opendaylight.controller.cluster.datastore.utils.ActorContext;
19 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
20 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23 import scala.concurrent.Future;
26 * Implementation of TransactionContextImpl used when talking to a pre-Lithium controller that doesn't
27 * support the BatchedModifications message.
29 * @author Thomas Pantelis
32 public class PreLithiumTransactionContextImpl extends RemoteTransactionContext {
33 private static final Logger LOG = LoggerFactory.getLogger(PreLithiumTransactionContextImpl.class);
35 private final String transactionPath;
37 public PreLithiumTransactionContextImpl(String transactionPath, ActorSelection actor,
38 ActorContext actorContext, boolean isTxActorLocal,
39 short remoteTransactionVersion, OperationLimiter limiter) {
40 super(actor, actorContext, isTxActorLocal, remoteTransactionVersion, limiter);
41 this.transactionPath = transactionPath;
45 public void deleteData(YangInstanceIdentifier path) {
46 executeOperationAsync(new DeleteData(path, getRemoteTransactionVersion()));
50 public void mergeData(YangInstanceIdentifier path, NormalizedNode<?, ?> data) {
51 executeOperationAsync(new MergeData(path, data, getRemoteTransactionVersion()));
55 public void writeData(YangInstanceIdentifier path, NormalizedNode<?, ?> data) {
56 executeOperationAsync(new WriteData(path, data, getRemoteTransactionVersion()));
60 public Future<ActorSelection> readyTransaction() {
61 LOG.debug("Tx {} readyTransaction called", getIdentifier());
63 // Send the ReadyTransaction message to the Tx actor.
65 Future<Object> lastReplyFuture = executeOperationAsync(ReadyTransaction.INSTANCE);
67 return transformReadyReply(lastReplyFuture);
71 protected Future<ActorSelection> transformReadyReply(final Future<Object> readyReplyFuture) {
72 // In base Helium we used to return the local path of the actor which represented
73 // a remote ThreePhaseCommitCohort. The local path would then be converted to
74 // a remote path using this resolvePath method. To maintain compatibility with
75 // a Helium node we need to continue to do this conversion.
76 // At some point in the future when upgrades from Helium are not supported
77 // we could remove this code to resolvePath and just use the cohortPath as the
78 // resolved cohortPath
79 if (getRemoteTransactionVersion() < DataStoreVersions.HELIUM_1_VERSION) {
80 return PreLithiumTransactionReadyReplyMapper.transform(readyReplyFuture, getActorContext(), getIdentifier(), transactionPath);
82 return super.transformReadyReply(readyReplyFuture);
87 public boolean supportsDirectCommit() {
92 public Future<Object> directCommit() {
93 throw new UnsupportedOperationException("directCommit is not supported for " + getClass());