Class SysctlUtil


  • @ThreadSafe
    public final class SysctlUtil
    extends java.lang.Object
    Provides access to sysctl calls on macOS
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static org.slf4j.Logger LOG  
      private static java.lang.String SYSCTL_FAIL  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private SysctlUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static com.sun.jna.Memory sysctl​(java.lang.String name)
      Executes a sysctl call with a Pointer result
      static int sysctl​(java.lang.String name, int def)
      Executes a sysctl call with an int result
      static int sysctl​(java.lang.String name, int def, boolean logWarning)
      Executes a sysctl call with an int result
      static long sysctl​(java.lang.String name, long def)
      Executes a sysctl call with a long result
      static boolean sysctl​(java.lang.String name, com.sun.jna.Structure struct)
      Executes a sysctl call with a Structure result
      static java.lang.String sysctl​(java.lang.String name, java.lang.String def)
      Executes a sysctl call with a String result
      static java.lang.String sysctl​(java.lang.String name, java.lang.String def, boolean logWarning)
      Executes a sysctl call with a String result
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • LOG

        private static final org.slf4j.Logger LOG
    • Constructor Detail

      • SysctlUtil

        private SysctlUtil()
    • Method Detail

      • sysctl

        public static int sysctl​(java.lang.String name,
                                 int def)
        Executes a sysctl call with an int result
        Parameters:
        name - name of the sysctl
        def - default int value
        Returns:
        The int result of the call if successful; the default otherwise
      • sysctl

        public static int sysctl​(java.lang.String name,
                                 int def,
                                 boolean logWarning)
        Executes a sysctl call with an int result
        Parameters:
        name - name of the sysctl
        def - default int value
        logWarning - whether to log the warning if not available
        Returns:
        The int result of the call if successful; the default otherwise
      • sysctl

        public static long sysctl​(java.lang.String name,
                                  long def)
        Executes a sysctl call with a long result
        Parameters:
        name - name of the sysctl
        def - default long value
        Returns:
        The long result of the call if successful; the default otherwise
      • sysctl

        public static java.lang.String sysctl​(java.lang.String name,
                                              java.lang.String def)
        Executes a sysctl call with a String result
        Parameters:
        name - name of the sysctl
        def - default String value
        Returns:
        The String result of the call if successful; the default otherwise
      • sysctl

        public static java.lang.String sysctl​(java.lang.String name,
                                              java.lang.String def,
                                              boolean logWarning)
        Executes a sysctl call with a String result
        Parameters:
        name - name of the sysctl
        def - default String value
        logWarning - whether to log the warning if not available
        Returns:
        The String result of the call if successful; the default otherwise
      • sysctl

        public static boolean sysctl​(java.lang.String name,
                                     com.sun.jna.Structure struct)
        Executes a sysctl call with a Structure result
        Parameters:
        name - name of the sysctl
        struct - structure for the result
        Returns:
        True if structure is successfuly populated, false otherwise
      • sysctl

        public static com.sun.jna.Memory sysctl​(java.lang.String name)
        Executes a sysctl call with a Pointer result
        Parameters:
        name - name of the sysctl
        Returns:
        An allocated memory buffer containing the result on success, null otherwise. Its value on failure is undefined.