+
+ @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(final @NonNull Shard shard) {
+ return new HashMap<>(Maps.transformValues(clients, meta -> meta.toLeaderState(shard)));
+ }
+
+ void disableTracking(final ClientIdentifier clientId) {
+ final FrontendIdentifier frontendId = clientId.getFrontendId();
+ final FrontendClientMetadataBuilder client = clients.get(frontendId);
+ if (client == null) {
+ // When we havent seen the client before, we still need to disable tracking for him since this only gets
+ // triggered once.
+ LOG.debug("{}: disableTracking {} does not match any client, pre-disabling client.", shardName, clientId);
+ clients.put(frontendId, new FrontendClientMetadataBuilder.Disabled(shardName, clientId));
+ return;
+ }
+ if (!clientId.equals(client.getIdentifier())) {
+ LOG.debug("{}: disableTracking {} does not match client {}, ignoring", shardName, clientId, client);
+ return;
+ }
+ if (client instanceof FrontendClientMetadataBuilder.Disabled) {
+ LOG.debug("{}: client {} is has already disabled tracking", shardName, client);
+ return;
+ }
+
+ verify(clients.replace(frontendId, client, new FrontendClientMetadataBuilder.Disabled(shardName, clientId)));
+ }
+
+ ImmutableSet<ClientIdentifier> getClients() {
+ return clients.values().stream()
+ .map(FrontendClientMetadataBuilder::getIdentifier)
+ .collect(ImmutableSet.toImmutableSet());
+ }