Skip to content

Commit 236ee24

Browse files
authored
Merge pull request #2889 from ControlSystemStudio/pva_search_monitor_fix
PVA search monitor: Fix cmd line arg handling
2 parents 4272a82 + feede7f commit 236ee24

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

core/pva/src/main/java/org/epics/pva/server/PVASearchMonitorMain.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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
@@ -12,6 +12,7 @@
1212
import java.util.concurrent.ConcurrentHashMap;
1313
import java.util.concurrent.CountDownLatch;
1414
import java.util.concurrent.TimeUnit;
15+
import java.util.concurrent.atomic.AtomicBoolean;
1516
import java.util.concurrent.atomic.AtomicLong;
1617
import java.util.logging.Level;
1718
import 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

Comments
 (0)