2 * Copyright (c) 2014 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
9 package org.opendaylight.netconf.sal.connect.netconf.sal.tx;
11 import com.google.common.util.concurrent.FutureCallback;
12 import org.opendaylight.controller.md.sal.dom.api.DOMRpcResult;
13 import org.opendaylight.netconf.sal.connect.netconf.util.NetconfBaseOps;
14 import org.opendaylight.netconf.sal.connect.netconf.util.NetconfRpcFutureCallback;
15 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
20 * Tx implementation for netconf devices that support only candidate datastore and writable running
21 * The sequence goes exactly as with only candidate supported, with one addition:
23 * <li>Running datastore is locked as the first thing and this lock has to succeed</li>
26 public class WriteCandidateRunningTx extends WriteCandidateTx {
28 private static final Logger LOG = LoggerFactory.getLogger(WriteCandidateRunningTx.class);
30 public WriteCandidateRunningTx(final RemoteDeviceId id, final NetconfBaseOps netOps, final boolean rollbackSupport) {
31 super(id, netOps, rollbackSupport);
35 protected synchronized void init() {
41 protected void cleanupOnSuccess() {
42 super.cleanupOnSuccess();
46 private void lockRunning() {
47 final FutureCallback<DOMRpcResult> lockRunningCallback = new FutureCallback<DOMRpcResult>() {
49 public void onSuccess(DOMRpcResult result) {
50 if (isSuccess(result)) {
51 if (LOG.isTraceEnabled()) {
52 LOG.trace("Lock running succesfull");
55 LOG.warn("{}: lock running invoked unsuccessfully: {}", id, result.getErrors());
60 public void onFailure(Throwable t) {
61 LOG.warn("{}: Failed to lock running. Failed to initialize transaction", id, t);
62 throw new RuntimeException(id + ": Failed to lock running. Failed to initialize transaction", t);
65 netOps.lockRunning(lockRunningCallback);
69 * This has to be non blocking since it is called from a callback on commit and its netty threadpool that is really sensitive to blocking calls
71 private void unlockRunning() {
72 netOps.unlockRunning(new NetconfRpcFutureCallback("Unlock running", id));