- void onHistoryClosed(final LocalHistoryIdentifier historyId) {
- final FrontendHistoryMetadataBuilder builder = currentHistories.get(historyId);
- if (builder != null) {
- builder.onHistoryClosed();
- LOG.debug("{}: Closed history {}", shardName, historyId);
- } else {
- LOG.warn("{}: Closed unknown history {}, ignoring", shardName, historyId);
+ Enabled(final String shardName, final FrontendClientMetadata meta) {
+ super(shardName, meta.clientId());
+
+ purgedHistories = meta.getPurgedHistories().mutableCopy();
+ for (var historyMeta : meta.getCurrentHistories()) {
+ final var builder = new FrontendHistoryMetadataBuilder(clientId(), historyMeta);
+ currentHistories.put(builder.getIdentifier(), builder);
+ }
+
+ // Sanity check and recovery
+ standaloneId = standaloneHistoryId();
+ if (!currentHistories.containsKey(standaloneId)) {
+ LOG.warn("{}: Client {} recovered histories {} do not contain stand-alone history, attempting recovery",
+ shardName, clientId(), currentHistories);
+ currentHistories.put(standaloneId, new FrontendHistoryMetadataBuilder(standaloneId));
+ }
+ }
+
+ @Override
+ FrontendClientMetadata build() {
+ return new FrontendClientMetadata(clientId(), purgedHistories.immutableCopy(),
+ Collections2.transform(currentHistories.values(), FrontendHistoryMetadataBuilder::build));
+ }
+
+ @Override
+ void onHistoryCreated(final LocalHistoryIdentifier historyId) {
+ final var newMeta = new FrontendHistoryMetadataBuilder(historyId);
+ final var oldMeta = currentHistories.putIfAbsent(historyId, newMeta);
+ if (oldMeta != null) {
+ // This should not be happening, warn about it
+ LOG.warn("{}: Reused local history {}", shardName(), historyId);
+ } else {
+ LOG.debug("{}: Created local history {}", shardName(), historyId);
+ }
+ }
+
+ @Override
+ void onHistoryClosed(final LocalHistoryIdentifier historyId) {
+ final var builder = currentHistories.get(historyId);
+ if (builder != null) {
+ builder.onHistoryClosed();
+ LOG.debug("{}: Closed history {}", shardName(), historyId);
+ } else {
+ LOG.warn("{}: Closed unknown history {}, ignoring", shardName(), historyId);
+ }