Remove sal.core.api.model
[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.TransactionChainListener;
18 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
19 import org.opendaylight.controller.md.sal.dom.api.DOMDataBrokerExtension;
20 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction;
21 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
22 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
23 import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
24 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
25 import org.opendaylight.mdsal.dom.broker.ShardedDOMDataBrokerAdapter;
26
27 /**
28  * DOMDataBroker implementation that forwards calls to
29  * {@link org.opendaylight.mdsal.dom.broker.ShardedDOMDataBrokerAdapter},
30  * which in turn translates calls to shard aware implementation of
31  * {@link org.opendaylight.mdsal.dom.api.DOMDataTreeService}
32  *
33  * <p>
34  * The incompatibility between first and latter APIs, puts restriction on {@link DOMDataReadWriteTransaction}
35  * and {@link DOMDataReadOnlyTransaction} provided by this data broker. See
36  * {@link ShardedDOMDataBrokerDelegatingReadWriteTransaction}
37  * and {@link ShardedDOMDataBrokerDelegatingReadTransaction} respectively.
38  */
39 // FIXME try to refactor some of the implementation to abstract class for better reusability
40 public class LegacyShardedDOMDataBrokerAdapter implements DOMDataBroker {
41
42     private final org.opendaylight.mdsal.dom.api.DOMDataBroker delegateDataBroker;
43     private final DOMSchemaService schemaService;
44     private final AtomicLong txNum = new AtomicLong();
45     private final AtomicLong chainNum = new AtomicLong();
46
47     public LegacyShardedDOMDataBrokerAdapter(final ShardedDOMDataBrokerAdapter delegateDataBroker,
48                                              final DOMSchemaService schemaService) {
49         this.delegateDataBroker = checkNotNull(delegateDataBroker);
50         this.schemaService = checkNotNull(schemaService);
51     }
52
53     @Override
54     public DOMDataReadOnlyTransaction newReadOnlyTransaction() {
55         return new ShardedDOMDataBrokerDelegatingReadTransaction(newTransactionIdentifier(),
56                                                                  delegateDataBroker.newReadOnlyTransaction());
57     }
58
59     @Override
60     public DOMDataReadWriteTransaction newReadWriteTransaction() {
61         return new ShardedDOMDataBrokerDelegatingReadWriteTransaction(newTransactionIdentifier(),
62                                                                       schemaService.getGlobalContext(),
63                                                                       newReadOnlyTransaction(),
64                                                                       newWriteOnlyTransaction());
65     }
66
67     @Override
68     public DOMDataWriteTransaction newWriteOnlyTransaction() {
69         return new ShardedDOMDataBrokerDelegatingWriteTransaction(newTransactionIdentifier(),
70                                                                   delegateDataBroker.newWriteOnlyTransaction());
71     }
72
73     @Override
74     public DOMTransactionChain createTransactionChain(final TransactionChainListener listener) {
75         return new ShardedDOMDataBrokerDelegatingTransactionChain(chainNum.getAndIncrement(),
76                                                                   schemaService.getGlobalContext(), delegateDataBroker,
77                                                                   listener);
78     }
79
80     @Nonnull
81     @Override
82     public Map<Class<? extends DOMDataBrokerExtension>, DOMDataBrokerExtension> getSupportedExtensions() {
83         return Collections.emptyMap();
84     }
85
86     private Object newTransactionIdentifier() {
87         return "DOM-" + txNum.getAndIncrement();
88     }
89 }

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