BUG-5280: Close client history after all histories are closed
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / databroker / actors / dds / SingleClientHistory.java
index b57e9b669ea6770622dd2f5709b2ad4b5cf44782..7c3bba9756043c0b4bad67ede6f272cb1c813111 100644 (file)
@@ -7,7 +7,11 @@
  */
 package org.opendaylight.controller.cluster.databroker.actors.dds;
 
+import org.opendaylight.controller.cluster.access.client.AbstractClientConnection;
 import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier;
+import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * An {@link AbstractClientHistory} which handles free-standing transactions.
@@ -15,8 +19,31 @@ import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifie
  * @author Robert Varga
  */
 final class SingleClientHistory extends AbstractClientHistory {
-    protected SingleClientHistory(final DistributedDataStoreClientBehavior client,
-            final LocalHistoryIdentifier identifier) {
+    private static final Logger LOG = LoggerFactory.getLogger(AbstractClientHistory.class);
+
+    SingleClientHistory(final AbstractDataStoreClientBehavior client, final LocalHistoryIdentifier identifier) {
         super(client, identifier);
     }
+
+    @Override
+    ClientSnapshot doCreateSnapshot() {
+        final TransactionIdentifier txId = new TransactionIdentifier(getIdentifier(), nextTx());
+        LOG.debug("{}: creating a new snapshot {}", this, txId);
+
+        return new ClientSnapshot(this, txId);
+    }
+
+    @Override
+    ClientTransaction doCreateTransaction() {
+        final TransactionIdentifier txId = new TransactionIdentifier(getIdentifier(), nextTx());
+        LOG.debug("{}: creating a new transaction {}", this, txId);
+
+        return new ClientTransaction(this, txId);
+    }
+
+    @Override
+    ProxyHistory createHistoryProxy(final LocalHistoryIdentifier historyId,
+            final AbstractClientConnection<ShardBackendInfo> connection) {
+        return ProxyHistory.createSingle(this, connection, historyId);
+    }
 }