1414import software .amazon .awssdk .services .iot .model .CreateThingRequest ;
1515import software .amazon .awssdk .services .iot .model .ResourceAlreadyExistsException ;
1616import software .amazon .awssdk .services .iotfleetwise .IoTFleetWiseAsyncClient ;
17+ import software .amazon .awssdk .services .iotfleetwise .model .Node ;
1718import software .amazon .awssdk .services .iotfleetwise .model .*;
1819import java .time .Duration ;
1920import java .util .HashMap ;
@@ -56,8 +57,9 @@ private static IoTFleetWiseAsyncClient getAsyncClient() {
5657 }
5758
5859 // snippet-start:[iotfleetwise.java2.create.catalog.main]
60+
5961 /**
60- * Creates a signal catalog asynchronously .
62+ * Creates a signal catalog.
6163 *
6264 * @param signalCatalogName the name of the signal catalog to be created
6365 * @return a {@link CompletableFuture} that completes with the Amazon Resource Name (ARN) of the created signal catalog
@@ -106,7 +108,7 @@ public CompletableFuture<String> createSignalCatalogAsync(String signalCatalogNa
106108 .whenComplete ((response , exception ) -> {
107109 if (exception != null ) {
108110 Throwable cause = exception .getCause ();
109- if (cause instanceof software .amazon .awssdk .services .iot .model .ValidationException ) {
111+ if (cause instanceof software .amazon .awssdk .services .iotfleetwise .model .ValidationException ) {
110112 throw new CompletionException ("A validation error occurred: " + cause .getMessage (), cause );
111113 }
112114 throw new CompletionException ("Error performing place search" , exception );
@@ -135,14 +137,15 @@ private static CompletableFuture<Void> delayAsync(long millis) {
135137 }
136138
137139 // snippet-start:[iotfleetwise.java2.delete.catalog.main]
140+
138141 /**
139- * Deletes the specified signal catalog asynchronously, if it exists .
142+ * Deletes the specified signal catalog.
140143 *
141144 * @param signalCatalogName the name of the signal catalog to delete
142145 * @return a {@link CompletableFuture} representing the asynchronous operation.
143- * The future will complete without a result if the signal catalog was successfully
144- * deleted or if the signal catalog does not exist. If an exception occurs during
145- * the deletion, the future will complete exceptionally with the corresponding exception.
146+ * The future will complete without a result if the signal catalog was successfully
147+ * deleted or if the signal catalog does not exist. If an exception occurs during
148+ * the deletion, the future will complete exceptionally with the corresponding exception.
146149 */
147150 public static CompletableFuture <Void > deleteSignalCatalogIfExistsAsync (String signalCatalogName ) {
148151 DeleteSignalCatalogRequest request = DeleteSignalCatalogRequest .builder ()
@@ -165,7 +168,7 @@ public static CompletableFuture<Void> deleteSignalCatalogIfExistsAsync(String si
165168
166169 // snippet-start:[iotfleetwise.java2.create.decoder.main]
167170 /**
168- * Creates a new decoder manifest asynchronously .
171+ * Creates a new decoder manifest.
169172 *
170173 * @param name the name of the decoder manifest
171174 * @param modelManifestArn the ARN of the model manifest
@@ -174,8 +177,6 @@ public static CompletableFuture<Void> deleteSignalCatalogIfExistsAsync(String si
174177 */
175178 public CompletableFuture <String > createDecoderManifestAsync (String name , String modelManifestArn ) {
176179 String interfaceId = "can0" ;
177-
178- // Define CAN interface.
179180 NetworkInterface networkInterface = NetworkInterface .builder ()
180181 .interfaceId (interfaceId )
181182 .type (NetworkInterfaceType .CAN_INTERFACE )
@@ -218,7 +219,6 @@ public CompletableFuture<String> createDecoderManifestAsync(String name, String
218219 .build ())
219220 .build ();
220221
221- // Create decoder manifest request.
222222 CreateDecoderManifestRequest request = CreateDecoderManifestRequest .builder ()
223223 .name (name )
224224 .modelManifestArn (modelManifestArn )
@@ -237,8 +237,9 @@ public CompletableFuture<String> createDecoderManifestAsync(String name, String
237237 // snippet-end:[iotfleetwise.java2.create.decoder.main]
238238
239239 // snippet-start:[iotfleetwise.java2.delete.decoder.main]
240+
240241 /**
241- * Deletes a decoder manifest asynchronously .
242+ * Deletes a decoder manifest.
242243 *
243244 * @param name the name of the decoder manifest to delete
244245 * @return a {@link CompletableFuture} that completes when the decoder manifest has been deleted
@@ -266,6 +267,7 @@ public CompletableFuture<Void> deleteDecoderManifestAsync(String name) {
266267 // snippet-end:[iotfleetwise.java2.delete.decoder.main]
267268
268269 // snippet-start:[iotfleetwise.java2.delete.vehicle.main]
270+
269271 /**
270272 * Asynchronously deletes a vehicle with the specified name.
271273 *
@@ -295,6 +297,7 @@ public CompletableFuture<Void> deleteVehicleAsync(String vecName) {
295297 // snippet-end:[iotfleetwise.java2.delete.vehicle.main]
296298
297299 // snippet-start:[iotfleetwise.java2.update.manifest.main]
300+
298301 /**
299302 * Updates the model manifest asynchronously.
300303 *
@@ -317,6 +320,7 @@ public void updateModelManifestAsync(String name) {
317320 // snippet-end:[iotfleetwise.java2.update.manifest.main]
318321
319322 // snippet-start:[iotfleetwise.java2.update.decoder.main]
323+
320324 /**
321325 * Asynchronously updates the decoder manifest with the given name.
322326 *
@@ -341,14 +345,15 @@ public CompletableFuture<Void> updateDecoderManifestAsync(String name) {
341345 // snippet-end:[iotfleetwise.java2.update.decoder.main]
342346
343347 // snippet-start:[iotfleetwise.java2.create.vehicle.main]
348+
344349 /**
345350 * Asynchronously creates a new vehicle in the system.
346351 *
347- * @param vecName the name of the vehicle to be created
348- * @param manifestArn the Amazon Resource Name (ARN) of the model manifest for the vehicle
349- * @param decArn the Amazon Resource Name (ARN) of the decoder manifest for the vehicle
352+ * @param vecName the name of the vehicle to be created
353+ * @param manifestArn the Amazon Resource Name (ARN) of the model manifest for the vehicle
354+ * @param decArn the Amazon Resource Name (ARN) of the decoder manifest for the vehicle
350355 * @return a {@link CompletableFuture} that completes when the vehicle has been created, or throws a
351- * {@link CompletionException} if there was an error during the creation process
356+ * {@link CompletionException} if there was an error during the creation process
352357 */
353358 public CompletableFuture <Void > createVehicleAsync (String vecName , String manifestArn , String decArn ) {
354359 CreateVehicleRequest request = CreateVehicleRequest .builder ()
@@ -374,6 +379,7 @@ public CompletableFuture<Void> createVehicleAsync(String vecName, String manifes
374379 // snippet-end:[iotfleetwise.java2.create.vehicle.main]
375380
376381 // snippet-start:[iotfleetwise.java2.decoder.active.main]
382+
377383 /**
378384 * Waits for the decoder manifest to become active asynchronously.
379385 *
@@ -393,7 +399,7 @@ public CompletableFuture<Void> waitForDecoderManifestActiveAsync(String decoderN
393399 public void run () {
394400 int elapsed = secondsElapsed .incrementAndGet ();
395401
396- // Only check status every 5 seconds
402+ // Check status every 5 seconds.
397403 if (elapsed % 5 == 0 ) {
398404 GetDecoderManifestRequest request = GetDecoderManifestRequest .builder ()
399405 .name (decoderName )
@@ -412,21 +418,20 @@ public void run() {
412418 lastStatus .set (status );
413419
414420 if (status == ManifestStatus .ACTIVE ) {
415- System . out . print ("\r ⏱️ Elapsed: " + elapsed + "s | Decoder Status: ACTIVE ✅\n " );
421+ logger . info ("\r ⏱️ Elapsed: " + elapsed + "s | Decoder Status: ACTIVE ✅\n " );
416422 scheduler .shutdown ();
417423 result .complete (null );
418424 } else if (status == ManifestStatus .INVALID ) {
419- System . out . print ("\r ⏱️ Elapsed: " + elapsed + "s | Decoder Status: INVALID ❌\n " );
425+ logger . info ("\r ⏱️ Elapsed: " + elapsed + "s | Decoder Status: INVALID ❌\n " );
420426 scheduler .shutdown ();
421427 result .completeExceptionally (
422428 new RuntimeException ("Decoder manifest became INVALID. Cannot proceed." ));
423429 } else {
424- // Just update the status text
425- System .out .print ("\r ⏱️ Elapsed: " + elapsed + "s | Decoder Status: " + status );
430+ logger .info ("\r ⏱️ Elapsed: " + elapsed + "s | Decoder Status: " + status );
426431 }
427432 });
428433 } else {
429- System . out . print ("\r ⏱️ Elapsed: " + elapsed + "s | Decoder Status: " + lastStatus .get ());
434+ logger . info ("\r ⏱️ Elapsed: " + elapsed + "s | Decoder Status: " + lastStatus .get ());
430435 }
431436 }
432437 };
@@ -437,6 +442,7 @@ public void run() {
437442 // snippet-end:[iotfleetwise.java2.decoder.active.main]
438443
439444 // snippet-start:[iotfleetwise.java2.get.manifest.main]
445+
440446 /**
441447 * Waits for the specified model manifest to become active.
442448 *
@@ -475,7 +481,7 @@ public void run() {
475481 lastStatus .set (status );
476482
477483 if (status == ManifestStatus .ACTIVE ) {
478- System . out . print ("\r ⏱️ Elapsed: " + elapsed + "s | Status: ACTIVE ✅\n " );
484+ logger . info ("\r ⏱️ Elapsed: " + elapsed + "s | Status: ACTIVE ✅\n " );
479485 scheduler .shutdown ();
480486 result .complete (null );
481487 } else if (status == ManifestStatus .INVALID ) {
@@ -484,13 +490,11 @@ public void run() {
484490 result .completeExceptionally (
485491 new RuntimeException ("Model manifest became INVALID. Cannot proceed." ));
486492 } else {
487- // Just update the status text
488- System .out .print ("\r ⏱️ Elapsed: " + elapsed + "s | Status: " + status );
493+ logger .info ("\r ⏱️ Elapsed: " + elapsed + "s | Status: " + status );
489494 }
490495 });
491496 } else {
492- // Still print even if not polling yet
493- System .out .print ("\r ⏱️ Elapsed: " + elapsed + "s | Status: " + lastStatus .get ());
497+ logger .info ("\r ⏱️ Elapsed: " + elapsed + "s | Status: " + lastStatus .get ());
494498 }
495499 }
496500 };
@@ -501,6 +505,7 @@ public void run() {
501505 // snippet-end:[iotfleetwise.java2.get.manifest.main]
502506
503507 // snippet-start:[iotfleetwise.java2.get.vehicle.main]
508+
504509 /**
505510 * Asynchronously fetches the details of a vehicle.
506511 *
@@ -568,8 +573,9 @@ public CompletableFuture<Void> createThingIfNotExistsAsync(String thingName) {
568573 }
569574
570575 // snippet-start:[iotfleetwise.java2.delete.model.main]
576+
571577 /**
572- * Deletes a model manifest asynchronously .
578+ * Deletes a model manifest.
573579 *
574580 * @param name the name of the model manifest to delete
575581 * @return a {@link CompletableFuture} that completes when the model manifest has been deleted
@@ -597,9 +603,10 @@ public CompletableFuture<Void> deleteModelManifestAsync(String name) {
597603
598604 // snippet-end:[iotfleetwise.java2.delete.model.main]
599605
600- // snippet-start:[iotfleetwise.java2.delete.catalog.main]
606+ // snippet-start:[iotfleetwise.java2.delete.catalog.main]
607+
601608 /**
602- * Deletes a signal catalog asynchronously .
609+ * Deletes a signal catalog.
603610 *
604611 * @param name the name of the signal catalog to delete
605612 * @return a {@link CompletableFuture} that completes when the signal catalog is deleted
@@ -628,8 +635,9 @@ public CompletableFuture<Void> deleteSignalCatalogAsync(String name) {
628635 // snippet-end:[iotfleetwise.java2.delete.catalog.main]
629636
630637 // snippet-start:[iotfleetwise.java2.list.catalogs.main]
638+
631639 /**
632- * Lists the signal catalog nodes asynchronously .
640+ * Lists the signal catalog nodes.
633641 *
634642 * @param signalCatalogName the name of the signal catalog
635643 * @return a CompletableFuture that, when completed, contains a list of nodes in the specified signal catalog
@@ -651,21 +659,22 @@ public CompletableFuture<List<Node>> listSignalCatalogNodeAsync(String signalCat
651659 // snippet-end:[iotfleetwise.java2.list.catalogs.main]
652660
653661 // snippet-start:[iotfleetwise.java2.create.model.main]
662+
654663 /**
655- * Creates a model manifest asynchronously .
664+ * Creates a model manifest.
656665 *
657- * @param name the name of the model manifest to create
658- * @param signalCatalogArn the Amazon Resource Name (ARN) of the signal catalog
659- * @param nodes a list of nodes to include in the model manifest
666+ * @param name the name of the model manifest to create
667+ * @param signalCatalogArn the Amazon Resource Name (ARN) of the signal catalog
668+ * @param nodes a list of nodes to include in the model manifest
660669 * @return a {@link CompletableFuture} that completes with the ARN of the created model manifest
661- * @throws RuntimeException if an unsupported node type is encountered
670+ * @throws RuntimeException if an unsupported node type is encountered
662671 * @throws CompletionException if there is a failure during the model manifest creation
663672 */
664673
665674 public CompletableFuture <String > createModelManifestAsync (String name ,
666- String signalCatalogArn ,
667- List <Node > nodes ) {
668- // Extract fully qualified names from each Node
675+ String signalCatalogArn ,
676+ List <Node > nodes ) {
677+ // Extract fully qualified names from each Node.
669678 List <String > fqnList = nodes .stream ()
670679 .map (node -> {
671680 if (node .sensor () != null ) {
@@ -726,10 +735,11 @@ public CompletableFuture<Void> deleteFleetAsync(String fleetId) {
726735
727736
728737 // snippet-start:[iotfleetwise.java2.create.fleet.main]
738+
729739 /**
730- * Creates a new fleet asynchronously using the AWS SDK for Java V2 .
740+ * Creates a new fleet.
731741 *
732- * @param catARN the Amazon Resource Name (ARN) of the signal catalog to associate with the fleet
742+ * @param catARN the Amazon Resource Name (ARN) of the signal catalog to associate with the fleet
733743 * @param fleetId the unique identifier for the fleet
734744 * @return a {@link CompletableFuture} that completes with the ID of the created fleet
735745 * @throws RuntimeException if there was an error creating the fleet
0 commit comments