import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
-import com.google.common.base.Strings;
import java.util.AbstractMap.SimpleEntry;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import javax.annotation.concurrent.NotThreadSafe;
+import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier;
+import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
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;
import org.opendaylight.controller.md.sal.dom.store.impl.DataChangeListenerRegistration;
+import org.opendaylight.yangtools.concepts.Identifier;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
@NotThreadSafe
public class ShardDataTree extends ShardDataTreeTransactionParent {
private static final Logger LOG = LoggerFactory.getLogger(ShardDataTree.class);
- private static final YangInstanceIdentifier ROOT_PATH = YangInstanceIdentifier.builder().build();
- private final Map<String, ShardDataTreeTransactionChain> transactionChains = new HashMap<>();
+ private final Map<LocalHistoryIdentifier, ShardDataTreeTransactionChain> transactionChains = new HashMap<>();
private final ShardDataTreeChangeListenerPublisher treeChangeListenerPublisher;
private final ShardDataChangeListenerPublisher dataChangeListenerPublisher;
private final TipProducingDataTree dataTree;
dataTree.setSchemaContext(schemaContext);
}
- private ShardDataTreeTransactionChain ensureTransactionChain(final String chainId) {
- ShardDataTreeTransactionChain chain = transactionChains.get(chainId);
+ private ShardDataTreeTransactionChain ensureTransactionChain(final LocalHistoryIdentifier localHistoryIdentifier) {
+ ShardDataTreeTransactionChain chain = transactionChains.get(localHistoryIdentifier);
if (chain == null) {
- chain = new ShardDataTreeTransactionChain(chainId, this);
- transactionChains.put(chainId, chain);
+ chain = new ShardDataTreeTransactionChain(localHistoryIdentifier, this);
+ transactionChains.put(localHistoryIdentifier, chain);
}
return chain;
}
- ReadOnlyShardDataTreeTransaction newReadOnlyTransaction(final String txId, final String chainId) {
- if (Strings.isNullOrEmpty(chainId)) {
+ ReadOnlyShardDataTreeTransaction newReadOnlyTransaction(final TransactionIdentifier txId) {
+ if (txId.getHistoryId().getHistoryId() == 0) {
return new ReadOnlyShardDataTreeTransaction(txId, dataTree.takeSnapshot());
}
- return ensureTransactionChain(chainId).newReadOnlyTransaction(txId);
+ return ensureTransactionChain(txId.getHistoryId()).newReadOnlyTransaction(txId);
}
- ReadWriteShardDataTreeTransaction newReadWriteTransaction(final String txId, final String chainId) {
- if (Strings.isNullOrEmpty(chainId)) {
+ ReadWriteShardDataTreeTransaction newReadWriteTransaction(final TransactionIdentifier txId) {
+ if (txId.getHistoryId().getHistoryId() == 0) {
return new ReadWriteShardDataTreeTransaction(ShardDataTree.this, txId, dataTree.takeSnapshot()
.newModification());
}
- return ensureTransactionChain(chainId).newReadWriteTransaction(txId);
+ return ensureTransactionChain(txId.getHistoryId()).newReadWriteTransaction(txId);
}
public void notifyListeners(final DataTreeCandidate candidate) {
transactionChains.clear();
}
- void closeTransactionChain(final String transactionChainId) {
+ void closeTransactionChain(final LocalHistoryIdentifier transactionChainId) {
final ShardDataTreeTransactionChain chain = transactionChains.remove(transactionChainId);
if (chain != null) {
chain.close();
}
private Optional<DataTreeCandidate> readCurrentData() {
- final Optional<NormalizedNode<?, ?>> currentState = dataTree.takeSnapshot().readNode(ROOT_PATH);
+ final Optional<NormalizedNode<?, ?>> currentState = dataTree.takeSnapshot().readNode(YangInstanceIdentifier.EMPTY);
return currentState.isPresent() ? Optional.of(DataTreeCandidates.fromNormalizedNode(
- ROOT_PATH, currentState.get())) : Optional.<DataTreeCandidate>absent();
+ YangInstanceIdentifier.EMPTY, currentState.get())) : Optional.<DataTreeCandidate>absent();
}
public Entry<ListenerRegistration<DOMDataTreeChangeListener>, Optional<DataTreeCandidate>> registerTreeChangeListener(
return new SimpleEntry<>(reg, readCurrentData());
}
- void applyForeignCandidate(final String identifier, final DataTreeCandidate foreign) throws DataValidationFailedException {
+ void applyForeignCandidate(final Identifier identifier, final DataTreeCandidate foreign) throws DataValidationFailedException {
LOG.debug("{}: Applying foreign transaction {}", logContext, identifier);
final DataTreeModification mod = dataTree.takeSnapshot().newModification();
return dataTree.takeSnapshot().newModification();
}
+ // FIXME: This should be removed, it violates encapsulation
public DataTreeCandidate commit(DataTreeModification modification) throws DataValidationFailedException {
modification.ready();
dataTree.validate(modification);