| 5 | [[Image(старт-рута.png)]] |
| 6 | [[Image(старт-рута-2.png)]] |
| 7 | |
| 8 | |
| 9 | ==== Симулација на real-time сигнал од автобус |
| 10 | |
| 11 | При старт на инстанца се испалува евент: |
| 12 | |
| 13 | {{{#!div |
| 14 | |
| 15 | {{{#!java |
| 16 | |
| 17 | return instancaNaLinijaRepository |
| 18 | .save(instanca) |
| 19 | .let { |
| 20 | publisher.publishEvent(StartRouteEvent(it)) |
| 21 | dtoMapper.toRouteInstanceResponse(it) |
| 22 | } |
| 23 | }}} |
| 24 | }}} |
| 25 | |
| 26 | Евентот се слуша овде: |
| 27 | |
| 28 | {{{#!div |
| 29 | {{{#!java |
| 30 | @Async |
| 31 | @EventListener |
| 32 | fun startRouteEvent(event: StartRouteEvent) { |
| 33 | println(event) |
| 34 | println(event) |
| 35 | val instance = event.source as InstancaNaLinija |
| 36 | val line = instance.linija |
| 37 | val direction = instance.pravec |
| 38 | val stations = stationService.findStationsByLineIdAndDirectionId(line.id, direction.id) |
| 39 | |
| 40 | simulator.simulate(instance, stations) |
| 41 | } |
| 42 | |
| 43 | @Async |
| 44 | @EventListener |
| 45 | fun routeInstanceOnStation(event: RouteInstanceOnStationEvent) { |
| 46 | println("------------------------------------------------") |
| 47 | println(event) |
| 48 | val source = event.source as RouteInstanceOnStation |
| 49 | routeInstanceOnStationService.create(source.instance.id, source.station.id, source.timestamp) |
| 50 | // todo: publish event to the websocket so that the user gets notified |
| 51 | webSocketService.sendMessage("routes", "Updated routes") |
| 52 | } |
| 53 | |
| 54 | @EventListener |
| 55 | fun stopRouteEvent(event: StopRouteInstanceEvent) { |
| 56 | val instance = event.source as InstancaNaLinija |
| 57 | routeInstanceService.stop(instance.id) |
| 58 | } |
| 59 | }}} |
| 60 | }}} |
| 61 | |
| 62 | Се стартува симулатор кој симулира пингови од GPS на автобус. |