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 com.google.common.base.Preconditions;
11 import javax.annotation.Nonnull;
12 import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
13 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
14 import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeListener;
15 import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService;
16 import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeIdentifier;
17 import org.opendaylight.controller.md.sal.dom.spi.ForwardingDOMDataBroker;
18 import org.opendaylight.yangtools.concepts.ListenerRegistration;
21 * An implementation of a {@link DOMDataBroker}, which forwards most requests to a delegate.
23 * Its interpretation of the API contract is somewhat looser, specifically it does not
24 * guarantee transaction ordering between transactions allocated directly from the broker
25 * and its transaction chains.
27 public final class PingPongDataBroker extends ForwardingDOMDataBroker implements AutoCloseable, DOMDataTreeChangeService {
28 private final DOMDataBroker delegate;
31 * Instantiate a new broker, backed by the the specified delegate
32 * {@link DOMDataBroker}.
34 * @param delegate Backend broker, may not be null.
36 public PingPongDataBroker(@Nonnull final DOMDataBroker delegate) {
37 this.delegate = Preconditions.checkNotNull(delegate);
41 protected DOMDataBroker delegate() {
46 public PingPongTransactionChain createTransactionChain(final TransactionChainListener listener) {
47 return new PingPongTransactionChain(delegate, listener);
56 public <L extends DOMDataTreeChangeListener> ListenerRegistration<L> registerDataTreeChangeListener(final DOMDataTreeIdentifier treeId, final L listener) {
57 final DOMDataTreeChangeService treeService =
58 (DOMDataTreeChangeService) delegate.getSupportedExtensions().get(DOMDataTreeChangeService.class);
59 if (treeService != null) {
60 return treeService.registerDataTreeChangeListener(treeId, listener);
63 throw new UnsupportedOperationException("Delegate " + delegate + " does not support required functionality");
67 public String toString() {
68 return "PingPongDataBroker backed by " + delegate;