Skip to content

Commit

Permalink
Introduce common paged iteration API to sync APIs (#4480)
Browse files Browse the repository at this point in the history
PagedIterable and IterableResponse API for Sync Client
  • Loading branch information
hemanttanwar authored Aug 1, 2019
1 parent 60bec6e commit 2d30103
Show file tree
Hide file tree
Showing 13 changed files with 3,801 additions and 158 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -625,27 +625,10 @@ Mono<PagedResponse<ConfigurationSetting>> listSettingRevisionsNextPage(String ne
return result;
}

Flux<ConfigurationSetting> listSettingRevisions(SettingSelector selector, Context context) {
Mono<PagedResponse<ConfigurationSetting>> result;

if (selector != null) {
String fields = ImplUtils.arrayToString(selector.fields(), SettingFields::toStringMapper);
String keys = ImplUtils.arrayToString(selector.keys(), key -> key);
String labels = ImplUtils.arrayToString(selector.labels(), label -> label);
String range = selector.range() != null ? String.format(RANGE_QUERY, selector.range()) : null;

result = service.listKeyValueRevisions(serviceEndpoint, keys, labels, fields, selector.acceptDateTime(), range, context)
.doOnRequest(ignoredValue -> logger.info("Listing ConfigurationSetting revisions - {}", selector))
.doOnSuccess(response -> logger.info("Listed ConfigurationSetting revisions - {}", selector))
.doOnError(error -> logger.warning("Failed to list ConfigurationSetting revisions - {}", selector, error));
} else {
result = service.listKeyValueRevisions(serviceEndpoint, null, null, null, null, null, context)
.doOnRequest(ignoredValue -> logger.info("Listing ConfigurationSetting revisions"))
.doOnSuccess(response -> logger.info("Listed ConfigurationSetting revisions"))
.doOnError(error -> logger.warning("Failed to list all ConfigurationSetting revisions", error));
}

return result.flatMapMany(r -> extractAndFetchConfigurationSettings(r, context));
PagedFlux<ConfigurationSetting> listSettingRevisions(SettingSelector selector, Context context) {
return new PagedFlux<>(() ->
listSettingRevisionsFirstPage(selector, context),
continuationToken -> listSettingRevisionsNextPage(continuationToken, context));
}

private Flux<ConfigurationSetting> listSettings(String nextPageLink, Context context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

package com.azure.data.appconfiguration;

import com.azure.core.http.rest.PagedIterable;
import com.azure.core.implementation.annotation.ReturnType;
import com.azure.core.implementation.annotation.ServiceClient;
import com.azure.core.implementation.annotation.ServiceMethod;
Expand All @@ -15,7 +16,6 @@
import com.azure.core.http.rest.Response;
import com.azure.core.util.Context;


/**
* This class provides a client that contains all the operations for {@link ConfigurationSetting ConfigurationSettings}
* in Azure App Configuration Store. Operations allowed by the client are adding, retrieving, updating, and deleting
Expand Down Expand Up @@ -447,14 +447,14 @@ private Response<ConfigurationSetting> deleteSetting(ConfigurationSetting settin
*
* <p>Retrieve all settings that use the key "prodDBConnection".</p>
*
* {@codesnippet com.azure.data.applicationconfig.configurationclient.listSettings#SettingSelector}
* {@codesnippet com.azure.data.applicationconfig.configurationclient.listSettings#settingSelector}
*
* @param options Optional. Options to filter configuration setting results from the service.
* @return A List of ConfigurationSettings that matches the {@code options}. If no options were provided, the List
* @return A {@link PagedIterable} of ConfigurationSettings that matches the {@code options}. If no options were provided, the List
* contains all of the current settings in the service.
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
public Iterable<ConfigurationSetting> listSettings(SettingSelector options) {
public PagedIterable<ConfigurationSetting> listSettings(SettingSelector options) {
return listSettings(options, Context.NONE);
}

Expand All @@ -466,16 +466,16 @@ public Iterable<ConfigurationSetting> listSettings(SettingSelector options) {
*
* <p>Retrieve all settings that use the key "prodDBConnection".</p>
*
* {@codesnippet com.azure.data.applicationconfig.configurationclient.listSettings#SettingSelector-Context}
* {@codesnippet com.azure.data.applicationconfig.configurationclient.listSettings#settingSelector-context}
*
* @param options Optional. Options to filter configuration setting results from the service.
* @param context Additional context that is passed through the Http pipeline during the service call.
* @return A List of ConfigurationSettings that matches the {@code options}. If no options were provided, the List
* @return A {@link PagedIterable} of ConfigurationSettings that matches the {@code options}. If no options were provided, the {@link PagedIterable}
* contains all of the current settings in the service.
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
public Iterable<ConfigurationSetting> listSettings(SettingSelector options, Context context) {
return client.listSettings(options, context).collectList().block();
public PagedIterable<ConfigurationSetting> listSettings(SettingSelector options, Context context) {
return new PagedIterable<>(client.listSettings(options, context));
}

/**
Expand All @@ -490,13 +490,13 @@ public Iterable<ConfigurationSetting> listSettings(SettingSelector options, Cont
*
* <p>Retrieve all revisions of the setting that has the key "prodDBConnection".</p>
*
* {@codesnippet com.azure.data.applicationconfig.configurationclient.listSettingRevisions#SettingSelector}
* {@codesnippet com.azure.data.applicationconfig.configurationclient.listSettingRevisions#settingSelector}
*
* @param selector Optional. Used to filter configuration setting revisions from the service.
* @return Revisions of the ConfigurationSetting
* @return {@link PagedIterable} of {@link ConfigurationSetting} revisions.
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
public Iterable<ConfigurationSetting> listSettingRevisions(SettingSelector selector) {
public PagedIterable<ConfigurationSetting> listSettingRevisions(SettingSelector selector) {
return listSettingRevisions(selector, Context.NONE);
}

Expand All @@ -512,14 +512,14 @@ public Iterable<ConfigurationSetting> listSettingRevisions(SettingSelector selec
*
* <p>Retrieve all revisions of the setting that has the key "prodDBConnection".</p>
*
* {@codesnippet com.azure.data.applicationconfig.configurationclient.listSettingRevisions#SettingSelector-Context}
* {@codesnippet com.azure.data.applicationconfig.configurationclient.listSettingRevisions#settingSelector-context}
*
* @param selector Optional. Used to filter configuration setting revisions from the service.
* @param context Additional context that is passed through the Http pipeline during the service call.
* @return Revisions of the ConfigurationSetting
* @return {@link PagedIterable} of {@link ConfigurationSetting} revisions.
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
public Iterable<ConfigurationSetting> listSettingRevisions(SettingSelector selector, Context context) {
return client.listSettingRevisions(selector, context).collectList().block();
public PagedIterable<ConfigurationSetting> listSettingRevisions(SettingSelector selector, Context context) {
return new PagedIterable<>(client.listSettingRevisions(selector, context));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -275,45 +275,57 @@ public void deleteSetting() {
*/
public void listSettings() {
ConfigurationClient configurationClient = createSyncConfigurationClient();
// BEGIN: com.azure.data.applicationconfig.configurationclient.listSettings#SettingSelector
for (ConfigurationSetting setting : configurationClient.listSettings(new SettingSelector()
.keys("prodDBConnection"))) {
// BEGIN: com.azure.data.applicationconfig.configurationclient.listSettings#settingSelector
SettingSelector settingSelector = new SettingSelector().keys("prodDBConnection");
configurationClient.listSettings(settingSelector).forEach(setting -> {
System.out.printf("Key: %s, Value: %s", setting.key(), setting.value());
}
// END: com.azure.data.applicationconfig.configurationclient.listSettings#SettingSelector
});
// END: com.azure.data.applicationconfig.configurationclient.listSettings#settingSelector
}

/**
* Generates code sample for using {@link ConfigurationClient#listSettings(SettingSelector, Context)}
*/
// BEGIN: com.azure.data.applicationconfig.configurationclient.listSettings#SettingSelector-Context
for (ConfigurationSetting setting : configurationClient.listSettings(new SettingSelector()
.keys("prodDBConnection"), new Context(key1, value1))) {
/**
* Generates code sample for using {@link ConfigurationClient#listSettings(SettingSelector, Context)}
*/
public void listSettingsContext() {
ConfigurationClient configurationClient = createSyncConfigurationClient();
// BEGIN: com.azure.data.applicationconfig.configurationclient.listSettings#settingSelector-context
SettingSelector settingSelector = new SettingSelector().keys("prodDBConnection");
Context ctx = new Context(key2, value2);
configurationClient.listSettings(settingSelector, ctx).forEach(setting -> {
System.out.printf("Key: %s, Value: %s", setting.key(), setting.value());
}
// END: com.azure.data.applicationconfig.configurationclient.listSettings#SettingSelector-Context
});
// END: com.azure.data.applicationconfig.configurationclient.listSettings#settingSelector-context
}

/**
* Generates code sample for using {@link ConfigurationClient#listSettingRevisions(SettingSelector)}
*/
public void listSettingRevisions() {
ConfigurationClient configurationClient = createSyncConfigurationClient();
// BEGIN: com.azure.data.applicationconfig.configurationclient.listSettingRevisions#SettingSelector
for (ConfigurationSetting revision : configurationClient.listSettingRevisions(new SettingSelector()
.keys("prodDBConnection"))) {
System.out.printf("Key: %s, Value: %s", revision.key(), revision.value());
}
// END: com.azure.data.applicationconfig.configurationclient.listSettingRevisions#SettingSelector
ConfigurationClient client = createSyncConfigurationClient();
// BEGIN: com.azure.data.applicationconfig.configurationclient.listSettingRevisions#settingSelector
SettingSelector settingSelector = new SettingSelector().keys("prodDBConnection");
client.listSettingRevisions(settingSelector).streamByPage().forEach(resp -> {
System.out.printf("Response headers are %s. Url %s and status code %d %n", resp.headers(),
resp.request().url(), resp.statusCode());
resp.items().forEach(value -> {
System.out.printf("Response value is %d %n", value);
});
});
// END: com.azure.data.applicationconfig.configurationclient.listSettingRevisions#settingSelector
}

/**
* Generates code sample for using {@link ConfigurationClient#listSettingRevisions(SettingSelector, Context)}
*/
// BEGIN: com.azure.data.applicationconfig.configurationclient.listSettingRevisions#SettingSelector-Context
for (ConfigurationSetting revision : configurationClient.listSettingRevisions(new SettingSelector()
.keys("prodDBConnection"), new Context(key2, value2))) {
System.out.printf("Key: %s, Value: %s", revision.key(), revision.value());
}
// END: com.azure.data.applicationconfig.configurationclient.listSettingRevisions#SettingSelector-Context
/**
* Generates code sample for using {@link ConfigurationClient#listSettingRevisions(SettingSelector, Context)}
*/
public void listSettingRevisionsContext() {
ConfigurationClient configurationClient = createSyncConfigurationClient();
// BEGIN: com.azure.data.applicationconfig.configurationclient.listSettingRevisions#settingSelector-context
SettingSelector settingSelector = new SettingSelector().keys("prodDBConnection");
Context ctx = new Context(key2, value2);
configurationClient.listSettingRevisions(settingSelector, ctx).forEach(setting -> {
System.out.printf("Key: %s, Value: %s", setting.key(), setting.value());
});
// END: com.azure.data.applicationconfig.configurationclient.listSettingRevisions#settingSelector-context
}

/**
Expand Down
Loading

0 comments on commit 2d30103

Please sign in to comment.