These are chat archives for atomix/atomix

2nd
Mar 2016
Richard Pijnenburg
@electrical
Mar 02 2016 00:17
@kuujo did you have time to check out the issues / repo by any chance? okay if you didn’t :-)
Richard Pijnenburg
@electrical
Mar 02 2016 00:59
@kuujo you busy?
Richard Pijnenburg
@electrical
Mar 02 2016 01:07
for when you have time. I’m trying to understand what the heck they are doing here. https://github.com/elastic/elasticsearch/blob/master/core/src/main/java/org/elasticsearch/monitor/jvm/JvmInfo.java#L65-L71 can’t replicate it to make it work on my side.
Richard Pijnenburg
@electrical
Mar 02 2016 01:26
made it working. not sure how yet :-)
Jordan Halterman
@kuujo
Mar 02 2016 01:26
haha
Richard Pijnenburg
@electrical
Mar 02 2016 01:27
their code is so damn confusing
Jordan Halterman
@kuujo
Mar 02 2016 01:27
true fact
Richard Pijnenburg
@electrical
Mar 02 2016 01:28
must be an easier way to collect some jvm / system info
oh f*ck. 1.30 am already. alarm goes off at 6
Better grab some sleep
Jonathan Halterman
@jhalterman
Mar 02 2016 03:15
@electrical You are right on - they're just grabbing some info about the java runtime and storing it in an instance of JvmInfo.
there are a few different ways to collect system info, but that looks about as straightforward as the others i've seen
Another way is to just inspect the java.version system property: System.getProperty("java.version")
that string can be formatted differently depending on the platform/version though
Richard Pijnenburg
@electrical
Mar 02 2016 07:40
@jhalterman I agree it's fairly simple I'm most likely missing context and java experience for how the class it self is constructed and why it works this way. :)
Jordan Halterman
@kuujo
Mar 02 2016 07:40
ahh yes
so...
What they’re doing is reading JVM information in the static block. Static class variables and code are evaluated when the class is loaded by the JVM. So, for instance, if you do Class.forName(“foo.bar.Baz”) then any static code in the Baz class will be evaluated. The static block can be used to operate on static fields when the class is loaded.
So, they’re basically constructing a singleton instance in a static block rather than in a static singleton method
Richard Pijnenburg
@electrical
Mar 02 2016 07:44
Ahh okay. Singletons I understand :) any advantages of doing it this way vs a singleton method ?
Jordan Halterman
@kuujo
Mar 02 2016 07:44
nah it’s just more idomatic I guess
Richard Pijnenburg
@electrical
Mar 02 2016 07:46
Okay :)
Richard Pijnenburg
@electrical
Mar 02 2016 07:56
And that they do info.something=foo ?
Jordan Halterman
@kuujo
Mar 02 2016 07:59
That’s just encapsulation. The fields of the class are package private (they have no modifier, i.e. private, protected, etc). Package private means any code in the same package can access it. The static block is obviously in the same package. They set the fields directly since it’s almost pointless to add setters for that, and the object is immutable outside the package
Richard Pijnenburg
@electrical
Mar 02 2016 08:17
Ahh okay. I see. And that's why you can get them with the this.somthing variable but need a getter that is public to actually get the value outside the class it self. And that they can set the fields is because info is an instance of the class it self ?
Jordan Halterman
@kuujo
Mar 02 2016 08:17
yep
Richard Pijnenburg
@electrical
Mar 02 2016 08:36
ah okay. is a bit clearer now :-) thank you :-)