Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add digital twin lifecycle sample #14744

Merged
merged 3 commits into from
Sep 2, 2020
Merged

Conversation

abhipsaMisra
Copy link
Member

@abhipsaMisra abhipsaMisra commented Sep 2, 2020

Add code for sample cleanup and creation of digital twin.

TODO:

  • Snippets
  • readme

@abhipsaMisra abhipsaMisra changed the title Feature/adt/abmisr/twin sample Add digital twin lifecycle sample Sep 2, 2020
.forEach((twinId, twinContent) -> {
// Call APIs to delete all relationships.
client.listRelationships(twinId, BasicRelationship.class)
.doOnComplete(deleteRelationshipsSemaphore::release)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This runnable is executed when the flux completes successfully.

// Call APIs to delete all relationships.
client.listRelationships(twinId, BasicRelationship.class)
.doOnComplete(deleteRelationshipsSemaphore::release)
.doOnError(throwable -> {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is executed when the flux completes with an error

@@ -6,7 +6,9 @@
import com.azure.core.http.policy.HttpLogDetailLevel;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should have an Async Suffix in the file name to indicate that we are using Async APIs for this sample.

public static void createTwins() throws IOException, InterruptedException {
System.out.println("CREATE DIGITAL TWINS");
Map<String, String> twins = FileHelper.loadAllFilesInPath(TwinsPath);
final Semaphore createTwinsSemaphore = new Semaphore(0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To understand why do we need semaphore here? Do we have some limitations for parallel operations?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, not really. The semaphore is to ensure that we do not exit before the async operation has completed. We start all async operations and then release the semaphore only once the async call has completed.
That way, the subsequent operations are executed after the previous call has completed -> similar to doing a await on a Task.

@abhipsaMisra abhipsaMisra merged commit dc4f2ba into master Sep 2, 2020
@abhipsaMisra abhipsaMisra deleted the feature/adt/abmisr/twinSample branch September 2, 2020 23:52
openapi-sdkautomation bot pushed a commit to AzureSDKAutomation/azure-sdk-for-java that referenced this pull request Jun 15, 2021
Update ReplicationLinks.json in 2021-02-01-preview (Azure#14744)

* update ReplicationLinks.json in 2021-02-01-preview

* update json file

* update examples/ReplicationLinkGet.json
openapi-sdkautomation bot pushed a commit to AzureSDKAutomation/azure-sdk-for-java that referenced this pull request Jun 17, 2021
Update ReplicationLinks.json in 2021-02-01-preview (Azure#14744)

* update ReplicationLinks.json in 2021-02-01-preview

* update json file

* update examples/ReplicationLinkGet.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants