def running()

in pekko-sample-sharding-scala/killrweather-fog/src/main/scala/sample/killrweather/fog/WeatherStation.scala [56:85]


  def running(httpPort: Int): Behavior[WeatherStation.Command] = {
    context.log.infoN(s"Started WeatherStation {} of total {} with weather port {}",
      wsid, settings.weatherStations, httpPort)

    Behaviors.setup[WeatherStation.Command] { context =>
      context.log.debugN(s"Started {} data sampling.", wsid)

      Behaviors.withTimers { timers =>
        timers.startSingleTimer(Sample, Sample, settings.sampleInterval)

        Behaviors.receiveMessage {
          case Sample =>
            val value = 5 + 30 * random.nextDouble
            val eventTime = System.currentTimeMillis
            context.log.debug("Recording temperature measurement {}", value)
            recordTemperature(eventTime, value)
            Behaviors.same

          case ProcessSuccess(msg) =>
            context.log.debugN("Successfully registered data: {}", msg)
            // trigger next sample only after we got a successful response
            timers.startSingleTimer(Sample, Sample, settings.sampleInterval)
            Behaviors.same

          case ProcessFailure(e) =>
            throw new RuntimeException("Failed to register data", e)
        }
      }
    }
  }