Skip to content

Commit cd365b4

Browse files
committed
Resolving dead lock
1 parent ade4b57 commit cd365b4

File tree

5 files changed

+48
-38
lines changed

5 files changed

+48
-38
lines changed

src/main/scala/edu/ie3/simbench/actor/Converter.scala

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ object Converter {
216216
)
217217
}
218218
} else {
219-
ctx.self ! LoadsConverted(Map.empty[LoadInput, UUID])
219+
ctx.self ! LoadsConverted(Map.empty[LoadInput, Option[UUID]])
220220
}
221221
if (simBenchModel.res.nonEmpty) {
222222
val resConverter =
@@ -238,7 +238,7 @@ object Converter {
238238
)
239239
}
240240
} else {
241-
ctx.self ! ResConverted(Map.empty[FixedFeedInInput, UUID])
241+
ctx.self ! ResConverted(Map.empty[FixedFeedInInput, Option[UUID]])
242242
}
243243
if (simBenchModel.powerPlants.nonEmpty) {
244244
val powerPlantConverter =
@@ -263,7 +263,9 @@ object Converter {
263263
)
264264
}
265265
} else {
266-
ctx.self ! PowerPlantsConverted(Map.empty[FixedFeedInInput, UUID])
266+
ctx.self ! PowerPlantsConverted(
267+
Map.empty[FixedFeedInInput, Option[UUID]]
268+
)
267269
}
268270

269271
converting(
@@ -596,8 +598,8 @@ object Converter {
596598
val timeSeriesMapping: Map[UUID, UUID] = awaitedResults.loads
597599
.map(
598600
modelToTimeSeries =>
599-
modelToTimeSeries.map {
600-
case (model, uuid) => model.getUuid -> uuid
601+
modelToTimeSeries.filter(_._2.nonEmpty).map {
602+
case (model, uuid) => model.getUuid -> uuid.get
601603
}
602604
)
603605
.getOrElse {
@@ -606,8 +608,8 @@ object Converter {
606608
} ++ awaitedResults.res
607609
.map(
608610
modelToTimeSeries =>
609-
modelToTimeSeries.map {
610-
case (model, uuid) => model.getUuid -> uuid
611+
modelToTimeSeries.filter(_._2.nonEmpty).map {
612+
case (model, uuid) => model.getUuid -> uuid.get
611613
}
612614
)
613615
.getOrElse {
@@ -618,8 +620,8 @@ object Converter {
618620
} ++ awaitedResults.powerPlants
619621
.map(
620622
modelToTimeSeries =>
621-
modelToTimeSeries.map {
622-
case (model, uuid) => model.getUuid -> uuid
623+
modelToTimeSeries.filter(_._2.nonEmpty).map {
624+
case (model, uuid) => model.getUuid -> uuid.get
623625
}
624626
)
625627
.getOrElse {
@@ -661,9 +663,9 @@ object Converter {
661663
transformers3w: Option[Vector[Transformer3WInput]],
662664
switches: Option[Vector[SwitchInput]],
663665
measurements: Option[Vector[MeasurementUnitInput]],
664-
loads: Option[Map[LoadInput, UUID]],
665-
res: Option[Map[FixedFeedInInput, UUID]],
666-
powerPlants: Option[Map[FixedFeedInInput, UUID]]
666+
loads: Option[Map[LoadInput, Option[UUID]]],
667+
res: Option[Map[FixedFeedInInput, Option[UUID]]],
668+
powerPlants: Option[Map[FixedFeedInInput, Option[UUID]]]
667669
) {
668670

669671
/**
@@ -775,14 +777,15 @@ object Converter {
775777
replyTo: ActorRef[PowerPlantConverter.ShuntConverterMessage]
776778
) extends ConverterMessage
777779

778-
final case class ResConverted(converted: Map[FixedFeedInInput, UUID])
780+
final case class ResConverted(converted: Map[FixedFeedInInput, Option[UUID]])
779781
extends ConverterMessage
780782

781-
final case class LoadsConverted(converted: Map[LoadInput, UUID])
783+
final case class LoadsConverted(converted: Map[LoadInput, Option[UUID]])
782784
extends ConverterMessage
783785

784-
final case class PowerPlantsConverted(converted: Map[FixedFeedInInput, UUID])
785-
extends ConverterMessage
786+
final case class PowerPlantsConverted(
787+
converted: Map[FixedFeedInInput, Option[UUID]]
788+
) extends ConverterMessage
786789

787790
object GridStructurePersisted extends ConverterMessage
788791
object TimeSeriesMappingPersisted extends ConverterMessage

src/main/scala/edu/ie3/simbench/actor/LoadConverter.scala

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import edu.ie3.datamodel.models.StandardLoadProfile.DefaultLoadProfiles
77
import edu.ie3.datamodel.models.input.system.LoadInput
88
import edu.ie3.datamodel.models.input.system.characteristic.CosPhiFixed
99
import edu.ie3.datamodel.models.input.{NodeInput, OperatorInput}
10-
import edu.ie3.simbench.actor.WorkerMessage.TimeSeriesPersisted
1110
import edu.ie3.simbench.convert.profiles.PowerProfileConverter
1211
import edu.ie3.simbench.convert.{NodeConverter, ShuntConverter}
1312
import edu.ie3.simbench.model.datamodel.profiles.{LoadProfile, LoadProfileType}
@@ -81,7 +80,7 @@ case object LoadConverter
8180

8281
def converting(
8382
activeConversions: Vector[(String, Node.NodeKey)],
84-
converted: Map[LoadInput, UUID],
83+
converted: Map[LoadInput, Option[UUID]],
8584
workerPool: ActorRef[WorkerMessage],
8685
converter: ActorRef[Converter.ConverterMessage]
8786
): Behaviors.Receive[ShuntConverterMessage] = Behaviors.receive {
@@ -190,7 +189,7 @@ case object LoadConverter
190189
id: String,
191190
node: Node.NodeKey,
192191
model: LoadInput,
193-
timeSeriesUuid: UUID
192+
timeSeriesUuid: Option[UUID]
194193
) extends super.Converted
195194

196195
object Worker {
@@ -220,7 +219,8 @@ case object LoadConverter
220219
)
221220

222221
/* Convert the model */
223-
val model = convertModel(convertRequest.model, convertRequest.node)
222+
val convertedModel =
223+
convertModel(convertRequest.model, convertRequest.node)
224224

225225
/* If needed, convert time series and await their finishing */
226226
convertRequest match {
@@ -233,9 +233,11 @@ case object LoadConverter
233233

234234
mutator ! Mutator.PersistTimeSeries(timeSeries, ctx.self)
235235
val updatedAwaitedTimeSeriesPersistence = awaitTimeSeriesPersistence +
236-
(timeSeries.getUuid -> (input.id, input.node.getKey, model, replyTo))
236+
(timeSeries.getUuid -> (input.id, input.node.getKey, convertedModel, replyTo))
237237
idle(mutator, updatedAwaitedTimeSeriesPersistence)
238-
case _: ConvertWithoutTimeSeries =>
238+
case ConvertWithoutTimeSeries(model, _, replyTo) =>
239+
replyTo ! LoadConverter
240+
.Converted(model.id, model.node.getKey, convertedModel, None)
239241
idle(mutator, awaitTimeSeriesPersistence)
240242
}
241243

@@ -246,7 +248,7 @@ case object LoadConverter
246248
val remainingPersistence =
247249
awaitTimeSeriesPersistence.filterNot(_._1 == uuid)
248250

249-
replyTo ! LoadConverter.Converted(id, nodeKey, model, uuid)
251+
replyTo ! LoadConverter.Converted(id, nodeKey, model, Some(uuid))
250252

251253
idle(mutator, remainingPersistence)
252254
case None =>

src/main/scala/edu/ie3/simbench/actor/PowerPlantConverter.scala

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ case object PowerPlantConverter
8787

8888
def converting(
8989
activeConversions: Vector[(String, Node.NodeKey)],
90-
converted: Map[FixedFeedInInput, UUID],
90+
converted: Map[FixedFeedInInput, Option[UUID]],
9191
workerPool: ActorRef[WorkerMessage],
9292
converter: ActorRef[Converter.ConverterMessage]
9393
): Behaviors.Receive[ShuntConverterMessage] = Behaviors.receive {
@@ -196,7 +196,7 @@ case object PowerPlantConverter
196196
id: String,
197197
node: Node.NodeKey,
198198
model: FixedFeedInInput,
199-
timeSeriesUuid: UUID
199+
timeSeriesUuid: Option[UUID]
200200
) extends super.Converted
201201

202202
object Worker {
@@ -226,7 +226,8 @@ case object PowerPlantConverter
226226
)
227227

228228
/* Convert the model */
229-
val model = convertModel(convertRequest.model, convertRequest.node)
229+
val convertedModel =
230+
convertModel(convertRequest.model, convertRequest.node)
230231

231232
/* If needed, convert time series and await their finishing */
232233
convertRequest match {
@@ -241,9 +242,11 @@ case object PowerPlantConverter
241242

242243
mutator ! Mutator.PersistTimeSeries(timeSeries, ctx.self)
243244
val updatedAwaitedTimeSeriesPersistence = awaitTimeSeriesPersistence +
244-
(timeSeries.getUuid -> (input.id, input.node.getKey, model, replyTo))
245+
(timeSeries.getUuid -> (input.id, input.node.getKey, convertedModel, replyTo))
245246
idle(mutator, updatedAwaitedTimeSeriesPersistence)
246-
case _: ConvertWithoutTimeSeries =>
247+
case ConvertWithoutTimeSeries(model, _, replyTo) =>
248+
replyTo ! PowerPlantConverter
249+
.Converted(model.id, model.node.getKey, convertedModel, None)
247250
idle(mutator, awaitTimeSeriesPersistence)
248251
}
249252

@@ -254,7 +257,8 @@ case object PowerPlantConverter
254257
val remainingPersistence =
255258
awaitTimeSeriesPersistence.filterNot(_._1 == uuid)
256259

257-
replyTo ! PowerPlantConverter.Converted(id, nodeKey, model, uuid)
260+
replyTo ! PowerPlantConverter
261+
.Converted(id, nodeKey, model, Some(uuid))
258262

259263
idle(mutator, remainingPersistence)
260264
case None =>

src/main/scala/edu/ie3/simbench/actor/ResConverter.scala

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,9 @@ import edu.ie3.util.quantities.PowerSystemUnits.{
1515
MEGAVOLTAMPERE,
1616
MEGAWATT
1717
}
18-
import tech.units.indriya.ComparableQuantity
1918
import tech.units.indriya.quantity.Quantities
2019

2120
import java.util.{Locale, UUID}
22-
import javax.measure.quantity.Power
2321

2422
case object ResConverter
2523
extends ShuntConverter
@@ -80,7 +78,7 @@ case object ResConverter
8078

8179
def converting(
8280
activeConversions: Vector[(String, Node.NodeKey)],
83-
converted: Map[FixedFeedInInput, UUID],
81+
converted: Map[FixedFeedInInput, Option[UUID]],
8482
workerPool: ActorRef[WorkerMessage],
8583
converter: ActorRef[Converter.ConverterMessage]
8684
): Behaviors.Receive[ShuntConverterMessage] = Behaviors.receive {
@@ -189,7 +187,7 @@ case object ResConverter
189187
id: String,
190188
node: Node.NodeKey,
191189
model: FixedFeedInInput,
192-
timeSeriesUuid: UUID
190+
timeSeriesUuid: Option[UUID]
193191
) extends super.Converted
194192

195193
object Worker {
@@ -219,7 +217,8 @@ case object ResConverter
219217
)
220218

221219
/* Convert the model */
222-
val model = convertModel(convertRequest.model, convertRequest.node)
220+
val convertedModel =
221+
convertModel(convertRequest.model, convertRequest.node)
223222

224223
/* If needed, convert time series and await their finishing */
225224
convertRequest match {
@@ -234,9 +233,11 @@ case object ResConverter
234233

235234
mutator ! Mutator.PersistTimeSeries(timeSeries, ctx.self)
236235
val updatedAwaitedTimeSeriesPersistence = awaitTimeSeriesPersistence +
237-
(timeSeries.getUuid -> (input.id, input.node.getKey, model, replyTo))
236+
(timeSeries.getUuid -> (input.id, input.node.getKey, convertedModel, replyTo))
238237
idle(mutator, updatedAwaitedTimeSeriesPersistence)
239-
case _: ConvertWithoutTimeSeries =>
238+
case ConvertWithoutTimeSeries(model, _, replyTo) =>
239+
replyTo ! ResConverter
240+
.Converted(model.id, model.node.getKey, convertedModel, None)
240241
idle(mutator, awaitTimeSeriesPersistence)
241242
}
242243

@@ -247,7 +248,7 @@ case object ResConverter
247248
val remainingPersistence =
248249
awaitTimeSeriesPersistence.filterNot(_._1 == uuid)
249250

250-
replyTo ! ResConverter.Converted(id, nodeKey, model, uuid)
251+
replyTo ! ResConverter.Converted(id, nodeKey, model, Some(uuid))
251252

252253
idle(mutator, remainingPersistence)
253254
case None =>

src/main/scala/edu/ie3/simbench/actor/ShuntConverterMessageSupport.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ trait ShuntConverterMessageSupport[I <: ShuntModel, P <: ProfileModel[_, _], R <
2727
val id: String
2828
val node: Node.NodeKey
2929
val model: R
30-
val timeSeriesUuid: UUID
30+
val timeSeriesUuid: Option[UUID]
3131
}
3232

3333
/**

0 commit comments

Comments
 (0)