// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. package com.multiclouddb.api.changefeed; import com.multiclouddb.api.MulticloudDbKey; import java.util.Objects; /** * Defines what slice of a collection's change feed a {@code readChanges} call * should consume. *

* Three variants: *

* *

This is a sealed interface — no third-party implementations. * Use {@code instanceof} pattern matching: *

{@code
 * switch (request.scope()) {
 *     case FeedScope.EntireCollection ec -> ...
 *     case FeedScope.PhysicalPartition(String id) -> ...
 *     case FeedScope.LogicalPartition(MulticloudDbKey key) -> ...
 * }
 * }
*/ public sealed interface FeedScope permits FeedScope.EntireCollection, FeedScope.PhysicalPartition, FeedScope.LogicalPartition { /** Read every change in the collection across every partition (default). */ static FeedScope entireCollection() { return EntireCollection.INSTANCE; } /** Read changes from a single provider-native physical partition. */ static FeedScope physicalPartition(String partitionId) { return new PhysicalPartition(partitionId); } /** * Filter the feed to a single logical partition key (Cosmos only). * Gated by {@link com.multiclouddb.api.Capability#CHANGE_FEED_LOGICAL_PARTITION_SCOPE}. */ static FeedScope logicalPartition(MulticloudDbKey key) { return new LogicalPartition(key); } /** Entire-collection scope (singleton). */ final class EntireCollection implements FeedScope { static final EntireCollection INSTANCE = new EntireCollection(); private EntireCollection() { } @Override public String toString() { return "FeedScope.EntireCollection"; } } /** * One provider-native physical partition. {@code partitionId} is opaque and * meaningful only against the same provider+resource that produced it. */ record PhysicalPartition(String partitionId) implements FeedScope { public PhysicalPartition { Objects.requireNonNull(partitionId, "partitionId"); if (partitionId.isBlank()) { throw new IllegalArgumentException("partitionId must be non-blank"); } } } /** Single logical partition key (Cosmos only — capability-gated). */ record LogicalPartition(MulticloudDbKey partitionKey) implements FeedScope { public LogicalPartition { Objects.requireNonNull(partitionKey, "partitionKey"); } } }