Fix checkstyle issues in module sal-dom-broker
[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 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;
19
20 /**
21  * An implementation of a {@link DOMDataBroker}, which forwards most requests to a delegate.
22  *
23  * <p>
24  * Its interpretation of the API contract is somewhat looser, specifically it does not
25  * guarantee transaction ordering between transactions allocated directly from the broker
26  * and its transaction chains.
27  */
28 public final class PingPongDataBroker extends ForwardingDOMDataBroker implements AutoCloseable,
29         DOMDataTreeChangeService {
30     private final DOMDataBroker delegate;
31
32     /**
33      * Instantiate a new broker, backed by the the specified delegate
34      * {@link DOMDataBroker}.
35      *
36      * @param delegate Backend broker, may not be null.
37      */
38     public PingPongDataBroker(@Nonnull final DOMDataBroker delegate) {
39         this.delegate = Preconditions.checkNotNull(delegate);
40     }
41
42     @Override
43     protected DOMDataBroker delegate() {
44         return delegate;
45     }
46
47     @Override
48     public PingPongTransactionChain createTransactionChain(final TransactionChainListener listener) {
49         return new PingPongTransactionChain(delegate, listener);
50     }
51
52     @Override
53     public void close() {
54         // intentionally NOOP
55     }
56
57     @Override
58     public <L extends DOMDataTreeChangeListener> ListenerRegistration<L> registerDataTreeChangeListener(
59             final DOMDataTreeIdentifier treeId, final L listener) {
60         final DOMDataTreeChangeService treeService = (DOMDataTreeChangeService) delegate.getSupportedExtensions()
61                 .get(DOMDataTreeChangeService.class);
62         if (treeService != null) {
63             return treeService.registerDataTreeChangeListener(treeId, listener);
64         }
65
66         throw new UnsupportedOperationException("Delegate " + delegate + " does not support required functionality");
67     }
68
69     @Override
70     public String toString() {
71         return "PingPongDataBroker backed by " + delegate;
72     }
73 }

©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.