@@ -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