Allow programmatic module sharding configuration
[controller.git] / opendaylight / md-sal / sal-dom-broker / src / main / java / org / opendaylight / controller / md / sal / dom / broker / impl / PingPongDataBroker.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.md.sal.dom.broker.impl;
9
10 import static java.util.Objects.requireNonNull;
11
12 import org.eclipse.jdt.annotation.NonNull;
13 import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
14 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
15 import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeListener;
16 import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService;
17 import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeIdentifier;
18 import org.opendaylight.controller.md.sal.dom.spi.ForwardingDOMDataBroker;
19 import org.opendaylight.yangtools.concepts.ListenerRegistration;
20
21 /**
22  * An implementation of a {@link DOMDataBroker}, which forwards most requests to a delegate.
23  *
24  * <p>
25  * Its interpretation of the API contract is somewhat looser, specifically it does not
26  * guarantee transaction ordering between transactions allocated directly from the broker
27  * and its transaction chains.
28  */
29 @Deprecated(forRemoval = true)
30 public final class PingPongDataBroker extends ForwardingDOMDataBroker implements AutoCloseable,
31         DOMDataTreeChangeService {
32     private final DOMDataBroker delegate;
33
34     /**
35      * Instantiate a new broker, backed by the the specified delegate
36      * {@link DOMDataBroker}.
37      *
38      * @param delegate Backend broker, may not be null.
39      */
40     public PingPongDataBroker(final @NonNull DOMDataBroker delegate) {
41         this.delegate = requireNonNull(delegate);
42     }
43
44     @Override
45     protected DOMDataBroker delegate() {
46         return delegate;
47     }
48
49     @Override
50     public PingPongTransactionChain createTransactionChain(final TransactionChainListener listener) {
51         return new PingPongTransactionChain(delegate, listener);
52     }
53
54     @Override
55     public void close() {
56         // intentionally NOOP
57     }
58
59     @Override
60     public <L extends DOMDataTreeChangeListener> ListenerRegistration<L> registerDataTreeChangeListener(
61             final DOMDataTreeIdentifier treeId, final L listener) {
62         final DOMDataTreeChangeService treeService = (DOMDataTreeChangeService) delegate.getSupportedExtensions()
63                 .get(DOMDataTreeChangeService.class);
64         if (treeService != null) {
65             return treeService.registerDataTreeChangeListener(treeId, listener);
66         }
67
68         throw new UnsupportedOperationException("Delegate " + delegate + " does not support required functionality");
69     }
70
71     @Override
72     public String toString() {
73         return "PingPongDataBroker backed by " + delegate;
74     }
75 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.