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.controller.sal.connect.netconf.sal.tx;
11 import com.google.common.base.Function;
12 import com.google.common.util.concurrent.ListenableFuture;
13 import org.opendaylight.controller.md.sal.dom.api.DOMRpcResult;
14 import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
15 import org.opendaylight.controller.sal.connect.netconf.listener.NetconfSessionPreferences;
16 import org.opendaylight.controller.sal.connect.netconf.util.NetconfBaseOps;
17 import org.opendaylight.controller.sal.connect.netconf.util.NetconfRpcFutureCallback;
18 import org.opendaylight.controller.sal.connect.util.RemoteDeviceId;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
23 * Tx implementation for netconf devices that support only candidate datastore and writable running
24 * The sequence goes exactly as with only candidate supported, with one addition:
26 * <li>Running datastore is locked as the first thing and this lock has to succeed</li>
29 public class WriteCandidateRunningTx extends WriteCandidateTx {
31 private static final Logger LOG = LoggerFactory.getLogger(WriteCandidateRunningTx.class);
33 public WriteCandidateRunningTx(final RemoteDeviceId id, final NetconfBaseOps netOps, final NetconfSessionPreferences netconfSessionPreferences) {
34 super(id, netOps, netconfSessionPreferences);
38 protected synchronized void init() {
44 protected void cleanupOnSuccess() {
45 super.cleanupOnSuccess();
49 private void lockRunning() {
51 invokeBlocking("Lock running", new Function<NetconfBaseOps, ListenableFuture<DOMRpcResult>>() {
53 public ListenableFuture<DOMRpcResult> apply(final NetconfBaseOps input) {
54 return input.lockRunning(new NetconfRpcFutureCallback("Lock running", id));
57 } catch (final NetconfDocumentedException e) {
58 LOG.warn("{}: Failed to lock running. Failed to initialize transaction", e);
60 throw new RuntimeException(id + ": Failed to lock running. Failed to initialize transaction", e);
65 * 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
67 private void unlockRunning() {
68 netOps.unlockRunning(new NetconfRpcFutureCallback("Unlock running", id));