Package org.springframework.boot.context
Class ApplicationPidFileWriter
java.lang.Object
org.springframework.boot.context.ApplicationPidFileWriter
- All Implemented Interfaces:
EventListener,ApplicationListener<SpringApplicationEvent>,Ordered
public class ApplicationPidFileWriter
extends Object
implements ApplicationListener<SpringApplicationEvent>, Ordered
An
ApplicationListener 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 a spring.pid.file property in the Spring Environment.
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 named
PID_FAIL_ON_WRITE_ERROR (or "pid_fail_on_write_error") or to
spring.pid.fail-on-write-error property in the Spring Environment.
Note: access to the Spring Environment is only possible when the
triggerEventType is set to
ApplicationEnvironmentPreparedEvent, ApplicationReadyEvent, or
ApplicationPreparedEvent.
- Since:
- 2.0.0
- Author:
- Jakub Kubrynski, Dave Syer, Phillip Webb, Tomasz Przybyla, Madhura Bhave
-
Field Summary
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Constructor Summary
ConstructorsConstructorDescriptionCreate a newApplicationPidFileWriterinstance using the filename 'application.pid'.ApplicationPidFileWriter(File file) Create a newApplicationPidFileWriterinstance with a specified file.ApplicationPidFileWriter(String filename) Create a newApplicationPidFileWriterinstance with a specified filename. -
Method Summary
Modifier and TypeMethodDescriptionintgetOrder()voidprotected static voidreset()Reset the created flag for testing purposes.voidsetOrder(int order) voidsetTriggerEventType(Class<? extends SpringApplicationEvent> triggerEventType) Sets the type of application event that will trigger writing of the PID file.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.context.ApplicationListener
supportsAsyncExecution
-
Constructor Details
-
ApplicationPidFileWriter
public ApplicationPidFileWriter()Create a newApplicationPidFileWriterinstance using the filename 'application.pid'. -
ApplicationPidFileWriter
Create a newApplicationPidFileWriterinstance with a specified filename.- Parameters:
filename- the name of file containing pid
-
ApplicationPidFileWriter
Create a newApplicationPidFileWriterinstance with a specified file.- Parameters:
file- the file containing pid
-
-
Method Details
-
setTriggerEventType
Sets the type of application event that will trigger writing of the PID file. Defaults toApplicationPreparedEvent. NOTE: If you use theApplicationStartingEventto trigger the write, you will not be able to specify the PID filename in the SpringEnvironment.- Parameters:
triggerEventType- the trigger event type
-
onApplicationEvent
- Specified by:
onApplicationEventin interfaceApplicationListener<SpringApplicationEvent>
-
setOrder
public void setOrder(int order) -
getOrder
public int getOrder() -
reset
protected static void reset()Reset the created flag for testing purposes.
-