@@ -246,7 +246,7 @@ protected DeviceManagerInterface getDeviceManager(int monitorSec) {
246
246
}
247
247
248
248
private CloudModel bindDevicesToGateway (String registryId , String gatewayId ,
249
- CloudModel cloudModel , Consumer <Integer > progress ) {
249
+ CloudModel cloudModel , Consumer <String > progress ) {
250
250
Set <String > deviceIds = ReflectProcessor .isLegacyRequest (cloudModel )
251
251
? cloudModel .device_ids .keySet () : getDeviceIds (cloudModel .gateway );
252
252
boolean toBind = cloudModel .operation == BIND ;
@@ -529,10 +529,11 @@ private Map<String, CloudModel> augmentGatewayModels(String registryId,
529
529
HashMap <String , String > proxyDeviceGateways = new HashMap <>();
530
530
Set <Entry <String , CloudModel >> gateways =
531
531
boundDevices .entrySet ().stream ().filter (this ::isGateway ).collect (Collectors .toSet ());
532
- AtomicInteger count = new AtomicInteger (- gateways . size () );
532
+ AtomicInteger count = new AtomicInteger ();
533
533
gateways .forEach (entry -> {
534
534
augmentGatewayModel (registryId , entry , proxyDeviceGateways );
535
- progress .accept (format ("Processed %d gateways..." , count .incrementAndGet ()));
535
+ progress .accept (format ("Augmented gateway %s (%d/%d)" ,
536
+ entry .getKey (), count .incrementAndGet (), gateways .size ()));
536
537
});
537
538
boundDevices .entrySet ()
538
539
.forEach (entry -> augmentProxiedModel (entry , proxyDeviceGateways ));
@@ -566,7 +567,7 @@ private GatewayModel makeGatewayModel(HashMap<String, CloudModel> boundDevices)
566
567
567
568
@ Override
568
569
public CloudModel modelDevice (String registryId , String deviceId , CloudModel cloudModel ,
569
- Consumer <Integer > progress ) {
570
+ Consumer <String > progress ) {
570
571
String devicePath = getDeviceName (registryId , deviceId );
571
572
Operation operation = cloudModel .operation ;
572
573
Resource_type type = ofNullable (cloudModel .resource_type ).orElse (Resource_type .DEVICE );
@@ -640,7 +641,7 @@ private StateNotificationConfig stateNotificationConfig() {
640
641
}
641
642
642
643
private CloudModel unbindAndDelete (String registryId , Device device , CloudModel request ,
643
- Consumer <Integer > progress ) {
644
+ Consumer <String > progress ) {
644
645
try {
645
646
final Set <String > unbindIds = ReflectProcessor .isLegacyRequest (request )
646
647
? legacyFindGateways (registryId , device )
@@ -685,7 +686,7 @@ private Set<String> legacyFindGateways(String registryId, Device device) {
685
686
}
686
687
687
688
private CloudModel unbindAndDeleteCore (String registryId , Device device , Set <String > unbindIds ,
688
- Consumer <Integer > progress ) {
689
+ Consumer <String > progress ) {
689
690
String deviceId = requireNonNull (device .toBuilder ().getId (), "unspecified device id" );
690
691
try {
691
692
ifNotNullThen (unbindIds , ids -> unbindGatewayDevices (registryId , device , ids , progress ));
@@ -704,20 +705,25 @@ private CloudModel unbindAndDeleteCore(String registryId, Device device, Set<Str
704
705
}
705
706
706
707
private void bindDevicesGateways (String registryId , Set <String > gatewayIds ,
707
- Set <String > deviceIds , boolean toBind , Consumer <Integer > progress ) {
708
+ Set <String > deviceIds , boolean toBind , Consumer <String > progress ) {
708
709
String opCode = toBind ? "Binding" : "Unbinding" ;
709
710
info ("%s %s: gateways %s devices %s" , opCode , registryId , gatewayIds , deviceIds );
710
711
AtomicInteger opCount = new AtomicInteger (0 );
712
+ ifNotNullThen (progress ,
713
+ p -> p .accept (format ("%s %d devices on %d gateways" , opCode , deviceIds .size (),
714
+ gatewayIds .size ())));
711
715
gatewayIds .forEach (gatewayId -> {
712
716
deviceIds .forEach (deviceId -> {
713
717
ifTrueThen (opCount .incrementAndGet () % OP_PROGRESS_BATCH_SIZE == 0 ,
714
- () -> ifNotNullThen (progress , p -> p .accept (opCount .get ())));
718
+ () -> ifNotNullThen (progress ,
719
+ p -> p .accept (format ("%s %d devices..." , opCode , opCount .get ()))));
715
720
ifTrueThen (toBind ,
716
721
() -> bindDevice (registryId , gatewayId , deviceId ),
717
722
() -> unbindDevice (registryId , gatewayId , deviceId ));
718
723
});
719
724
});
720
- ifTrueThen (opCount .get () > 0 , () -> ifNotNullThen (progress , p -> p .accept (opCount .get ())));
725
+ ifTrueThen (opCount .get () > 0 , () -> ifNotNullThen (progress , p -> p .accept (
726
+ format ("Completed binding %d devices." , opCount .get ()))));
721
727
}
722
728
723
729
private void unbindDevice (String registryId , String gatewayId , String proxyId ) {
@@ -734,7 +740,7 @@ private void unbindDevice(String registryId, String gatewayId, String proxyId) {
734
740
}
735
741
736
742
private boolean unbindGatewayDevices (String registryId , Device gatewayDevice ,
737
- Set <String > unbindIds , Consumer <Integer > progress ) {
743
+ Set <String > unbindIds , Consumer <String > progress ) {
738
744
try {
739
745
ImmutableSet <String > gatewayIds = ImmutableSet .of (gatewayDevice .toBuilder ().getId ());
740
746
bindDevicesGateways (registryId , gatewayIds , unbindIds , false , progress );
0 commit comments