Java 类org.springframework.boot.context.event.SpringApplicationEvent 实例源码
项目:https-github.com-g0t4-jenkins2-course-spring-boot
文件:ApplicationPidFileWriter.java
@Override
public void onApplicationEvent(SpringApplicationEvent event) {
if (this.triggerEventType.isInstance(event)) {
if (created.compareAndSet(false, true)) {
try {
writePidFile(event);
}
catch (Exception ex) {
String message = String.format("Cannot create pid file %s",
this.file);
if (failOnWriteError(event)) {
throw new IllegalStateException(message, ex);
}
logger.warn(message, ex);
}
}
}
}
项目:spring-boot-concourse
文件:ApplicationPidFileWriter.java
@Override
public void onApplicationEvent(SpringApplicationEvent event) {
if (this.triggerEventType.isInstance(event)) {
if (created.compareAndSet(false, true)) {
try {
writePidFile(event);
}
catch (Exception ex) {
String message = String.format("Cannot create pid file %s",
this.file);
if (failOnWriteError(event)) {
throw new IllegalStateException(message, ex);
}
logger.warn(message, ex);
}
}
}
}
项目:contestparser
文件:ApplicationPidFileWriter.java
@Override
public void onApplicationEvent(SpringApplicationEvent event) {
if (this.triggerEventType.isInstance(event)) {
if (created.compareAndSet(false, true)) {
try {
writePidFile(event);
}
catch (Exception ex) {
String message = String.format("Cannot create pid file %s",
this.file);
if (failOnWriteError(event)) {
throw new IllegalStateException(message, ex);
}
logger.warn(message, ex);
}
}
}
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot
文件:ApplicationPidFileWriter.java
private void writePidFile(SpringApplicationEvent event) throws IOException {
File pidFile = this.file;
String override = getProperty(event, FILE_PROPERTIES);
if (override != null) {
pidFile = new File(override);
}
new ApplicationPid().write(pidFile);
pidFile.deleteOnExit();
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot
文件:ApplicationPidFileWriter.java
private String getProperty(SpringApplicationEvent event, List<Property> candidates) {
for (Property candidate : candidates) {
String value = candidate.getValue(event);
if (value != null) {
return value;
}
}
return null;
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot
文件:ApplicationPidFileWriter.java
@Override
public String getValue(SpringApplicationEvent event) {
Environment environment = getEnvironment(event);
if (environment == null) {
return null;
}
return new RelaxedPropertyResolver(environment, this.prefix)
.getProperty(this.key);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot
文件:ApplicationPidFileWriter.java
private Environment getEnvironment(SpringApplicationEvent event) {
if (event instanceof ApplicationEnvironmentPreparedEvent) {
return ((ApplicationEnvironmentPreparedEvent) event).getEnvironment();
}
if (event instanceof ApplicationPreparedEvent) {
return ((ApplicationPreparedEvent) event).getApplicationContext()
.getEnvironment();
}
return null;
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot
文件:ApplicationPidFileWriterTests.java
@Test
public void overridePidFileWithSpring() throws Exception {
File file = this.temporaryFolder.newFile();
SpringApplicationEvent event = createPreparedEvent("spring.pid.file",
file.getAbsolutePath());
ApplicationPidFileWriter listener = new ApplicationPidFileWriter();
listener.onApplicationEvent(event);
assertThat(FileCopyUtils.copyToString(new FileReader(file))).isNotEmpty();
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot
文件:ApplicationPidFileWriterTests.java
@Test
public void differentEventTypes() throws Exception {
File file = this.temporaryFolder.newFile();
SpringApplicationEvent event = createEnvironmentPreparedEvent("spring.pid.file",
file.getAbsolutePath());
ApplicationPidFileWriter listener = new ApplicationPidFileWriter();
listener.onApplicationEvent(event);
assertThat(FileCopyUtils.copyToString(new FileReader(file))).isEmpty();
listener.setTriggerEventType(ApplicationEnvironmentPreparedEvent.class);
listener.onApplicationEvent(event);
assertThat(FileCopyUtils.copyToString(new FileReader(file))).isNotEmpty();
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot
文件:ApplicationPidFileWriterTests.java
@Test
public void throwWhenPidFileIsReadOnlyWithSpring() throws Exception {
File file = this.temporaryFolder.newFile();
file.setReadOnly();
SpringApplicationEvent event = createPreparedEvent(
"spring.pid.fail-on-write-error", "true");
ApplicationPidFileWriter listener = new ApplicationPidFileWriter(file);
this.exception.expect(IllegalStateException.class);
this.exception.expectMessage("Cannot create pid file");
listener.onApplicationEvent(event);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot
文件:ApplicationPidFileWriterTests.java
private SpringApplicationEvent createPreparedEvent(String propName,
String propValue) {
ConfigurableEnvironment environment = createEnvironment(propName, propValue);
ConfigurableApplicationContext context = mock(
ConfigurableApplicationContext.class);
given(context.getEnvironment()).willReturn(environment);
return new ApplicationPreparedEvent(new SpringApplication(), new String[] {},
context);
}
项目:spring-boot-concourse
文件:ApplicationPidFileWriter.java
private void writePidFile(SpringApplicationEvent event) throws IOException {
File pidFile = this.file;
String override = getProperty(event, FILE_PROPERTIES);
if (override != null) {
pidFile = new File(override);
}
new ApplicationPid().write(pidFile);
pidFile.deleteOnExit();
}
项目:spring-boot-concourse
文件:ApplicationPidFileWriter.java
private String getProperty(SpringApplicationEvent event, List<Property> candidates) {
for (Property candidate : candidates) {
String value = candidate.getValue(event);
if (value != null) {
return value;
}
}
return null;
}
项目:spring-boot-concourse
文件:ApplicationPidFileWriter.java
@Override
public String getValue(SpringApplicationEvent event) {
Environment environment = getEnvironment(event);
if (environment == null) {
return null;
}
return new RelaxedPropertyResolver(environment, this.prefix)
.getProperty(this.key);
}
项目:spring-boot-concourse
文件:ApplicationPidFileWriter.java
private Environment getEnvironment(SpringApplicationEvent event) {
if (event instanceof ApplicationEnvironmentPreparedEvent) {
return ((ApplicationEnvironmentPreparedEvent) event).getEnvironment();
}
if (event instanceof ApplicationPreparedEvent) {
return ((ApplicationPreparedEvent) event).getApplicationContext()
.getEnvironment();
}
return null;
}
项目:spring-boot-concourse
文件:ApplicationPidFileWriterTests.java
@Test
public void overridePidFileWithSpring() throws Exception {
File file = this.temporaryFolder.newFile();
SpringApplicationEvent event = createPreparedEvent("spring.pid.file",
file.getAbsolutePath());
ApplicationPidFileWriter listener = new ApplicationPidFileWriter();
listener.onApplicationEvent(event);
assertThat(FileCopyUtils.copyToString(new FileReader(file))).isNotEmpty();
}
项目:spring-boot-concourse
文件:ApplicationPidFileWriterTests.java
@Test
public void differentEventTypes() throws Exception {
File file = this.temporaryFolder.newFile();
SpringApplicationEvent event = createEnvironmentPreparedEvent("spring.pid.file",
file.getAbsolutePath());
ApplicationPidFileWriter listener = new ApplicationPidFileWriter();
listener.onApplicationEvent(event);
assertThat(FileCopyUtils.copyToString(new FileReader(file))).isEmpty();
listener.setTriggerEventType(ApplicationEnvironmentPreparedEvent.class);
listener.onApplicationEvent(event);
assertThat(FileCopyUtils.copyToString(new FileReader(file))).isNotEmpty();
}
项目:spring-boot-concourse
文件:ApplicationPidFileWriterTests.java
@Test
public void throwWhenPidFileIsReadOnlyWithSpring() throws Exception {
File file = this.temporaryFolder.newFile();
file.setReadOnly();
SpringApplicationEvent event = createPreparedEvent(
"spring.pid.fail-on-write-error", "true");
ApplicationPidFileWriter listener = new ApplicationPidFileWriter(file);
this.exception.expect(IllegalStateException.class);
this.exception.expectMessage("Cannot create pid file");
listener.onApplicationEvent(event);
}
项目:spring-boot-concourse
文件:ApplicationPidFileWriterTests.java
private SpringApplicationEvent createPreparedEvent(String propName,
String propValue) {
ConfigurableEnvironment environment = createEnvironment(propName, propValue);
ConfigurableApplicationContext context = mock(
ConfigurableApplicationContext.class);
given(context.getEnvironment()).willReturn(environment);
return new ApplicationPreparedEvent(new SpringApplication(), new String[] {},
context);
}
项目:contestparser
文件:ApplicationPidFileWriter.java
private void writePidFile(SpringApplicationEvent event) throws IOException {
File pidFile = this.file;
String override = getProperty(event, FILE_PROPERTIES);
if (override != null) {
pidFile = new File(override);
}
new ApplicationPid().write(pidFile);
pidFile.deleteOnExit();
}
项目:contestparser
文件:ApplicationPidFileWriter.java
private String getProperty(SpringApplicationEvent event, List<Property> candidates) {
for (Property candidate : candidates) {
String value = candidate.getValue(event);
if (value != null) {
return value;
}
}
return null;
}
项目:contestparser
文件:ApplicationPidFileWriter.java
@Override
public String getValue(SpringApplicationEvent event) {
Environment environment = getEnvironment(event);
if (environment == null) {
return null;
}
return new RelaxedPropertyResolver(environment, this.prefix)
.getProperty(this.key);
}
项目:contestparser
文件:ApplicationPidFileWriter.java
private Environment getEnvironment(SpringApplicationEvent event) {
if (event instanceof ApplicationEnvironmentPreparedEvent) {
return ((ApplicationEnvironmentPreparedEvent) event).getEnvironment();
}
if (event instanceof ApplicationPreparedEvent) {
return ((ApplicationPreparedEvent) event).getApplicationContext()
.getEnvironment();
}
return null;
}
项目:contestparser
文件:ApplicationPidFileWriterTests.java
@Test
public void overridePidFileWithSpring() throws Exception {
File file = this.temporaryFolder.newFile();
SpringApplicationEvent event = createPreparedEvent("spring.pid.file",
file.getAbsolutePath());
ApplicationPidFileWriter listener = new ApplicationPidFileWriter();
listener.onApplicationEvent(event);
assertThat(FileCopyUtils.copyToString(new FileReader(file)),
not(isEmptyString()));
}
项目:contestparser
文件:ApplicationPidFileWriterTests.java
@Test
public void differentEventTypes() throws Exception {
File file = this.temporaryFolder.newFile();
SpringApplicationEvent event = createEnvironmentPreparedEvent("spring.pid.file",
file.getAbsolutePath());
ApplicationPidFileWriter listener = new ApplicationPidFileWriter();
listener.onApplicationEvent(event);
assertThat(FileCopyUtils.copyToString(new FileReader(file)), isEmptyString());
listener.setTriggerEventType(ApplicationEnvironmentPreparedEvent.class);
listener.onApplicationEvent(event);
assertThat(FileCopyUtils.copyToString(new FileReader(file)),
not(isEmptyString()));
}
项目:contestparser
文件:ApplicationPidFileWriterTests.java
@Test
public void throwWhenPidFileIsReadOnlyWithSpring() throws Exception {
File file = this.temporaryFolder.newFile();
file.setReadOnly();
SpringApplicationEvent event = createPreparedEvent(
"spring.pid.fail-on-write-error", "true");
ApplicationPidFileWriter listener = new ApplicationPidFileWriter(file);
this.exception.expect(IllegalStateException.class);
this.exception.expectMessage("Cannot create pid file");
listener.onApplicationEvent(event);
}
项目:contestparser
文件:ApplicationPidFileWriterTests.java
private SpringApplicationEvent createPreparedEvent(String propName,
String propValue) {
ConfigurableEnvironment environment = createEnvironment(propName, propValue);
ConfigurableApplicationContext context = mock(
ConfigurableApplicationContext.class);
given(context.getEnvironment()).willReturn(environment);
return new ApplicationPreparedEvent(new SpringApplication(), new String[] {},
context);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot
文件:ApplicationPidFileWriter.java
private boolean failOnWriteError(SpringApplicationEvent event) {
String value = getProperty(event, FAIL_ON_WRITE_ERROR_PROPERTIES);
return (value == null ? false : Boolean.parseBoolean(value));
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot
文件:ApplicationPidFileWriter.java
@Override
public String getValue(SpringApplicationEvent event) {
return SystemProperties.get(this.properties);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot
文件:ApplicationPidFileWriterTests.java
private SpringApplicationEvent createEnvironmentPreparedEvent(String propName,
String propValue) {
ConfigurableEnvironment environment = createEnvironment(propName, propValue);
return new ApplicationEnvironmentPreparedEvent(new SpringApplication(),
new String[] {}, environment);
}
项目:spring-boot-concourse
文件:ApplicationPidFileWriter.java
private boolean failOnWriteError(SpringApplicationEvent event) {
String value = getProperty(event, FAIL_ON_WRITE_ERROR_PROPERTIES);
return (value == null ? false : Boolean.parseBoolean(value));
}
项目:spring-boot-concourse
文件:ApplicationPidFileWriter.java
@Override
public String getValue(SpringApplicationEvent event) {
return SystemProperties.get(this.properties);
}
项目:spring-boot-concourse
文件:ApplicationPidFileWriterTests.java
private SpringApplicationEvent createEnvironmentPreparedEvent(String propName,
String propValue) {
ConfigurableEnvironment environment = createEnvironment(propName, propValue);
return new ApplicationEnvironmentPreparedEvent(new SpringApplication(),
new String[] {}, environment);
}
项目:contestparser
文件:ApplicationPidFileWriter.java
private boolean failOnWriteError(SpringApplicationEvent event) {
String value = getProperty(event, FAIL_ON_WRITE_ERROR_PROPERTIES);
return (value == null ? false : Boolean.parseBoolean(value));
}
项目:contestparser
文件:ApplicationPidFileWriter.java
@Override
public String getValue(SpringApplicationEvent event) {
return SystemProperties.get(this.properties);
}
项目:contestparser
文件:ApplicationPidFileWriterTests.java
private SpringApplicationEvent createEnvironmentPreparedEvent(String propName,
String propValue) {
ConfigurableEnvironment environment = createEnvironment(propName, propValue);
return new ApplicationEnvironmentPreparedEvent(new SpringApplication(),
new String[] {}, environment);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot
文件:ApplicationPidFileWriter.java
/**
* Sets the type of application event that will trigger writing of the PID file.
* Defaults to {@link ApplicationPreparedEvent}. NOTE: If you use the
* {@link org.springframework.boot.context.event.ApplicationStartedEvent} to trigger
* the write, you will not be able to specify the PID filename in the Spring
* {@link Environment}.
* @param triggerEventType the trigger event type
*/
public void setTriggerEventType(
Class<? extends SpringApplicationEvent> triggerEventType) {
Assert.notNull(triggerEventType, "Trigger event type must not be null");
this.triggerEventType = triggerEventType;
}
项目:spring-boot-concourse
文件:ApplicationPidFileWriter.java
/**
* Sets the type of application event that will trigger writing of the PID file.
* Defaults to {@link ApplicationPreparedEvent}. NOTE: If you use the
* {@link org.springframework.boot.context.event.ApplicationStartedEvent} to trigger
* the write, you will not be able to specify the PID filename in the Spring
* {@link Environment}.
* @param triggerEventType the trigger event type
*/
public void setTriggerEventType(
Class<? extends SpringApplicationEvent> triggerEventType) {
Assert.notNull(triggerEventType, "Trigger event type must not be null");
this.triggerEventType = triggerEventType;
}
项目:contestparser
文件:ApplicationPidFileWriter.java
/**
* Sets the type of application event that will trigger writing of the PID file.
* Defaults to {@link ApplicationPreparedEvent}. NOTE: If you use the
* {@link org.springframework.boot.context.event.ApplicationStartedEvent} to trigger
* the write, you will not be able to specify the PID filename in the Spring
* {@link Environment}.
* @param triggerEventType the trigger event type
*/
public void setTriggerEventType(
Class<? extends SpringApplicationEvent> triggerEventType) {
Assert.notNull(triggerEventType, "Trigger event type must not be null");
this.triggerEventType = triggerEventType;
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot
文件:ApplicationPidFileWriter.java
String getValue(SpringApplicationEvent event);