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 / legacy / sharded / adapter / LegacyShardedDOMDataBrokerAdapter.java
1 /*
2  * Copyright (c) 2016 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
9 package org.opendaylight.controller.md.sal.dom.broker.impl.legacy.sharded.adapter;
10
11 import static com.google.common.base.Preconditions.checkNotNull;
12
13 import java.util.Collections;
14 import java.util.Map;
15 import java.util.concurrent.atomic.AtomicLong;
16 import javax.annotation.Nonnull;
17 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
18 import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
19 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
20 import org.opendaylight.controller.md.sal.dom.api.DOMDataBrokerExtension;
21 import org.opendaylight.controller.md.sal.dom.api.DOMDataChangeListener;
22 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction;
23 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
24 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
25 import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
26 import org.opendaylight.controller.sal.core.api.model.SchemaService;
27 import org.opendaylight.mdsal.dom.broker.ShardedDOMDataBrokerAdapter;
28 import org.opendaylight.yangtools.concepts.ListenerRegistration;
29 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
30
31 /**
32  * DOMDataBroker implementation that forwards calls to
33  * {@link org.opendaylight.mdsal.dom.broker.ShardedDOMDataBrokerAdapter},
34  * which in turn translates calls to shard aware implementation of
35  * {@link org.opendaylight.mdsal.dom.api.DOMDataTreeService}
36  *
37  * <p>
38  * The incompatibility between first and latter APIs, puts restriction on {@link DOMDataReadWriteTransaction}
39  * and {@link DOMDataReadOnlyTransaction} provided by this data broker. See
40  * {@link ShardedDOMDataBrokerDelegatingReadWriteTransaction}
41  * and {@link ShardedDOMDataBrokerDelegatingReadTransaction} respectively.
42  */
43 // FIXME try to refactor some of the implementation to abstract class for better reusability
44 public class LegacyShardedDOMDataBrokerAdapter implements DOMDataBroker {
45
46     private final org.opendaylight.mdsal.dom.api.DOMDataBroker delegateDataBroker;
47     private final SchemaService schemaService;
48     private final AtomicLong txNum = new AtomicLong();
49     private final AtomicLong chainNum = new AtomicLong();
50
51     public LegacyShardedDOMDataBrokerAdapter(final ShardedDOMDataBrokerAdapter delegateDataBroker,
52                                              final SchemaService schemaService) {
53         this.delegateDataBroker = checkNotNull(delegateDataBroker);
54         this.schemaService = checkNotNull(schemaService);
55     }
56
57     @Override
58     public DOMDataReadOnlyTransaction newReadOnlyTransaction() {
59         return new ShardedDOMDataBrokerDelegatingReadTransaction(newTransactionIdentifier(),
60                                                                  delegateDataBroker.newReadOnlyTransaction());
61     }
62
63     @Override
64     public DOMDataReadWriteTransaction newReadWriteTransaction() {
65         return new ShardedDOMDataBrokerDelegatingReadWriteTransaction(newTransactionIdentifier(),
66                                                                       schemaService.getGlobalContext(),
67                                                                       newReadOnlyTransaction(),
68                                                                       newWriteOnlyTransaction());
69     }
70
71     @Override
72     public DOMDataWriteTransaction newWriteOnlyTransaction() {
73         return new ShardedDOMDataBrokerDelegatingWriteTransaction(newTransactionIdentifier(),
74                                                                   delegateDataBroker.newWriteOnlyTransaction());
75     }
76
77     @Override
78     public ListenerRegistration<DOMDataChangeListener> registerDataChangeListener(final LogicalDatastoreType store,
79                                                                                   final YangInstanceIdentifier path,
80                                                                                   final DOMDataChangeListener listener,
81                                                                                   final DataChangeScope
82                                                                                               triggeringScope) {
83         throw new UnsupportedOperationException(
84                 "Registering data change listeners is not supported in " + "md-sal forwarding data broker");
85
86     }
87
88     @Override
89     public DOMTransactionChain createTransactionChain(final TransactionChainListener listener) {
90         return new ShardedDOMDataBrokerDelegatingTransactionChain(chainNum.getAndIncrement(),
91                                                                   schemaService.getGlobalContext(), delegateDataBroker,
92                                                                   listener);
93     }
94
95     @Nonnull
96     @Override
97     public Map<Class<? extends DOMDataBrokerExtension>, DOMDataBrokerExtension> getSupportedExtensions() {
98         return Collections.emptyMap();
99     }
100
101     private Object newTransactionIdentifier() {
102         return "DOM-" + txNum.getAndIncrement();
103     }
104 }

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