@@ -440,13 +440,13 @@ private HashMap<String, CloudModel> fetchDevices(String deviceRegistryId,
440
440
response .getDevicesList ().stream ().map (ClearBladeIotAccessProvider ::convertPartial )
441
441
.collect (toMap (Entry ::getKey , Entry ::getValue ));
442
442
List <String > exists = responseMap .keySet ().stream ().filter (collect ::containsKey ).toList ();
443
- ifNotTrueThen (exists .isEmpty (), () -> ifNotNullThen ( progress ,
444
- p -> p .accept ("Found duplicate device entries: " + exists ) ));
443
+ ifNotTrueThen (exists .isEmpty (),
444
+ () -> progress .accept ("Found duplicate device entries: " + exists ));
445
445
446
446
collect .putAll (responseMap );
447
447
pageToken = response .getNextPageToken ();
448
448
queryCount ++;
449
- ifNotNullThen ( progress , p -> p .accept (getProgressMessage (collect , gatewayListOptions ) ));
449
+ progress .accept (getProgressMessage (collect , gatewayListOptions ));
450
450
debug (format ("fetchDevices %s #%d found %d total %d more %s" , deviceRegistryId ,
451
451
queryCount , responseMap .size (), collect .size (), pageToken != null ));
452
452
} while (pageToken != null );
@@ -596,10 +596,11 @@ private GatewayModel makeGatewayModel(HashMap<String, CloudModel> boundDevices)
596
596
597
597
@ Override
598
598
public CloudModel modelDevice (String registryId , String deviceId , CloudModel cloudModel ,
599
- Consumer <String > progress ) {
599
+ Consumer <String > maybeProgress ) {
600
600
String devicePath = getDeviceName (registryId , deviceId );
601
601
Operation operation = cloudModel .operation ;
602
602
Resource_type type = ofNullable (cloudModel .resource_type ).orElse (Resource_type .DEVICE );
603
+ Consumer <String > progress = ofNullable (maybeProgress ).orElse (this ::bitBucket );
603
604
checkState (type == DEVICE || type == GATEWAY , "unexpected resource type " + type );
604
605
try {
605
606
Device device = convert (cloudModel , deviceId );
@@ -617,6 +618,10 @@ public CloudModel modelDevice(String registryId, String deviceId, CloudModel clo
617
618
}
618
619
}
619
620
621
+ private void bitBucket (String s ) {
622
+ // Do nothing, just drop the messages on the floor.
623
+ }
624
+
620
625
private CloudModel getReply (String registryId , String deviceId , CloudModel request ,
621
626
String numId ) {
622
627
CloudModel reply = new CloudModel ();
@@ -739,22 +744,18 @@ private void bindDevicesGateways(String registryId, Set<String> gatewayIds,
739
744
String opCode = toBind ? "Binding" : "Unbinding" ;
740
745
info ("%s %s: gateways %s devices %s" , opCode , registryId , gatewayIds , deviceIds );
741
746
AtomicInteger opCount = new AtomicInteger (0 );
742
- ifNotNullThen (progress ,
743
- p -> p .accept (format ("%s %d devices on %d gateways" , opCode , deviceIds .size (),
744
- gatewayIds .size ())));
747
+ progress .accept (format ("%s %d devices on %d gateways" , opCode , deviceIds .size (),
748
+ gatewayIds .size ()));
745
749
gatewayIds .forEach (gatewayId -> {
746
750
deviceIds .forEach (deviceId -> {
747
- // ifTrueThen(opCount.incrementAndGet() % OP_PROGRESS_BATCH_SIZE == 0,
748
- // () -> ifNotNullThen(progress,
749
- // p -> p.accept(format("%s %d devices...", opCode, opCount.get()))));
750
- ifNotNullThen (progress , p -> p .accept (format ("%s %s from/to %s" , opCode , deviceId , gatewayId )));
751
+ progress .accept (format ("%s %s from/to %s" , opCode , deviceId , gatewayId ));
751
752
ifTrueThen (toBind ,
752
753
() -> bindDevice (registryId , gatewayId , deviceId ),
753
754
() -> unbindDevice (registryId , gatewayId , deviceId ));
754
755
});
755
756
});
756
- ifTrueThen (opCount .get () > 0 , () -> ifNotNullThen ( progress , p -> p .accept (
757
- format ("Completed binding %d devices." , opCount .get ())))) ;
757
+ ifTrueThen (opCount .get () > 0 , () -> progress .accept (
758
+ format ("Completed binding %d devices." , opCount .get ())));
758
759
}
759
760
760
761
private void unbindDevice (String registryId , String gatewayId , String proxyId ) {
@@ -923,7 +924,8 @@ public boolean isEnabled() {
923
924
}
924
925
925
926
@ Override
926
- public CloudModel listDevices (String registryId , Consumer <String > progress ) {
927
+ public CloudModel listDevices (String registryId , Consumer <String > maybeProgress ) {
928
+ Consumer <String > progress = ofNullable (maybeProgress ).orElse (this ::bitBucket );
927
929
return listRegistryDevices (registryId , null , progress );
928
930
}
929
931
0 commit comments