@@ -284,21 +284,18 @@ public void commandReceived(ZigBeeCommand command) {
284284 }
285285 });
286286
287- Runtime .getRuntime ().addShutdownHook (new Thread (new Runnable () {
288- @ Override
289- public void run () {
290- shutdown = true ;
291- try {
292- System .in .close ();
293- } catch (IOException e ) {
294- e .printStackTrace ();
295- }
296- try {
297- mainThread .interrupt ();
298- mainThread .join ();
299- } catch (InterruptedException e ) {
300- e .printStackTrace ();
301- }
287+ Runtime .getRuntime ().addShutdownHook (new Thread (() -> {
288+ shutdown = true ;
289+ try {
290+ System .in .close ();
291+ } catch (IOException e ) {
292+ e .printStackTrace ();
293+ }
294+ try {
295+ mainThread .interrupt ();
296+ mainThread .join ();
297+ } catch (InterruptedException e ) {
298+ e .printStackTrace ();
302299 }
303300 }));
304301 }
@@ -945,74 +942,62 @@ public boolean process(final ZigBeeApi zigbeeApi, final String[] args, final Pri
945942 return false ;
946943 }
947944
948- new Thread (new Runnable () {
949- @ Override
950- public void run () {
951- int cnt = 0 ;
952- while (true ) {
953- print ("STRESSING 1 CNT: " + cnt ++, out );
954- ZclOnOffCluster cluster = (ZclOnOffCluster ) endpoint
955- .getInputCluster (ZclOnOffCluster .CLUSTER_ID );
956- cluster .onCommand ();
957- try {
958- Thread .sleep (167 );
959- } catch (InterruptedException e ) {
960- e .printStackTrace ();
961- }
945+ new Thread (() -> {
946+ int cnt = 0 ;
947+ while (true ) {
948+ print ("STRESSING 1 CNT: " + cnt ++, out );
949+ ZclOnOffCluster cluster = (ZclOnOffCluster ) endpoint
950+ .getInputCluster (ZclOnOffCluster .CLUSTER_ID );
951+ cluster .onCommand ();
952+ try {
953+ Thread .sleep (167 );
954+ } catch (InterruptedException e ) {
955+ e .printStackTrace ();
962956 }
963957 }
964958 }).start ();
965959
966- new Thread (new Runnable () {
967- @ Override
968- public void run () {
969- int cnt = 0 ;
970- while (true ) {
971- print ("STRESSING 2 CNT: " + cnt ++, out );
972- ZclOnOffCluster cluster = (ZclOnOffCluster ) endpoint
973- .getInputCluster (ZclOnOffCluster .CLUSTER_ID );
974- cluster .onCommand ();
975- try {
976- Thread .sleep (107 );
977- } catch (InterruptedException e ) {
978- e .printStackTrace ();
979- }
960+ new Thread (() -> {
961+ int cnt = 0 ;
962+ while (true ) {
963+ print ("STRESSING 2 CNT: " + cnt ++, out );
964+ ZclOnOffCluster cluster = (ZclOnOffCluster ) endpoint
965+ .getInputCluster (ZclOnOffCluster .CLUSTER_ID );
966+ cluster .onCommand ();
967+ try {
968+ Thread .sleep (107 );
969+ } catch (InterruptedException e ) {
970+ e .printStackTrace ();
980971 }
981972 }
982973 }).start ();
983974
984- new Thread (new Runnable () {
985- @ Override
986- public void run () {
987- int cnt = 0 ;
988- while (true ) {
989- print ("STRESSING 3 CNT: " + cnt ++, out );
990- ZclOnOffCluster cluster = (ZclOnOffCluster ) endpoint
991- .getInputCluster (ZclOnOffCluster .CLUSTER_ID );
992- cluster .onCommand ();
993- try {
994- Thread .sleep (131 );
995- } catch (InterruptedException e ) {
996- e .printStackTrace ();
997- }
975+ new Thread (() -> {
976+ int cnt = 0 ;
977+ while (true ) {
978+ print ("STRESSING 3 CNT: " + cnt ++, out );
979+ ZclOnOffCluster cluster = (ZclOnOffCluster ) endpoint
980+ .getInputCluster (ZclOnOffCluster .CLUSTER_ID );
981+ cluster .onCommand ();
982+ try {
983+ Thread .sleep (131 );
984+ } catch (InterruptedException e ) {
985+ e .printStackTrace ();
998986 }
999987 }
1000988 }).start ();
1001989
1002- new Thread (new Runnable () {
1003- @ Override
1004- public void run () {
1005- int cnt = 0 ;
1006- while (true ) {
1007- print ("STRESSING 4 CNT: " + cnt ++, out );
1008- ZclOnOffCluster cluster = (ZclOnOffCluster ) endpoint
1009- .getInputCluster (ZclOnOffCluster .CLUSTER_ID );
1010- cluster .onCommand ();
1011- try {
1012- Thread .sleep (187 );
1013- } catch (InterruptedException e ) {
1014- e .printStackTrace ();
1015- }
990+ new Thread (() -> {
991+ int cnt = 0 ;
992+ while (true ) {
993+ print ("STRESSING 4 CNT: " + cnt ++, out );
994+ ZclOnOffCluster cluster = (ZclOnOffCluster ) endpoint
995+ .getInputCluster (ZclOnOffCluster .CLUSTER_ID );
996+ cluster .onCommand ();
997+ try {
998+ Thread .sleep (187 );
999+ } catch (InterruptedException e ) {
1000+ e .printStackTrace ();
10161001 }
10171002 }
10181003 }).start ();
@@ -1089,46 +1074,42 @@ public String getSyntax() {
10891074 */
10901075 @ Override
10911076 public boolean process (final ZigBeeApi zigbeeApi , final String [] args , final PrintStream out ) throws Exception {
1092- new Thread (new Runnable () {
1093- @ Override
1094- public void run () {
1095- int cnts = 1000 ;
1096- int errors = 0 ;
1097- int cnt = 0 ;
1098- List <Integer > lqi = new ArrayList <>();
1099- while (cnt < cnts ) {
1100- print ("LQI Poll CNT: " + cnt ++, out );
1101- final ManagementLqiRequest neighborRequest = new ManagementLqiRequest (0 );
1102- neighborRequest .setDestinationAddress (new ZigBeeEndpointAddress (0 ));
1103-
1104- CommandResult response ;
1105- try {
1106- response = networkManager .sendTransaction (neighborRequest , neighborRequest ).get ();
1107- final ManagementLqiResponse neighborResponse = response .getResponse ();
1108-
1109- if (neighborResponse == null || neighborResponse .getStatus () != ZdoStatus .SUCCESS ) {
1110- errors ++;
1111- continue ;
1112- }
1113- if (neighborResponse .getNeighborTableList ().isEmpty ()) {
1114- print ("No neighbors" , out );
1115- continue ;
1116- }
1117- lqi .add (neighborResponse .getNeighborTableList ().get (0 ).getLqi ());
1118- } catch (InterruptedException | ExecutionException e ) {
1119- // TODO Auto-generated catch block
1120- e .printStackTrace ();
1077+ new Thread (() -> {
1078+ int cnts = 1000 ;
1079+ int errors = 0 ;
1080+ int cnt = 0 ;
1081+ List <Integer > lqi = new ArrayList <>();
1082+ while (cnt < cnts ) {
1083+ print ("LQI Poll CNT: " + cnt ++, out );
1084+ final ManagementLqiRequest neighborRequest = new ManagementLqiRequest (0 );
1085+ neighborRequest .setDestinationAddress (new ZigBeeEndpointAddress (0 ));
1086+
1087+ CommandResult response ;
1088+ try {
1089+ response = networkManager .sendTransaction (neighborRequest , neighborRequest ).get ();
1090+ final ManagementLqiResponse neighborResponse = response .getResponse ();
1091+
1092+ if (neighborResponse == null || neighborResponse .getStatus () != ZdoStatus .SUCCESS ) {
1093+ errors ++;
1094+ continue ;
11211095 }
1096+ if (neighborResponse .getNeighborTableList ().isEmpty ()) {
1097+ print ("No neighbors" , out );
1098+ continue ;
1099+ }
1100+ lqi .add (neighborResponse .getNeighborTableList ().get (0 ).getLqi ());
1101+ } catch (InterruptedException | ExecutionException e ) {
1102+ // TODO Auto-generated catch block
1103+ e .printStackTrace ();
11221104 }
1123- IntSummaryStatistics stats = lqi .stream ().mapToInt ((x ) -> x ).summaryStatistics ();
1124-
1125- print ("LQI Polling Complete" , out );
1126- print ("Errors: " + errors , out );
1127- print ("Min : " + stats .getMin (), out );
1128- print ("Max : " + stats .getMax (), out );
1129- print ("Avg : " + stats .getAverage (), out );
1130-
11311105 }
1106+ IntSummaryStatistics stats = lqi .stream ().mapToInt ((x ) -> x ).summaryStatistics ();
1107+
1108+ print ("LQI Polling Complete" , out );
1109+ print ("Errors: " + errors , out );
1110+ print ("Min : " + stats .getMin (), out );
1111+ print ("Max : " + stats .getMax (), out );
1112+ print ("Avg : " + stats .getAverage (), out );
11321113 }).start ();
11331114
11341115 return true ;
@@ -1157,12 +1138,7 @@ public String getSyntax() {
11571138 */
11581139 @ Override
11591140 public boolean process (final ZigBeeApi zigbeeApi , final String [] args , final PrintStream out ) throws Exception {
1160- new Thread (new Runnable () {
1161- @ Override
1162- public void run () {
1163- networkManager .reinitialize ();
1164- }
1165- }).start ();
1141+ new Thread (networkManager ::reinitialize ).start ();
11661142
11671143 return true ;
11681144 }
0 commit comments