-
Notifications
You must be signed in to change notification settings - Fork 84
Adding support for a new platform
To add support for a new platform, you need to write a new class that implements the interface com.jezhumble.javasysmon.Monitor
. The class needs to be instantiated in the static initializing block in com.jezhumble.javasysmon.JavaSysMon
.
You need to write a zero-argument constructor in your new class that does two things:
- calls
JavaSysMon.addSupportedConfig
with a string describing the platform your new class supports - checks if it is running on a supported platform, and calls
JavaSysMon.setMonitor
with an instance of itself if so
Take a look at some of the existing classes that implement Monitor
to see how to do this.
Then of course you actually need to implement the interface.
This is the easiest option. Take a look at LinuxSystemMonitor for an example of this. You just need to implement the Monitor
interface.
You’ll need to mess with JNI to get this working. First of all, create a Java class which implements Monitor, but makes the necessary methods native (see MacOsXMonitor
for an example). Then run ant
to build the project, and run javah
from within the target
directory with the fully qualified class name as an argument. This will generate a C header file.
Create a directory under src/main/c
named after the platform you’re supporting, and copy the C header there. Put all the C code required to create the native library there, and check it in.
Once you have a native library binary, copy it inside lib/native
, and check it in. You can then run ant
again to package up the jar and test it.