@@ -35,10 +35,10 @@ public class ConnectionStatusServer extends Thread
3535
3636 public ConnectionStatusServer (String host , CurrentConnections watched , int watchedPort )
3737 {
38- if (host == null || watched == null ) throw new SecurityException ("//bodi/connect" );
38+ if (host == null || watched == null ) throw new SecurityException ("//bodi/connect" );
3939
40- this .host = host ;
41- this .watched = watched ;
40+ this .host = host ;
41+ this .watched = watched ;
4242 this .watchedPort = watchedPort ;
4343
4444 this .setName ("ConnectionStatusServer" );
@@ -55,9 +55,9 @@ public void run()
5555 serverSocket = new ServerSocket (STATUS_PORT , 256 , addr );
5656
5757 CommonRails .printSystemComponent (this , this .hashCode (),
58- ". ConnectionStatusServer listening on port " + STATUS_PORT + " ." );
58+ ". ConnectionStatusServer listening on port " + STATUS_PORT + " ." );
5959
60- while (!Thread .currentThread ().isInterrupted ())
60+ while (!Thread .currentThread ().isInterrupted ())
6161 {
6262 Socket client = serverSocket .accept ();
6363
@@ -66,8 +66,7 @@ public void run()
6666 responder .setDaemon (true );
6767 responder .start ();
6868 }
69- }
70- catch (Exception e )
69+ } catch (Exception e )
7170 {
7271 ExceptionHandler .dispatch (e );
7372 e .printStackTrace (System .err );
@@ -80,41 +79,46 @@ private void respond(Socket client)
8079 {
8180 int count = watched .size ();
8281
83- String remoteIp = client .getInetAddress ().getHostAddress ();
84- String geoLine = fetchGeo (remoteIp );
82+ String remoteIp = client .getInetAddress ().getHostAddress ();
83+ String geoLine = fetchGeo (remoteIp );
8584 String localTime = LocalTime .now ().format (DateTimeFormatter .ofPattern ("h:mm a" ));
8685
8786 String banner =
88- "╔══════════════════════════════════════════════╗\n " +
89- "║ National JDK Finance Engine v2811.1 v12.1 ║\n " +
90- "╚══════════════════════════════════════════════╝\n " ;
87+ "╔══════════════════════════════════════════════╗\n " +
88+ "║ National JDK Finance Engine v2811.1 v12.1 ║\n " +
89+ "╚══════════════════════════════════════════════╝\n " ;
9190
9291 String report = banner +
93- "Remote IP: " + remoteIp + "\n " +
94- "Geo Location: " + geoLine + "\n " +
95- "Local Server Time: " + localTime + "\n " +
96- "Current Connections: " + count + "\n " ;
92+ "Remote IP: " + remoteIp + "\n " +
93+ "Geo Location: " + geoLine + "\n " +
94+ "Local Server Time: " + localTime + "\n " +
95+ "Current Connections: " + count + "\n " ;
9796
9897 CommonRails .printSystemComponent (this , this .hashCode (),
99- ". ConnectionStatusServer >> status query: port=" + watchedPort
100- + " connections=" + count + " ." );
98+ ". ConnectionStatusServer >> status query: port=" + watchedPort
99+ + " connections=" + count + " ." );
101100
102101 BufferedWriter writer = new BufferedWriter (new OutputStreamWriter (client .getOutputStream ()));
103102
104103 writer .write (report );
105104 writer .flush ();
106- }
107- catch (Exception e )
105+ } catch (Exception e )
108106 {
109107 ExceptionHandler .dispatch (e );
110- }
111- finally
108+ } finally
112109 {
113- try { client .close (); } catch (Exception ignored ) {}
110+ try
111+ {
112+ client .close ();
113+ } catch (Exception ignored )
114+ {
115+ }
114116 }
115117 }
116118
117- /** Returns "City, Country" for the given IP, or "Unknown" on failure. */
119+ /**
120+ * Returns "City, Country" for the given IP, or "Unknown" on failure.
121+ */
118122 private String fetchGeo (String ip )
119123 {
120124 try
@@ -123,12 +127,15 @@ private String fetchGeo(String ip)
123127 conn .setConnectTimeout (2000 );
124128 conn .setReadTimeout (2000 );
125129
126- try (BufferedReader br = new BufferedReader (new InputStreamReader (conn .getInputStream ())))
130+ try (BufferedReader br = new BufferedReader (new InputStreamReader (conn .getInputStream ())))
127131 {
128- String city = br .readLine ();
132+ String city = br .readLine ();
129133 String country = br .readLine ();
130134 return (city != null ? city : "?" ) + ", " + (country != null ? country : "?" );
131135 }
136+ } catch (Exception e )
137+ {
138+ return "Unknown" ;
132139 }
133- catch (Exception e ) { return "Unknown" ; }
134140 }
141+ }
0 commit comments