Class AbstractOperatingSystem

    • Field Detail

      • USE_WHO_COMMAND

        protected static final boolean USE_WHO_COMMAND
      • manufacturer

        private final java.util.function.Supplier<java.lang.String> manufacturer
      • bitness

        private final java.util.function.Supplier<java.lang.Integer> bitness
    • Constructor Detail

      • AbstractOperatingSystem

        public AbstractOperatingSystem()
    • Method Detail

      • getManufacturer

        public java.lang.String getManufacturer()
        Description copied from interface: OperatingSystem
        Get the Operating System manufacturer.
        Specified by:
        getManufacturer in interface OperatingSystem
        Returns:
        the manufacturer
      • queryManufacturer

        protected abstract java.lang.String queryManufacturer()
      • getFamily

        public java.lang.String getFamily()
        Description copied from interface: OperatingSystem
        Get the Operating System family.
        Specified by:
        getFamily in interface OperatingSystem
        Returns:
        the family
      • getBitness

        public int getBitness()
        Description copied from interface: OperatingSystem
        Gets the bitness (32 or 64) of the operating system.
        Specified by:
        getBitness in interface OperatingSystem
        Returns:
        The number of bits supported by the operating system.
      • queryPlatformBitness

        private int queryPlatformBitness()
      • queryBitness

        protected abstract int queryBitness​(int jvmBitness)
        Backup OS-specific query to determine bitness if previous checks fail
        Parameters:
        jvmBitness - The bitness of the JVM
        Returns:
        The operating system bitness
      • getProcesses

        public java.util.List<OSProcess> getProcesses​(java.util.function.Predicate<OSProcess> filter,
                                                      java.util.Comparator<OSProcess> sort,
                                                      int limit)
        Description copied from interface: OperatingSystem
        Gets currently running processes, optionally filtering, sorting, and limited to the top "N".
        Specified by:
        getProcesses in interface OperatingSystem
        Parameters:
        filter - An optional Predicate limiting the results to the specified filter. Some common predicates are available in OperatingSystem.ProcessSorting. May be null for no filtering.
        sort - An optional Comparator specifying the sorting order. Some common comparators are available in OperatingSystem.ProcessSorting. May be null for no sorting.
        limit - Max number of results to return, or 0 to return all results
        Returns:
        A list of OSProcess objects, optionally filtered, sorted, and limited to the specified number.

        The list may contain processes with a state of OSProcess.State.INVALID if a process terminates during iteration.

      • queryAllProcesses

        protected abstract java.util.List<OSProcess> queryAllProcesses()
      • getChildProcesses

        public java.util.List<OSProcess> getChildProcesses​(int parentPid,
                                                           java.util.function.Predicate<OSProcess> filter,
                                                           java.util.Comparator<OSProcess> sort,
                                                           int limit)
        Description copied from interface: OperatingSystem
        Gets currently running child processes of provided parent PID, optionally filtering, sorting, and limited to the top "N".
        Specified by:
        getChildProcesses in interface OperatingSystem
        Parameters:
        parentPid - The Process ID whose children to list.
        filter - An optional Predicate limiting the results to the specified filter. Some common predicates are available in OperatingSystem.ProcessSorting. May be null for no filtering.
        sort - An optional Comparator specifying the sorting order. Some common comparators are available in OperatingSystem.ProcessSorting. May be null for no sorting.
        limit - Max number of results to return, or 0 to return all results
        Returns:
        A list of OSProcess objects representing the currently running child processes of the provided PID, optionally filtered, sorted, and limited to the specified number.

        The list may contain processes with a state of OSProcess.State.INVALID if a process terminates during iteration.

      • queryChildProcesses

        protected abstract java.util.List<OSProcess> queryChildProcesses​(int parentPid)
      • getDescendantProcesses

        public java.util.List<OSProcess> getDescendantProcesses​(int parentPid,
                                                                java.util.function.Predicate<OSProcess> filter,
                                                                java.util.Comparator<OSProcess> sort,
                                                                int limit)
        Description copied from interface: OperatingSystem
        Gets currently running processes of provided parent PID's descendants, including their children, the children's children, etc., optionally filtering, sorting, and limited to the top "N".
        Specified by:
        getDescendantProcesses in interface OperatingSystem
        Parameters:
        parentPid - The Process ID whose children to list.
        filter - An optional Predicate limiting the results to the specified filter. Some common predicates are available in OperatingSystem.ProcessSorting. May be null for no filtering.
        sort - An optional Comparator specifying the sorting order. Some common comparators are available in OperatingSystem.ProcessSorting. May be null for no sorting.
        limit - Max number of results to return, or 0 to return all results
        Returns:
        A list of OSProcess objects representing the currently running descendant processes of the provided PID, optionally filtered, sorted, and limited to the specified number.

        The list may contain processes with a state of OSProcess.State.INVALID if a process terminates during iteration.

      • queryDescendantProcesses

        protected abstract java.util.List<OSProcess> queryDescendantProcesses​(int parentPid)
      • getChildrenOrDescendants

        protected static java.util.Set<java.lang.Integer> getChildrenOrDescendants​(java.util.Collection<OSProcess> allProcs,
                                                                                   int parentPid,
                                                                                   boolean allDescendants)
        Utility method for subclasses to take a full process list as input and return the children or descendants of a particular process. The process itself is also returned to more efficiently extract its start time for filtering
        Parameters:
        allProcs - A collection of all processes
        parentPid - The process ID whose children or descendants to return
        allDescendants - If false, only gets immediate children of this process. If true, gets all descendants.
        Returns:
        Set of children or descendants of parentPid
      • getChildrenOrDescendants

        protected static java.util.Set<java.lang.Integer> getChildrenOrDescendants​(java.util.Map<java.lang.Integer,​java.lang.Integer> parentPidMap,
                                                                                   int parentPid,
                                                                                   boolean allDescendants)
        Utility method for subclasses to take a map of pid to parent as input and return the children or descendants of a particular process.
        Parameters:
        parentPidMap - a map of all processes with processID as key and parentProcessID as value
        parentPid - The process ID whose children or descendants to return
        allDescendants - If false, only gets immediate children of this process. If true, gets all descendants.
        Returns:
        Set of children or descendants of parentPid, including the parent
      • getChildren

        private static java.util.Set<java.lang.Integer> getChildren​(java.util.Map<java.lang.Integer,​java.lang.Integer> parentPidMap,
                                                                    int parentPid)
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object