ServerController
This commit is contained in:
parent
16f5a62c9c
commit
82e8aa1712
20
src/main/java/de/ph87/homeautomation/ServerController.java
Normal file
20
src/main/java/de/ph87/homeautomation/ServerController.java
Normal file
@ -0,0 +1,20 @@
|
||||
package de.ph87.homeautomation;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("server")
|
||||
@RequiredArgsConstructor
|
||||
public class ServerController {
|
||||
|
||||
private final ServerService serverService;
|
||||
|
||||
@GetMapping("shutdown")
|
||||
public void shutdown() {
|
||||
serverService.shutdownAsync();
|
||||
}
|
||||
|
||||
}
|
||||
29
src/main/java/de/ph87/homeautomation/ServerService.java
Normal file
29
src/main/java/de/ph87/homeautomation/ServerService.java
Normal file
@ -0,0 +1,29 @@
|
||||
package de.ph87.homeautomation;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@EnableAsync
|
||||
@RequiredArgsConstructor
|
||||
public class ServerService {
|
||||
|
||||
private final ApplicationContext context;
|
||||
|
||||
@Async
|
||||
public void shutdownAsync() {
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
// ignore
|
||||
}
|
||||
((ConfigurableApplicationContext) context).close();
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user