Package io.microsphere.process
Class ClassicProcessIdResolver
- java.lang.Object
-
- io.microsphere.process.ClassicProcessIdResolver
-
- All Implemented Interfaces:
Prioritized,ProcessIdResolver,java.lang.Comparable<Prioritized>
public class ClassicProcessIdResolver extends java.lang.Object implements ProcessIdResolver
AProcessIdResolverimplementation for classic JDK versions (5 - 8).This class resolves the current process ID using the name obtained from
RuntimeMXBean.getName(). The format of the returned name is usually:pid@hostname
pidrepresents the process ID. This resolver extracts and returns the numeric part before the '@' symbol.Supported Environments
This resolver is designed to work on Java 5 through Java 8, where newer APIs like
java.lang.ProcessHandle#current()are not available.Example Output
// Assuming RuntimeMXBean.getName() returns "12345@localhost" ClassicProcessIdResolver resolver = new ClassicProcessIdResolver(); if (resolver.supports()) { Long pid = resolver.current(); System.out.println("Current PID: " + pid); // Outputs: Current PID: 12345 }Logging Behavior
If trace logging is enabled via the underlying logger (
Logger), this resolver logs the resolved PID along with the raw value obtained from the runtime MXBean:[TRACE] The PID was resolved from the method 'java.lang.management.RuntimeMXBean#getName()' = 12345@localhost : 12345Priority
This resolver has a priority level set to
Prioritized.NORMAL_PRIORITYplus 9, which means it will be considered after resolvers with higher priority but before those with lower.- 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 ClassicProcessIdResolver()
-
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
-
-