Package org.springframework.boot.context
Class ApplicationPidFileWriter
- java.lang.Object
- org.springframework.boot.context.ApplicationPidFileWriter
- All Implemented Interfaces:
EventListener
,org.springframework.context.ApplicationListener<SpringApplicationEvent>
,org.springframework.core.Ordered
public class ApplicationPidFileWriter extends Object implements org.springframework.context.ApplicationListener<SpringApplicationEvent>, org.springframework.core.Ordered
AnApplicationListener
that saves application PID into file. This application listener will be triggered exactly once per JVM, and the file name can be overridden at runtime with a System property or environment variable named "PIDFILE" (or "pidfile") or using aspring.pid.file
property in the SpringEnvironment
.If PID file can not be created no exception is reported. This behavior can be changed by assigning
true
to System property or environment variable namedPID_FAIL_ON_WRITE_ERROR
(or "pid_fail_on_write_error") or tospring.pid.fail-on-write-error
property in the SpringEnvironment
.Note: access to the Spring
Environment
is only possible when thetriggerEventType
is set toApplicationEnvironmentPreparedEvent
,ApplicationReadyEvent
, orApplicationPreparedEvent
.- Since:
- 2.0.0
Constructor Summary
Constructors Constructor Description ApplicationPidFileWriter()
Create a newApplicationPidFileWriter
instance using the filename 'application.pid'.ApplicationPidFileWriter(File file)
Create a newApplicationPidFileWriter
instance with a specified file.ApplicationPidFileWriter(String filename)
Create a newApplicationPidFileWriter
instance with a specified filename.
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
getOrder()
void
onApplicationEvent(SpringApplicationEvent event)
protected static void
reset()
Reset the created flag for testing purposes.void
setOrder(int order)
void
setTriggerEventType(Class<? extends SpringApplicationEvent> triggerEventType)
Sets the type of application event that will trigger writing of the PID file.
Constructor Detail
ApplicationPidFileWriter
public ApplicationPidFileWriter()
Create a newApplicationPidFileWriter
instance using the filename 'application.pid'.
ApplicationPidFileWriter
public ApplicationPidFileWriter(String filename)
Create a newApplicationPidFileWriter
instance with a specified filename.- Parameters:
filename
- the name of file containing pid
ApplicationPidFileWriter
public ApplicationPidFileWriter(File file)
Create a newApplicationPidFileWriter
instance with a specified file.- Parameters:
file
- the file containing pid
Method Detail
setTriggerEventType
public void setTriggerEventType(Class<? extends SpringApplicationEvent> triggerEventType)
Sets the type of application event that will trigger writing of the PID file. Defaults toApplicationPreparedEvent
. NOTE: If you use theApplicationStartingEvent
to trigger the write, you will not be able to specify the PID filename in the SpringEnvironment
.- Parameters:
triggerEventType
- the trigger event type
onApplicationEvent
public void onApplicationEvent(SpringApplicationEvent event)
- Specified by:
onApplicationEvent
in interfaceorg.springframework.context.ApplicationListener<SpringApplicationEvent>
setOrder
public void setOrder(int order)
getOrder
public int getOrder()
- Specified by:
getOrder
in interfaceorg.springframework.core.Ordered
reset
protected static void reset()
Reset the created flag for testing purposes.