public class ApplicationPidFileWriter extends Object implements org.springframework.context.ApplicationListener<SpringApplicationEvent>, org.springframework.core.Ordered
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
.
Constructor and Description |
---|
ApplicationPidFileWriter()
Create a new
ApplicationPidFileWriter instance using the filename
'application.pid'. |
ApplicationPidFileWriter(File file)
Create a new
ApplicationPidFileWriter instance with a specified file. |
ApplicationPidFileWriter(String filename)
Create a new
ApplicationPidFileWriter instance with a specified filename. |
Modifier and Type | Method and 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.
|
public ApplicationPidFileWriter()
ApplicationPidFileWriter
instance using the filename
'application.pid'.public ApplicationPidFileWriter(String filename)
ApplicationPidFileWriter
instance with a specified filename.filename
- the name of file containing pidpublic ApplicationPidFileWriter(File file)
ApplicationPidFileWriter
instance with a specified file.file
- the file containing pidpublic void setTriggerEventType(Class<? extends SpringApplicationEvent> triggerEventType)
ApplicationPreparedEvent
. NOTE: If you use the
ApplicationStartingEvent
to trigger
the write, you will not be able to specify the PID filename in the Spring
Environment
.triggerEventType
- the trigger event typepublic void onApplicationEvent(SpringApplicationEvent event)
onApplicationEvent
in interface org.springframework.context.ApplicationListener<SpringApplicationEvent>
public void setOrder(int order)
public int getOrder()
getOrder
in interface org.springframework.core.Ordered
protected static void reset()
Copyright © 2018 Pivotal Software, Inc.. All rights reserved.