Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed implementation of actor naming #523

Merged
merged 9 commits into from
Aug 14, 2024
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
21 changes: 10 additions & 11 deletions src/main/scala/edu/ie3/simona/actor/SimonaActorNaming.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,28 @@ 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 {

implicit class RichActorRefFactory(private val refFactory: ActorRefFactory)
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,8 @@ class GridAgentController(
maybeControllingEm,
),
listener.map(_.toClassic),
)
),
evcsInput.getId,
)
.toTyped

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ class SimonaStandaloneSetup(
simulationStart,
),
simulationStart,
)
),
"primaryServiceProxyAgent",
)

scheduler ! ScheduleActivation(primaryServiceProxy.toTyped, INIT_SIM_TICK)
Expand All @@ -178,7 +179,8 @@ class SimonaStandaloneSetup(
.toZonedDateTime(simonaConfig.simona.time.startDateTime),
TimeUtil.withDefaults
.toZonedDateTime(simonaConfig.simona.time.endDateTime),
)
),
"weatherAgent",
)
weatherService ! SimonaService.Create(
InitWeatherServiceStateData(
Expand Down