Merge der Refaktorisierung des EndlessConsumer (Branch 'stored-state')
[demos/kafka/training] / src / main / java / de / juplo / kafka / DriverController.java
1 package de.juplo.kafka;
2
3 import lombok.RequiredArgsConstructor;
4 import org.springframework.http.HttpStatus;
5 import org.springframework.web.bind.annotation.ExceptionHandler;
6 import org.springframework.web.bind.annotation.GetMapping;
7 import org.springframework.web.bind.annotation.PostMapping;
8 import org.springframework.web.bind.annotation.ResponseStatus;
9 import org.springframework.web.bind.annotation.RestController;
10
11 import java.util.Map;
12 import java.util.concurrent.ExecutionException;
13
14
15 @RestController
16 @RequiredArgsConstructor
17 public class DriverController
18 {
19   private final EndlessConsumer consumer;
20
21
22   @PostMapping("start")
23   public void start()
24   {
25     consumer.start();
26   }
27
28   @PostMapping("stop")
29   public void stop() throws ExecutionException, InterruptedException
30   {
31     consumer.stop();
32   }
33
34
35   @GetMapping("seen")
36   public Map<Integer, Map<String, Long>> seen()
37   {
38     return consumer.getSeen();
39   }
40
41
42   @ExceptionHandler
43   @ResponseStatus(HttpStatus.BAD_REQUEST)
44   public ErrorResponse illegalStateException(IllegalStateException e)
45   {
46     return new ErrorResponse(e.getMessage(), HttpStatus.BAD_REQUEST.value());
47   }
48 }