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 //TODO replace custom RPCs future callbacks with NetconfRpcFutureCallback
27 public class WriteCandidateRunningTx extends WriteCandidateTx {
29 private static final Logger LOG = LoggerFactory.getLogger(WriteCandidateRunningTx.class);
31 public WriteCandidateRunningTx(final RemoteDeviceId id, final NetconfBaseOps netOps, final boolean rollbackSupport) {
32 super(id, netOps, rollbackSupport);
36 protected synchronized void init() {
42 protected void cleanupOnSuccess() {
43 super.cleanupOnSuccess();
47 private void lockRunning() {
48 final FutureCallback<DOMRpcResult> lockRunningCallback = new FutureCallback<DOMRpcResult>() {
50 public void onSuccess(DOMRpcResult result) {
51 if (isSuccess(result)) {
52 if (LOG.isTraceEnabled()) {
53 LOG.trace("Lock running succesfull");
56 LOG.warn("{}: lock running invoked unsuccessfully: {}", id, result.getErrors());
61 public void onFailure(Throwable t) {
62 LOG.warn("{}: Failed to lock running. Failed to initialize transaction", id, t);
65 resultsFutures.add(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));