*/
package org.opendaylight.controller.cluster.datastore;
-import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
-import java.net.URI;
import java.util.AbstractMap.SimpleEntry;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
-import java.util.Set;
import javax.annotation.concurrent.NotThreadSafe;
-import org.opendaylight.controller.cluster.datastore.node.utils.transformer.NormalizedNodePruner;
import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeListener;
import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeListener;
* This class is not part of the API contract and is subject to change at any time.
*/
@NotThreadSafe
-public final class ShardDataTree extends ShardDataTreeTransactionParent {
+public class ShardDataTree extends ShardDataTreeTransactionParent {
private static final Logger LOG = LoggerFactory.getLogger(ShardDataTree.class);
private static final ShardDataTreeNotificationManager MANAGER = new ShardDataTreeNotificationManager();
private final Map<String, ShardDataTreeTransactionChain> transactionChains = new HashMap<>();
private final ShardDataTreeChangePublisher treeChangePublisher = new ShardDataTreeChangePublisher();
private final ListenerTree listenerTree = ListenerTree.create();
private final TipProducingDataTree dataTree;
- private Set<URI> validNamespaces;
- private ShardDataTreeTransactionFactory transactionFactory = new RecoveryShardDataTreeTransactionFactory();
+ private SchemaContext schemaContext;
- ShardDataTree(final SchemaContext schemaContext) {
+ public ShardDataTree(final SchemaContext schemaContext) {
dataTree = InMemoryDataTreeFactory.getInstance().create();
updateSchemaContext(schemaContext);
}
- TipProducingDataTree getDataTree() {
+ public TipProducingDataTree getDataTree() {
return dataTree;
}
+ SchemaContext getSchemaContext() {
+ return schemaContext;
+ }
+
void updateSchemaContext(final SchemaContext schemaContext) {
Preconditions.checkNotNull(schemaContext);
+ this.schemaContext = schemaContext;
dataTree.setSchemaContext(schemaContext);
- validNamespaces = NormalizedNodePruner.namespaces(schemaContext);
}
private ShardDataTreeTransactionChain ensureTransactionChain(final String chainId) {
ReadOnlyShardDataTreeTransaction newReadOnlyTransaction(final String txId, final String chainId) {
if (Strings.isNullOrEmpty(chainId)) {
- return transactionFactory.newReadOnlyTransaction(txId, chainId);
+ return new ReadOnlyShardDataTreeTransaction(txId, dataTree.takeSnapshot());
}
return ensureTransactionChain(chainId).newReadOnlyTransaction(txId);
ReadWriteShardDataTreeTransaction newReadWriteTransaction(final String txId, final String chainId) {
if (Strings.isNullOrEmpty(chainId)) {
- return transactionFactory.newReadWriteTransaction(txId, chainId);
+ return new ReadWriteShardDataTreeTransaction(ShardDataTree.this, txId, dataTree.takeSnapshot()
+ .newModification());
}
return ensureTransactionChain(chainId).newReadWriteTransaction(txId);
}
- void notifyListeners(final DataTreeCandidate candidate) {
+ public void notifyListeners(final DataTreeCandidate candidate) {
LOG.debug("Notifying listeners on candidate {}", candidate);
// DataTreeChanges first, as they are more light-weight
return new SimpleEntry<>(reg, event);
}
- Entry<ListenerRegistration<DOMDataTreeChangeListener>, DataTreeCandidate> registerTreeChangeListener(final YangInstanceIdentifier path,
+ public Entry<ListenerRegistration<DOMDataTreeChangeListener>, DataTreeCandidate> registerTreeChangeListener(final YangInstanceIdentifier path,
final DOMDataTreeChangeListener listener) {
final ListenerRegistration<DOMDataTreeChangeListener> reg = treeChangePublisher.registerTreeChangeListener(path, listener);
ShardDataTreeCohort finishTransaction(final ReadWriteShardDataTreeTransaction transaction) {
final DataTreeModification snapshot = transaction.getSnapshot();
snapshot.ready();
- return new SimpleShardDataTreeCohort(this, snapshot);
- }
-
- void recoveryDone(){
- transactionFactory = new RegularShardDataTreeTransactionFactory();
- }
-
- @VisibleForTesting
- ShardDataTreeTransactionFactory getTransactionFactory(){
- return transactionFactory;
- }
-
- @VisibleForTesting
- static interface ShardDataTreeTransactionFactory {
- ReadOnlyShardDataTreeTransaction newReadOnlyTransaction(final String txId, final String chainId);
-
- ReadWriteShardDataTreeTransaction newReadWriteTransaction(final String txId, final String chainId);
- }
-
- @VisibleForTesting
- class RecoveryShardDataTreeTransactionFactory implements ShardDataTreeTransactionFactory {
-
- @Override
- public ReadOnlyShardDataTreeTransaction newReadOnlyTransaction(String txId, String chainId) {
- return new ReadOnlyShardDataTreeTransaction(txId,
- new ShardDataTreeSnapshot(dataTree.takeSnapshot(), validNamespaces));
- }
-
- @Override
- public ReadWriteShardDataTreeTransaction newReadWriteTransaction(String txId, String chainId) {
- return new ReadWriteShardDataTreeTransaction(ShardDataTree.this, txId,
- new ShardDataTreeSnapshot(dataTree.takeSnapshot(), validNamespaces).newModification());
- }
- }
-
- @VisibleForTesting
- class RegularShardDataTreeTransactionFactory implements ShardDataTreeTransactionFactory {
-
- @Override
- public ReadOnlyShardDataTreeTransaction newReadOnlyTransaction(String txId, String chainId) {
- return new ReadOnlyShardDataTreeTransaction(txId, dataTree.takeSnapshot());
-
- }
-
- @Override
- public ReadWriteShardDataTreeTransaction newReadWriteTransaction(String txId, String chainId) {
- return new ReadWriteShardDataTreeTransaction(ShardDataTree.this, txId, dataTree.takeSnapshot()
- .newModification());
- }
+ return new SimpleShardDataTreeCohort(this, snapshot, transaction.getId());
}
}