Skip to content

Commit ac0e6e4

Browse files
committed
System Touch
1 parent 7ffb9bb commit ac0e6e4

2 files changed

Lines changed: 150 additions & 35 deletions

File tree

source/commons/CommonRails.java

Lines changed: 72 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ public CommonRails()
5555

5656
}
5757

58+
// Color constants
59+
private static final String ANSI_WHITE = "\033[38;5;15m";
60+
private static final String ANSI_DEEP_RED = "\033[38;5;160m";
61+
private static final String ANSI_SILVER = "\033[38;5;250m";
62+
private static final String ANSI_RESET = "\u001B[0m";
63+
5864
public static <T> Integer size(ArrayList<T> list)
5965
{
6066
return list.size();
@@ -146,12 +152,27 @@ public static void printSystemComponent(Object object, Integer hashcode, String
146152
// Uppercase specific keywords anywhere in the line when they appear as whole words
147153
if (lineFixed != null)
148154
{
149-
String[] keywords = new String[]{"telnet", "proxy", "installer", "communicator", "webexpress"};
155+
String[] keywords = new String[]{"telnet", "proxy", "installer", "communicator", "webexpress", "messagequeuesorter", "messagequeuehandler", "serversocket"};
150156
for (String kw : keywords)
151157
{
152158
// (?i) for case-insensitive, \b for word boundary, use Pattern.quote to avoid accidental regex metacharacters
153159
lineFixed = lineFixed.replaceAll("(?i)\\b" + java.util.regex.Pattern.quote(kw) + "\\b", kw.toUpperCase());
154160
}
161+
162+
// Colorize JAVA and TM symbol: make JAVA full white, TM in deep red-burgundy
163+
try
164+
{
165+
// Replace standalone JAVA (case-insensitive) with white-colored version
166+
lineFixed = lineFixed.replaceAll("(?i)\\bJAVA\\b", ANSI_WHITE + "JAVA" + ANSI_RESET);
167+
168+
// Replace trademark symbol ™ with deep red color
169+
lineFixed = lineFixed.replaceAll("™", ANSI_DEEP_RED + "™" + ANSI_RESET);
170+
171+
// Color NitroExpress and "National Finance" in white-silver
172+
lineFixed = lineFixed.replaceAll("(?i)\\bNitroExpress\\b", ANSI_SILVER + "NitroExpress" + ANSI_RESET);
173+
lineFixed = lineFixed.replaceAll("(?i)National Finance", ANSI_SILVER + "National Finance" + ANSI_RESET);
174+
}
175+
catch (Throwable ignored) {}
155176
}
156177

157178
String reference = object_id + " " + date + " " + classnamePadded + " " + lineFixed;
@@ -296,20 +317,23 @@ public static synchronized void registerProcess(ProcessBuilder pb, Process proce
296317

297318
Object printer = (owner == null) ? CommonRails.class : owner;
298319

320+
// derive a process descriptor from ProcessBuilder or Process info
321+
final String procDesc = getProcessDescriptor(pb, process);
322+
299323
try
300324
{
301-
CommonRails.printSystemComponent(printer, process.hashCode(), ". CommonRails registerProcess >> registered process: " + process + " . ");
325+
CommonRails.printSystemComponent(printer, process.hashCode(), ". CommonRails REGISTERED: " + process + " [proc: " + procDesc + "] . ");
302326

303327
// Attach onExit listener
304328
process.onExit().thenAccept(p -> {
305329
try
306330
{
307-
CommonRails.printSystemComponent(printer, p.hashCode(), ". CommonRails processExited >> process closed: " + p + " exit=" + p.exitValue() + " . ");
331+
CommonRails.printSystemComponent(printer, p.hashCode(), ". CommonRails processExited >> process closed: " + p + " exit=" + p.exitValue() + " [proc: " + procDesc + "] . ");
308332
}
309333
catch (Throwable t)
310334
{
311335
// Best-effort printing
312-
CommonRails.printSystemComponent(printer, p.hashCode(), ". CommonRails processExited >> process closed: " + p + " . ");
336+
CommonRails.printSystemComponent(printer, p.hashCode(), ". CommonRails processExited >> process closed: " + p + " [proc: " + procDesc + "] . ");
313337
}
314338
finally
315339
{
@@ -323,7 +347,7 @@ public static synchronized void registerProcess(ProcessBuilder pb, Process proce
323347
{
324348
if (!process.waitFor(2, TimeUnit.HOURS))
325349
{
326-
CommonRails.printSystemComponent(printer, process.hashCode(), ". CommonRails process timeout (2 hours) exceeded; destroying: " + process + " . ");
350+
CommonRails.printSystemComponent(printer, process.hashCode(), ". CommonRails process timeout (2 hours) exceeded; destroying: " + process + " [proc: " + procDesc + "] . ");
327351

328352
try { process.destroyForcibly(); } catch (Throwable ignored) {}
329353
}
@@ -346,11 +370,11 @@ public static synchronized void registerProcess(ProcessBuilder pb, Process proce
346370
{
347371
int rv = process.exitValue();
348372

349-
CommonRails.printSystemComponent(printer, process.hashCode(), ". CommonRails processExited(watcher) >> process closed: " + process + " exit=" + rv + " . ");
373+
CommonRails.printSystemComponent(printer, process.hashCode(), ". CommonRails processExited(watcher) >> process closed: " + process + " exit=" + rv + " [proc: " + getProcessDescriptor(null, process) + "] . ");
350374
}
351375
else
352376
{
353-
CommonRails.printSystemComponent(printer, process.hashCode(), ". CommonRails process watcher timeout (2 hours) exceeded; destroying: " + process + " . ");
377+
CommonRails.printSystemComponent(printer, process.hashCode(), ". CommonRails process watcher timeout (2 hours) exceeded; destroying: " + process + " [proc: " + getProcessDescriptor(null, process) + "] . ");
354378

355379
try { process.destroyForcibly(); } catch (Throwable ignored) {}
356380
}
@@ -367,6 +391,46 @@ public static synchronized void registerProcess(ProcessBuilder pb, Process proce
367391
}
368392
}
369393

394+
/**
395+
* Derive a human-friendly process descriptor for printing.
396+
*/
397+
protected static String getProcessDescriptor(ProcessBuilder pb, Process process)
398+
{
399+
try
400+
{
401+
if (pb != null)
402+
{
403+
try
404+
{
405+
java.util.List<String> cmd = pb.command();
406+
if (cmd != null && !cmd.isEmpty()) return String.join(" ", cmd);
407+
}
408+
catch (Throwable ignored) {}
409+
}
410+
411+
if (process != null)
412+
{
413+
try
414+
{
415+
ProcessHandle.Info info = process.info();
416+
if (info.command().isPresent())
417+
{
418+
String cmd = info.command().get();
419+
String[] args = info.arguments().orElse(new String[0]);
420+
if (args.length > 0) return cmd + " " + String.join(" ", args);
421+
return cmd;
422+
}
423+
}
424+
catch (Throwable ignored) {}
425+
426+
return process.toString();
427+
}
428+
}
429+
catch (Throwable ignored) {}
430+
431+
return "<unknown>";
432+
}
433+
370434
public static synchronized List<Process> getRegisteredProcesses()
371435
{
372436
return new ArrayList<>(REGISTERED_PROCESSES);
@@ -416,7 +480,7 @@ public void run()
416480
*/
417481
public static class IranianWedding
418482
{
419-
private static final String BURGUNDY_ANSI = "\033[38;5;88m";
483+
private static final String BURGUNDY_ANSI = "\033[38;5;160m";
420484
private static final String RESET_ANSI = "\u001B[0m";
421485

422486
/**

source/national/NationalDriver.java

Lines changed: 78 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,22 @@ protected static String extractClassName(String reference)
4848
* Print registered startup references in corrected order using CommonRails.delayableFinePrinter.
4949
* Desired order: NitroWebExpress, WebExpress, BaseServer, Telnet module, AES module, Bitcoin module, remainder
5050
*/
51+
protected static List<List<String>> GROUPED_STARTUP_REFERENCES = null;
52+
protected static List<String> GROUP_NAMES = null;
53+
54+
public static synchronized List<List<String>> getGroupedStartupReferences()
55+
{
56+
return GROUPED_STARTUP_REFERENCES;
57+
}
58+
59+
public static synchronized List<String> getGroupNames()
60+
{
61+
return GROUP_NAMES;
62+
}
63+
5164
public static synchronized void printCorrectedOrder()
5265
{
53-
class Entry { String ref; long ts; int idx; Entry(String r,long t,int i){ref=r;ts=t;idx=i;} }
66+
class Entry { String ref; long ts; int idx; String className; Entry(String r,long t,int i,String cn){ref=r;ts=t;idx=i;className=cn;} }
5467

5568
List<Entry> nitro = new ArrayList<>();
5669
List<Entry> web = new ArrayList<>();
@@ -67,50 +80,88 @@ class Entry { String ref; long ts; int idx; Entry(String r,long t,int i){ref=r;t
6780
String low = cn.toLowerCase();
6881
long ts = extractTimestamp(ref); // may be -1 on parse failure
6982

70-
if (cn.equalsIgnoreCase("NitroWebExpress") || low.contains("nitrowebexpress")) nitro.add(new Entry(ref, ts, index));
71-
else if (cn.equalsIgnoreCase("WebExpress") || low.contains("webexpress")) web.add(new Entry(ref, ts, index));
72-
else if (cn.equalsIgnoreCase("BaseServer") || low.contains("baseserver")) base.add(new Entry(ref, ts, index));
73-
else if (low.contains("telnet")) telnet.add(new Entry(ref, ts, index));
74-
else if (low.contains("aes") || low.contains("aesc") || low.contains("aesen")) aes.add(new Entry(ref, ts, index));
75-
else if (low.contains("bitcoin")) bitcoin.add(new Entry(ref, ts, index));
76-
else remainder.add(new Entry(ref, ts, index));
83+
// treat any mention of "nitro" as NitroWebExpress group to ensure they print first
84+
if (low.contains("nitro")) nitro.add(new Entry(ref, ts, index, cn));
85+
else if (cn.equalsIgnoreCase("WebExpress") || low.contains("webexpress")) web.add(new Entry(ref, ts, index, cn));
86+
else if (cn.equalsIgnoreCase("BaseServer") || low.contains("baseserver")) base.add(new Entry(ref, ts, index, cn));
87+
else if (low.contains("telnet")) telnet.add(new Entry(ref, ts, index, cn));
88+
else if (low.contains("aes") || low.contains("aesc") || low.contains("aesen")) aes.add(new Entry(ref, ts, index, cn));
89+
else if (low.contains("bitcoin")) bitcoin.add(new Entry(ref, ts, index, cn));
90+
else remainder.add(new Entry(ref, ts, index, cn));
7791

7892
index++;
7993
}
8094

8195
// Sort each group by timestamp (ascending). If timestamp unknown (-1), preserve original index ordering.
8296
java.util.Comparator<Entry> cmp = (a,b) -> {
83-
if (a.ts != -1 && b.ts != -1) return Long.compare(a.ts, b.ts);
84-
if (a.ts != -1) return -1;
85-
if (b.ts != -1) return 1;
97+
if (a.ts != -1 && b.ts != -1)
98+
{
99+
int r = Long.compare(a.ts, b.ts);
100+
if (r != 0) return r;
101+
}
102+
else if (a.ts != -1) return -1;
103+
else if (b.ts != -1) return 1;
104+
105+
// secondary: class name alphabetical to group similar subentries, then original index
106+
int cn = a.className.compareToIgnoreCase(b.className);
107+
if (cn != 0) return cn;
86108
return Integer.compare(a.idx, b.idx);
87109
};
88110

89111
nitro.sort(cmp); web.sort(cmp); base.sort(cmp); telnet.sort(cmp); aes.sort(cmp); bitcoin.sort(cmp); remainder.sort(cmp);
90112

91-
// Print in the requested sequence using CommonRails.delayableFinePrinter to preserve formatting/animation.
113+
// Convert to lists of strings and store grouped arrays
114+
List<String> nitroRefs = new ArrayList<>(); for (Entry e: nitro) nitroRefs.add(e.ref);
115+
List<String> webRefs = new ArrayList<>(); for (Entry e: web) webRefs.add(e.ref);
116+
List<String> baseRefs = new ArrayList<>(); for (Entry e: base) baseRefs.add(e.ref);
117+
List<String> telnetRefs = new ArrayList<>(); for (Entry e: telnet) telnetRefs.add(e.ref);
118+
List<String> aesRefs = new ArrayList<>(); for (Entry e: aes) aesRefs.add(e.ref);
119+
List<String> bitcoinRefs = new ArrayList<>(); for (Entry e: bitcoin) bitcoinRefs.add(e.ref);
120+
List<String> remainderRefs = new ArrayList<>(); for (Entry e: remainder) remainderRefs.add(e.ref);
121+
122+
List<List<String>> grouped = new ArrayList<>();
123+
grouped.add(nitroRefs);
124+
grouped.add(webRefs);
125+
grouped.add(baseRefs);
126+
grouped.add(telnetRefs);
127+
grouped.add(aesRefs);
128+
grouped.add(bitcoinRefs);
129+
grouped.add(remainderRefs);
130+
131+
List<String> groupNames = new ArrayList<>();
132+
groupNames.add("NITRO");
133+
groupNames.add("WEBEXPRESS");
134+
groupNames.add("BASESERVER");
135+
groupNames.add("TELNET");
136+
groupNames.add("AES");
137+
groupNames.add("BITCOIN");
138+
groupNames.add("REMAINDER");
139+
140+
GROUPED_STARTUP_REFERENCES = grouped;
141+
GROUP_NAMES = groupNames;
142+
143+
// Print groups in order; each group's entries are printed together
92144
try
93145
{
94-
for (Entry e : nitro) CommonRails.delayableFinePrinter(e.ref, 21);
95-
for (Entry e : web) CommonRails.delayableFinePrinter(e.ref, 21);
96-
for (Entry e : base) CommonRails.delayableFinePrinter(e.ref, 21);
97-
for (Entry e : telnet) CommonRails.delayableFinePrinter(e.ref, 21);
98-
for (Entry e : aes) CommonRails.delayableFinePrinter(e.ref, 21);
99-
for (Entry e : bitcoin) CommonRails.delayableFinePrinter(e.ref, 21);
100-
for (Entry e : remainder) CommonRails.delayableFinePrinter(e.ref, 21);
146+
for (int gi = 0; gi < grouped.size(); gi++)
147+
{
148+
List<String> g = grouped.get(gi);
149+
String gname = groupNames.get(gi);
150+
CommonRails.delayableFinePrinter(". START GROUP: " + gname + " (" + g.size() + ") .", 21);
151+
for (String s : g) CommonRails.delayableFinePrinter(s, 21);
152+
}
101153
}
102154
catch (Throwable t)
103155
{
104-
// best-effort printing; if CommonRails printing fails, fall back to System.out
105156
try
106157
{
107-
for (Entry e : nitro) System.out.println(e.ref);
108-
for (Entry e : web) System.out.println(e.ref);
109-
for (Entry e : base) System.out.println(e.ref);
110-
for (Entry e : telnet) System.out.println(e.ref);
111-
for (Entry e : aes) System.out.println(e.ref);
112-
for (Entry e : bitcoin) System.out.println(e.ref);
113-
for (Entry e : remainder) System.out.println(e.ref);
158+
for (int gi = 0; gi < grouped.size(); gi++)
159+
{
160+
List<String> g = grouped.get(gi);
161+
String gname = groupNames.get(gi);
162+
System.out.println("START GROUP: " + gname + " (" + g.size() + ")");
163+
for (String s : g) System.out.println(s);
164+
}
114165
}
115166
catch (Throwable ignored) {}
116167
}

0 commit comments

Comments
 (0)