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
8 package org.opendaylight.controller.md.sal.dom.broker.impl;
10 import static com.google.common.base.Preconditions.checkArgument;
11 import static java.util.Objects.requireNonNull;
13 import java.util.Collection;
15 import org.opendaylight.controller.md.sal.common.api.data.AsyncTransaction;
16 import org.opendaylight.controller.sal.core.spi.data.DOMStoreTransaction;
17 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
18 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
21 * Composite DOM Transaction backed by {@link DOMStoreTransaction}.
24 * Abstract base for composite transaction, which provides access only to common
25 * functionality as retrieval of subtransaction, close method and retrieval of
29 * Subtransaction distinguisher
33 @Deprecated(forRemoval = true)
34 abstract class AbstractDOMForwardedCompositeTransaction<K, T extends DOMStoreTransaction> implements
35 AsyncTransaction<YangInstanceIdentifier, NormalizedNode<?, ?>> {
37 private final Map<K, T> backingTxs;
38 private final Object identifier;
41 * Creates new composite Transactions.
44 * Identifier of transaction.
46 * Key,value map of backing transactions.
48 protected AbstractDOMForwardedCompositeTransaction(final Object identifier, final Map<K, T> backingTxs) {
49 this.identifier = requireNonNull(identifier, "Identifier should not be null");
50 this.backingTxs = requireNonNull(backingTxs, "Backing transactions should not be null");
54 * Returns subtransaction associated with supplied key.
57 * @return subtransaction
58 * @throws NullPointerException
60 * @throws IllegalArgumentException
61 * if no subtransaction is associated with key.
63 protected final T getSubtransaction(final K key) {
64 final T ret = backingTxs.get(requireNonNull(key, "key must not be null."));
65 checkArgument(ret != null, "No subtransaction associated with %s", key);
70 * Returns immutable Iterable of all subtransactions.
73 protected Collection<T> getSubtransactions() {
74 return backingTxs.values();
78 public Object getIdentifier() {
82 @SuppressWarnings("checkstyle:IllegalCatch")
83 protected void closeSubtransactions() {
85 * We share one exception for all failures, which are added
86 * as supressedExceptions to it.
88 IllegalStateException failure = null;
89 for (T subtransaction : backingTxs.values()) {
91 subtransaction.close();
92 } catch (Exception e) {
93 // If we did not allocated failure we allocate it
94 if (failure == null) {
95 failure = new IllegalStateException("Uncaught exception occured during closing transaction", e);
97 // We update it with additional exceptions, which occurred during error.
98 failure.addSuppressed(e);
102 // If we have failure, we throw it at after all attempts to close.
103 if (failure != null) {