Добавлен эндпоинт для запуска pcap

This commit is contained in:
serega6531
2020-04-06 01:46:06 +03:00
parent a0ceda4cb4
commit 0391d55e91
8 changed files with 83 additions and 6 deletions

View File

@@ -6,7 +6,8 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.event.EventListener;
import ru.serega6531.packmate.pcap.PcapWorker;
import ru.serega6531.packmate.model.enums.CaptureMode;
import ru.serega6531.packmate.service.PcapService;
@SpringBootApplication
public class PackmateApplication {
@@ -14,15 +15,18 @@ public class PackmateApplication {
@Value("${enable-capture}")
private boolean enableCapture;
@Value("${capture-mode}")
private CaptureMode captureMode;
public static void main(String[] args) {
SpringApplication.run(PackmateApplication.class, args);
}
@EventListener(ApplicationReadyEvent.class)
public void afterStartup(ApplicationReadyEvent event) throws PcapNativeException {
if (enableCapture) {
final PcapWorker pcapWorker = event.getApplicationContext().getBean(PcapWorker.class);
pcapWorker.start();
if (enableCapture && captureMode == CaptureMode.LIVE) {
final PcapService pcapService = event.getApplicationContext().getBean(PcapService.class);
pcapService.start();
}
}