diff --git a/CHANGELOG.md b/CHANGELOG.md index 72df5515ec..216d239639 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -156,6 +156,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Changed format of example grid `vn_simona` [#216](https://github.com/ie3-institute/simona/issues/216) - Renamed ChpData to ChpRelevantData [#494](https://github.com/ie3-institute/simona/issues/494) - Updated gradle to 8.2.1, cleaned up `build.gradle` and `Jenkinsfile` [#572](https://github.com/ie3-institute/simona/issues/572) +- Changed implementation of actor naming for unique name generation [#103](https://github.com/ie3-institute/simona/issues/103) ### Fixed - Location of `vn_simona` test grid (was partially in Berlin and Dortmund) [#72](https://github.com/ie3-institute/simona/issues/72) diff --git a/src/main/scala/edu/ie3/simona/actor/SimonaActorNaming.scala b/src/main/scala/edu/ie3/simona/actor/SimonaActorNaming.scala index 6aeeaf093c..fed8f600f3 100644 --- a/src/main/scala/edu/ie3/simona/actor/SimonaActorNaming.scala +++ b/src/main/scala/edu/ie3/simona/actor/SimonaActorNaming.scala @@ -10,7 +10,7 @@ import org.apache.pekko.actor.typed.ActorRef import org.apache.pekko.actor.typed.scaladsl.adapter.TypedActorRefOps import org.apache.pekko.actor.{ActorRefFactory, Props, ActorRef => ClassicRef} -import java.util.UUID +import scala.util.Random object SimonaActorNaming { @@ -18,21 +18,20 @@ object SimonaActorNaming { extends AnyVal { def simonaActorOf(props: Props, actorId: String): ClassicRef = - refFactory.actorOf(props, actorName(props, actorId)) - - def simonaActorOf(props: Props): ClassicRef = - refFactory.actorOf(props, actorName(props, simonaActorUuid)) + refFactory.actorOf(props, actorName(props, simonaActorId(actorId))) } - /** Constructs a uuid and cuts it down to 6 digits for convenience. Although - * this is dangerous as duplicates might be possible, it should be sufficient - * in our case as the uniqueness is only required in one actor system + /** Constructs an Id for convenience actor naming. Although this is dangerous + * as duplicates might be possible, it should be sufficient in our case as + * the uniqueness is only required in one actor system * * @return - * a shortened uuid string + * an Id string */ - private def simonaActorUuid: String = - UUID.randomUUID().toString.substring(0, 5) + private def simonaActorId(actorId: String): String = { + val randomNumber = Random.nextInt(1000).toString + s"$actorId-$randomNumber" + } /** Constructs an actor name based on the simona convention for actor names. * The provided combination of class and id has to be unique for the whole diff --git a/src/main/scala/edu/ie3/simona/agent/grid/GridAgentController.scala b/src/main/scala/edu/ie3/simona/agent/grid/GridAgentController.scala index 393e7417e7..5ebfefa55b 100644 --- a/src/main/scala/edu/ie3/simona/agent/grid/GridAgentController.scala +++ b/src/main/scala/edu/ie3/simona/agent/grid/GridAgentController.scala @@ -678,7 +678,8 @@ class GridAgentController( maybeControllingEm, ), listener.map(_.toClassic), - ) + ), + evcsInput.getId, ) .toTyped diff --git a/src/main/scala/edu/ie3/simona/sim/setup/SimonaStandaloneSetup.scala b/src/main/scala/edu/ie3/simona/sim/setup/SimonaStandaloneSetup.scala index 32711a4a3d..29f2bb7240 100644 --- a/src/main/scala/edu/ie3/simona/sim/setup/SimonaStandaloneSetup.scala +++ b/src/main/scala/edu/ie3/simona/sim/setup/SimonaStandaloneSetup.scala @@ -160,7 +160,8 @@ class SimonaStandaloneSetup( simulationStart, ), simulationStart, - ) + ), + "primaryServiceProxyAgent", ) scheduler ! ScheduleActivation(primaryServiceProxy.toTyped, INIT_SIM_TICK) @@ -178,7 +179,8 @@ class SimonaStandaloneSetup( .toZonedDateTime(simonaConfig.simona.time.startDateTime), TimeUtil.withDefaults .toZonedDateTime(simonaConfig.simona.time.endDateTime), - ) + ), + "weatherAgent", ) weatherService ! SimonaService.Create( InitWeatherServiceStateData(