BUG-8056: make doCommit/finishCommit package-private
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / FrontendMetadata.java
index 6a04674b6ca2919c32b63a28e1b699a037d73cc1..5f86125523cb37fd0be72dc5157947d21a316f7c 100644 (file)
@@ -7,9 +7,12 @@
  */
 package org.opendaylight.controller.cluster.datastore;
 
+import com.google.common.base.Preconditions;
 import com.google.common.collect.Collections2;
+import com.google.common.collect.Maps;
 import java.util.HashMap;
 import java.util.Map;
+import javax.annotation.Nonnull;
 import javax.annotation.concurrent.NotThreadSafe;
 import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier;
 import org.opendaylight.controller.cluster.access.concepts.FrontendIdentifier;
@@ -32,6 +35,11 @@ final class FrontendMetadata extends ShardDataTreeMetadata<FrontendShardDataTree
     private static final Logger LOG = LoggerFactory.getLogger(FrontendMetadata.class);
 
     private final Map<FrontendIdentifier, FrontendClientMetadataBuilder> clients = new HashMap<>();
+    private final String shardName;
+
+    FrontendMetadata(final String shardName) {
+        this.shardName = Preconditions.checkNotNull(shardName);
+    }
 
     @Override
     Class<FrontendShardDataTreeSnapshotMetadata> getSupportedType() {
@@ -67,13 +75,18 @@ final class FrontendMetadata extends ShardDataTreeMetadata<FrontendShardDataTree
         final FrontendClientMetadataBuilder client = new FrontendClientMetadataBuilder(id);
         final FrontendClientMetadataBuilder previous = clients.put(id.getFrontendId(), client);
         if (previous != null) {
-            LOG.debug("Replaced client {} with {}", previous, client);
+            LOG.debug("{}: Replaced client {} with {}", shardName, previous, client);
         } else {
-            LOG.debug("Added client {}", client);
+            LOG.debug("{}: Added client {}", shardName, client);
         }
         return client;
     }
 
+    @Override
+    void onHistoryCreated(final LocalHistoryIdentifier historyId) {
+        ensureClient(historyId.getClientId()).onHistoryCreated(historyId);
+    }
+
     @Override
     void onHistoryClosed(final LocalHistoryIdentifier historyId) {
         ensureClient(historyId.getClientId()).onHistoryClosed(historyId);
@@ -84,8 +97,27 @@ final class FrontendMetadata extends ShardDataTreeMetadata<FrontendShardDataTree
         ensureClient(historyId.getClientId()).onHistoryPurged(historyId);
     }
 
+    @Override
+    void onTransactionAborted(final TransactionIdentifier txId) {
+        ensureClient(txId.getHistoryId().getClientId()).onTransactionAborted(txId);
+    }
+
     @Override
     void onTransactionCommitted(final TransactionIdentifier txId) {
         ensureClient(txId.getHistoryId().getClientId()).onTransactionCommitted(txId);
     }
+
+    @Override
+    void onTransactionPurged(final TransactionIdentifier txId) {
+        ensureClient(txId.getHistoryId().getClientId()).onTransactionPurged(txId);
+    }
+
+    /**
+     * Transform frontend metadata into an active leader state map.
+     *
+     * @return Leader frontend state
+     */
+    @Nonnull Map<FrontendIdentifier, LeaderFrontendState> toLeaderState(@Nonnull final Shard shard) {
+        return new HashMap<>(Maps.transformValues(clients, meta -> meta.toLeaderState(shard)));
+    }
 }