b825a1a6bb67b8d166766b069f79c576e699b3e3
[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 /**
33  * DOMDataBroker implementation that forwards calls to {@link org.opendaylight.mdsal.dom.broker.ShardedDOMDataBrokerAdapter},
34  * which in turn translates calls to shard aware implementation of {@link org.opendaylight.mdsal.dom.api.DOMDataTreeService}
35  * <p>
36  * The incompatibility between first and latter APIs, puts restriction on {@link DOMDataReadWriteTransaction}
37  * and {@link DOMDataReadOnlyTransaction} provided by this data broker. See {@link ShardedDOMDataBrokerDelegatingReadWriteTransaction}
38  * and {@link ShardedDOMDataBrokerDelegatingReadTransaction} respectively.
39  */
40 // FIXME try to refactor some of the implementation to abstract class for better reusability
41 public class LegacyShardedDOMDataBrokerAdapter implements DOMDataBroker {
42
43     private final org.opendaylight.mdsal.dom.api.DOMDataBroker delegateDataBroker;
44     private final SchemaService schemaService;
45     private final AtomicLong txNum = new AtomicLong();
46     private final AtomicLong chainNum = new AtomicLong();
47
48     public LegacyShardedDOMDataBrokerAdapter(final ShardedDOMDataBrokerAdapter delegateDataBroker,
49                                              final SchemaService schemaService) {
50         this.delegateDataBroker = checkNotNull(delegateDataBroker);
51         this.schemaService = checkNotNull(schemaService);
52     }
53
54     @Override
55     public DOMDataReadOnlyTransaction newReadOnlyTransaction() {
56         return new ShardedDOMDataBrokerDelegatingReadTransaction(newTransactionIdentifier(),
57                 delegateDataBroker.newReadOnlyTransaction());
58     }
59
60     @Override
61     public DOMDataReadWriteTransaction newReadWriteTransaction() {
62         return new ShardedDOMDataBrokerDelegatingReadWriteTransaction(newTransactionIdentifier(), schemaService.getGlobalContext(),
63                 newReadOnlyTransaction(), newWriteOnlyTransaction());
64     }
65
66     @Override
67     public DOMDataWriteTransaction newWriteOnlyTransaction() {
68         return new ShardedDOMDataBrokerDelegatingWriteTransaction(newTransactionIdentifier(),
69                 delegateDataBroker.newWriteOnlyTransaction());
70     }
71
72     @Override
73     public ListenerRegistration<DOMDataChangeListener> registerDataChangeListener(final LogicalDatastoreType store,
74                                                                                   final YangInstanceIdentifier path,
75                                                                                   final DOMDataChangeListener listener,
76                                                                                   final DataChangeScope triggeringScope) {
77         throw new UnsupportedOperationException("Registering data change listeners is not supported in " +
78                 "md-sal forwarding data broker");
79
80     }
81
82     @Override
83     public DOMTransactionChain createTransactionChain(final TransactionChainListener listener) {
84         return new ShardedDOMDataBrokerDelegatingTransactionChain(chainNum.getAndIncrement(), schemaService.getGlobalContext(),
85                 delegateDataBroker, listener);
86     }
87
88     @Nonnull
89     @Override
90     public Map<Class<? extends DOMDataBrokerExtension>, DOMDataBrokerExtension> getSupportedExtensions() {
91         return Collections.emptyMap();
92     }
93
94     private Object newTransactionIdentifier() {
95         return "DOM-" + txNum.getAndIncrement();
96     }
97 }

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