1111
1212public class JarSettingsProperties {
1313
14- static final String DEFAULT_JVM = "default" ;
15- static final String DEFAULT_STACKSIZE = "1024k" ;
16- static final boolean DEFAULT_FORCEIP4 = false ;
14+ private static final String DEFAULT_JVM = "default" ;
15+ private static final String DEFAULT_STACKSIZE = "1024k" ;
16+ private static final String DEFAULT_HOMEDIR = new File ("home" ).getAbsolutePath ();
17+ private static final String DEFAULT_ADDRESS = "localhost" ;
18+ private static final int DEFAULT_PROXYPORT = 1080 ;
19+ private static final int DEFAULT_PORT = 8082 ;
20+ private static final String DEFAULT_HEAPSIZE ;
21+
22+ static {
23+ com .sun .management .OperatingSystemMXBean os = (com .sun .management .OperatingSystemMXBean ) java .lang .management .ManagementFactory .getOperatingSystemMXBean ();
24+ long physicalMemorySize = os .getTotalPhysicalMemorySize ();
25+ DEFAULT_HEAPSIZE = Math .min (1024 * 1024 * 1024 , physicalMemorySize / 2 / 1024 / 1024 ) + "m" ;
26+ }
1727
1828 private String jvm ;
1929 private String stacksize ;
20- private boolean forceipv4 ;
21-
22- private String homedir = new File ("home" ).getAbsolutePath ();
23-
24- private String address = "localhost" ;
25-
26- private String proxyHost = "" ;
30+ private boolean forceipv4 = false ;
2731
32+ private String homedir ;
33+ private String address ;
2834 private boolean useProxy = false ;
29-
30- private int proxyPort = 1080 ;
31-
32- private int port = 8082 ;
33-
35+ private String proxyHost = "" ;
36+ private int proxyPort ;
37+ private int port ;
3438 private String heapsize ;
3539
36-
37- public JarSettingsProperties () {
38- com .sun .management .OperatingSystemMXBean os = (com .sun .management .OperatingSystemMXBean ) java .lang .management .ManagementFactory .getOperatingSystemMXBean ();
39- long physicalMemorySize = os .getTotalPhysicalMemorySize ();
40- heapsize = Math .min (1024 * 1024 * 1024 , physicalMemorySize / 2 / 1024 / 1024 ) + "m" ;
41- }
42-
4340 public static JarSettingsProperties readFromFile () {
4441 return readFromFile (Paths .get ("settings.properties" ));
4542 }
@@ -54,14 +51,14 @@ public static JarSettingsProperties readFromFile(Path path) {
5451 }
5552 jarSettingsProperties .setJvm (properties .getProperty ("jvm" , DEFAULT_JVM ));
5653 jarSettingsProperties .setStacksize (properties .getProperty ("stacksize" ,DEFAULT_STACKSIZE ));
57- jarSettingsProperties .setForceipv4 (Boolean .parseBoolean (properties .getProperty ("forceip4" , String . valueOf ( DEFAULT_FORCEIP4 ) )));
58- jarSettingsProperties .setHomedir (properties .getProperty ("homedir" ));
59- jarSettingsProperties .setAddress (properties .getProperty ("address" ));
54+ jarSettingsProperties .setForceipv4 (Boolean .parseBoolean (properties .getProperty ("forceip4" )));
55+ jarSettingsProperties .setHomedir (properties .getProperty ("homedir" , DEFAULT_HOMEDIR ));
56+ jarSettingsProperties .setAddress (properties .getProperty ("address" , DEFAULT_ADDRESS ));
6057 jarSettingsProperties .setUseProxy (Boolean .parseBoolean (properties .getProperty ("useProxy" )));
6158 jarSettingsProperties .setProxyHost (properties .getProperty ("proxyHost" ));
62- jarSettingsProperties .setProxyPort (Integer .parseInt (properties .getProperty ("proxyPort" )));
63- jarSettingsProperties .setPort (Integer .parseInt (properties .getProperty ("port" )));
64- jarSettingsProperties .setHeapsize (properties .getProperty ("heapsize" ));
59+ jarSettingsProperties .setProxyPort (Integer .parseInt (properties .getProperty ("proxyPort" , String . valueOf ( DEFAULT_PROXYPORT ) )));
60+ jarSettingsProperties .setPort (Integer .parseInt (properties .getProperty ("port" , String . valueOf ( DEFAULT_PORT ) )));
61+ jarSettingsProperties .setHeapsize (properties .getProperty ("heapsize" , DEFAULT_HEAPSIZE ));
6562 }
6663 } catch (IOException e ) {
6764 e .printStackTrace ();
0 commit comments