Fixes für Setup/README.sh aus 'deserialization' in 'stored-offsets' gemerged
[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.*;
6
7 import java.util.Map;
8 import java.util.concurrent.ExecutionException;
9
10
11 @RestController
12 @RequiredArgsConstructor
13 public class DriverController
14 {
15   private final EndlessConsumer consumer;
16   private final KeyCountingRecordHandler keyCountingRecordHandler;
17
18
19   @PostMapping("start")
20   public void start()
21   {
22     consumer.start();
23   }
24
25   @PostMapping("stop")
26   public void stop() throws ExecutionException, InterruptedException
27   {
28     consumer.stop();
29   }
30
31
32   @GetMapping("seen")
33   public Map<Integer, Map<String, Long>> seen()
34   {
35     return keyCountingRecordHandler.getSeen();
36   }
37
38
39   @ExceptionHandler
40   @ResponseStatus(HttpStatus.BAD_REQUEST)
41   public ErrorResponse illegalStateException(IllegalStateException e)
42   {
43     return new ErrorResponse(e.getMessage(), HttpStatus.BAD_REQUEST.value());
44   }
45 }