forked from Azure/azure-sdk-for-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Iterating on FeedRange Api for Java SDK
- Loading branch information
1 parent
56519f4
commit 52e182a
Showing
5 changed files
with
143 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 36 additions & 6 deletions
42
...m/azure/cosmos/implementation/changefeed/implementation/ChangeFeedRequestOptionsImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,48 @@ | ||
package com.azure.cosmos.implementation.changefeed.implementation; | ||
|
||
import com.azure.cosmos.implementation.HttpConstants; | ||
import com.azure.cosmos.implementation.RxDocumentServiceRequest; | ||
import com.azure.cosmos.implementation.feedranges.FeedRangeInternal; | ||
import com.azure.cosmos.implementation.feedranges.FeedRangeRequestMessagePopulatorVisitor; | ||
import com.azure.cosmos.models.CosmosChangeFeedRequestOptions; | ||
import com.azure.cosmos.models.FeedRange; | ||
|
||
import java.time.Instant; | ||
|
||
public final class ChangeFeedRequestOptionsImpl { | ||
public static void populateRequestOptions( | ||
CosmosChangeFeedRequestOptions requestOptions, | ||
RxDocumentServiceRequest request, | ||
ChangeFeedStartFromInternal startFromInternal, | ||
FeedRangeInternal feedRange) | ||
{ | ||
// TODO fabianm - Implement | ||
FeedRangeInternal feedRange) { | ||
if (requestOptions == null) { | ||
throw new NullPointerException("requestOptions"); | ||
} | ||
|
||
if (request == null) { | ||
throw new NullPointerException("request"); | ||
} | ||
|
||
if (startFromInternal == null) { | ||
throw new NullPointerException("startFromInternal"); | ||
} | ||
|
||
final PopulateStartFromRequestOptionVisitor populateRequestOptionsVisitor = | ||
new PopulateStartFromRequestOptionVisitor(request); | ||
startFromInternal.accept(populateRequestOptionsVisitor); | ||
|
||
Integer maxItemCount = requestOptions.getMaxItemCount(); | ||
if (maxItemCount != null) { | ||
request.getHeaders().put( | ||
HttpConstants.HttpHeaders.PAGE_SIZE, | ||
maxItemCount.toString()); | ||
} | ||
|
||
if (feedRange != null) { | ||
final FeedRangeRequestMessagePopulatorVisitor feedRangeVisitor = | ||
new FeedRangeRequestMessagePopulatorVisitor(request); | ||
feedRange.accept(feedRangeVisitor); | ||
} | ||
|
||
request.getHeaders().put( | ||
HttpConstants.HttpHeaders.A_IM, | ||
HttpConstants.A_IMHeaderValues.INCREMENTAL_FEED); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
...osmos/implementation/changefeed/implementation/PopulateStartFromRequestOptionVisitor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.azure.cosmos.implementation.changefeed.implementation; | ||
|
||
import java.time.Instant; | ||
import java.time.format.DateTimeFormatter; | ||
|
||
import com.azure.cosmos.implementation.HttpConstants; | ||
import com.azure.cosmos.implementation.RxDocumentServiceRequest; | ||
|
||
class PopulateStartFromRequestOptionVisitor extends ChangeFeedStartFromVisitor { | ||
private static final long START_FROM_BEGINNING_EPOCH_SECONDS = -62135596800L; | ||
private static final Instant START_FROM_BEGINNING_TIME = | ||
Instant.ofEpochSecond(START_FROM_BEGINNING_EPOCH_SECONDS); | ||
|
||
private final RxDocumentServiceRequest request; | ||
|
||
public PopulateStartFromRequestOptionVisitor(final RxDocumentServiceRequest request) { | ||
if (request == null) { | ||
throw new NullPointerException("request"); | ||
} | ||
|
||
this.request = request; | ||
} | ||
|
||
@Override | ||
public void Visit(ChangeFeedStartFromNowImpl startFromNow) { | ||
this.request.getHeaders().put( | ||
HttpConstants.HttpHeaders.IF_NONE_MATCH, | ||
HttpConstants.HeaderValues.IF_NONE_MATCH_ALL); | ||
} | ||
|
||
@Override | ||
public void Visit(ChangeFeedStartFromPointInTimeImpl startFromTime) { | ||
// Our current public contract for ChangeFeedProcessor uses DateTime.MinValue.ToUniversalTime as beginning. | ||
// We need to add a special case here, otherwise it would send it as normal StartTime. | ||
// The problem is Multi master accounts do not support StartTime header on ReadFeed, and thus, | ||
// it would break multi master Change Feed Processor users using Start From Beginning semantics. | ||
// It's also an optimization, since the backend won't have to binary search for the value. | ||
Instant pointInTime = startFromTime.getPointInTime(); | ||
if (pointInTime != START_FROM_BEGINNING_TIME) | ||
{ | ||
this.request.getHeaders().put( | ||
HttpConstants.HttpHeaders.IF_MODIFIED_SINCE, | ||
DateTimeFormatter.RFC_1123_DATE_TIME.format(pointInTime)); | ||
} | ||
} | ||
|
||
@Override | ||
public void Visit(ChangeFeedStartFromContinuationImpl startFromContinuation) { | ||
// On REST level, change feed is using IfNoneMatch/ETag instead of continuation | ||
this.request.getHeaders().put( | ||
HttpConstants.HttpHeaders.IF_NONE_MATCH, | ||
startFromContinuation.getContinuation()); | ||
} | ||
|
||
@Override | ||
public void Visit(ChangeFeedStartFromBeginningImpl startFromBeginning) { | ||
// We don't need to set any headers to start from the beginning | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters