11/*******************************************************************************
2- * Copyright (c) 2022 Oak Ridge National Laboratory.
2+ * Copyright (c) 2022-2023 Oak Ridge National Laboratory.
33 * All rights reserved. This program and the accompanying materials
44 * are made available under the terms of the Eclipse Public License v1.0
55 * which accompanies this distribution, and is available at
1212import java .util .concurrent .ConcurrentHashMap ;
1313import java .util .concurrent .CountDownLatch ;
1414import java .util .concurrent .TimeUnit ;
15+ import java .util .concurrent .atomic .AtomicBoolean ;
1516import java .util .concurrent .atomic .AtomicLong ;
1617import java .util .logging .Level ;
1718import java .util .logging .LogManager ;
@@ -50,6 +51,7 @@ private static class SearchInfo implements Comparable<SearchInfo>
5051 this .name = name ;
5152 }
5253
54+ /** Sort by search count */
5355 @ Override
5456 public int compareTo (final SearchInfo other )
5557 {
@@ -93,7 +95,7 @@ public static void main(String[] args) throws Exception
9395 LogManager .getLogManager ().readConfiguration (PVASettings .class .getResourceAsStream ("/pva_logging.properties" ));
9496 setLogLevel (Level .WARNING );
9597 long update_period = 10 ;
96- boolean once = false ;
98+ final AtomicBoolean once = new AtomicBoolean () ;
9799
98100 for (int i =0 ; i <args .length ; ++i )
99101 {
@@ -104,9 +106,12 @@ public static void main(String[] args) throws Exception
104106 return ;
105107 }
106108 if (arg .startsWith ("-1" ))
107- once = true ;
109+ once . set ( true ) ;
108110 else if (arg .startsWith ("-p" ) && (i +1 ) < args .length )
111+ {
109112 update_period = Long .parseLong (args [i +1 ]);
113+ ++i ;
114+ }
110115 else if (arg .startsWith ("-v" ) && (i +1 ) < args .length )
111116 {
112117 switch (Integer .parseInt (args [i +1 ]))
@@ -138,8 +143,8 @@ else if (arg.startsWith("-v") && (i+1) < args.length)
138143
139144 final SearchHandler search_handler = (seq , cid , name , addr , reply_sender ) ->
140145 {
141- // Quit when receiving search for name "QUIT"
142- if (name .equals ("QUIT" ))
146+ // In "continuing" mode, quit when receiving search for name "QUIT"
147+ if (! once . get () && name .equals ("QUIT" ))
143148 done .countDown ();
144149
145150 final SearchInfo search = searches .computeIfAbsent (name , n -> new SearchInfo (name ));
@@ -155,7 +160,7 @@ else if (arg.startsWith("-v") && (i+1) < args.length)
155160 ( final PVAServer server = new PVAServer (search_handler ) )
156161 {
157162 System .out .println ("Monitoring search requests for " + update_period + " seconds..." );
158- if (! once )
163+ if (! once . get () )
159164 System .out .println ("Run 'pvget QUIT' to stop" );
160165 while (! done .await (update_period , TimeUnit .SECONDS ))
161166 {
@@ -172,7 +177,7 @@ else if (arg.startsWith("-v") && (i+1) < args.length)
172177 info .client .toString (),
173178 now .getEpochSecond () - info .last .getEpochSecond ());
174179 });
175- if (once )
180+ if (once . get () )
176181 break ;
177182 }
178183 }
0 commit comments