Package io.microsphere.process
Class VirtualMachineProcessIdResolver
- java.lang.Object
-
- io.microsphere.process.VirtualMachineProcessIdResolver
-
- All Implemented Interfaces:
Prioritized,ProcessIdResolver,java.lang.Comparable<Prioritized>
public class VirtualMachineProcessIdResolver extends java.lang.Object implements ProcessIdResolver
AProcessIdResolverimplementation for retrieving the process ID using the SUN JVM internal APIs.This resolver utilizes reflection to access the internal fields and methods of the JVM, specifically targeting the
sun.management.VMManagementImplclass which provides a method to retrieve the native process ID.How It Works
The process ID is obtained via reflection by accessing the hidden "jvm" field in the
RuntimeMXBeaninstance, and then invoking thegetProcessId()method on that internal object. This approach is specific to the HotSpot JVM and may not be available on all JVM implementations.Example Usage
ProcessIdResolver resolver = new VirtualMachineProcessIdResolver(); if (resolver.supports()) { Long pid = resolver.current(); System.out.println("Current Process ID: " + pid); }Priority
This resolver has a priority level of
getPriority(), making it preferred over some other resolvers but not the highest priority. The priority helps determine which resolver should be used when multiple resolvers are available.- Since:
- 1.0.0
- Author:
- Mercy
- See Also:
ProcessIdResolver
-
-
Field Summary
-
Fields inherited from interface io.microsphere.lang.Prioritized
COMPARATOR, MAX_PRIORITY, MIN_PRIORITY, NORMAL_PRIORITY
-
Fields inherited from interface io.microsphere.process.ProcessIdResolver
UNKNOWN_PROCESS_ID
-
-
Constructor Summary
Constructors Constructor Description VirtualMachineProcessIdResolver()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Longcurrent()Resolve the current process idintgetPriority()Get the prioritybooleansupports()Whether supports to resolve the process id or not?-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.microsphere.lang.Prioritized
compareTo
-
-
-
-
Method Detail
-
supports
public boolean supports()
Description copied from interface:ProcessIdResolverWhether supports to resolve the process id or not?- Specified by:
supportsin interfaceProcessIdResolver- Returns:
trueif supports, otherwisefalse
-
current
public java.lang.Long current()
Description copied from interface:ProcessIdResolverResolve the current process id- Specified by:
currentin interfaceProcessIdResolver- Returns:
>nullif can't be resolved
-
getPriority
public int getPriority()
Description copied from interface:PrioritizedGet the priority- Specified by:
getPriorityin interfacePrioritized- Returns:
- the default is
minimum one
-
-