@@ -47,8 +47,6 @@ class Worker {
4747
4848 def apply (id : Int , sims : Seq [Actor ], totalWorkers : Int ): Behavior [WorkerEvent ] = Behaviors .setup { ctx =>
4949 // ctx.log.debug("Register agent with receptionist")
50- ctx.system.receptionist ! Receptionist .Register (WorkerUpdateAgentMapServiceKey , ctx.self)
51-
5250 // val containers: ListBuffer[Actor] = ListBuffer[Actor]()
5351 local_sims = new ConcurrentHashMap (mapAsJavaMap(sims.map(x => (x.id, x)).toMap))
5452 totalAgents = sims.size
@@ -67,18 +65,26 @@ class Worker {
6765 // } else {
6866 local_compute_threads = new ConcurrentHashMap (mapAsJavaMap(sims.map(a => (a.id, ctx.spawn((new LocalAgent ).apply(a), f " simAgent ${a.id}" ))).toMap))
6967 // }
70-
71- val workerSub = ctx.messageAdapter[Receptionist .Listing ] {
72- case WorkerUpdateAgentMapServiceKey .Listing (workers) =>
73- if (workers.size == totalWorkers){
74- workers.filter(i => i!= ctx.self).foreach(w => {
75- w ! ReceiveAgentMap (workerId, local_sims.keys().toSeq.asInstanceOf [Iterable [java.lang.Long ]], ctx.self)
76- })
77- }
78- Prepare ()
79- }
80-
81- ctx.system.receptionist ! Receptionist .Subscribe (WorkerUpdateAgentMapServiceKey , workerSub)
68+
69+ if (totalWorkers > 1 ){
70+ ctx.system.receptionist ! Receptionist .Register (WorkerUpdateAgentMapServiceKey , ctx.self)
71+
72+ val workerSub = ctx.messageAdapter[Receptionist .Listing ] {
73+ case WorkerUpdateAgentMapServiceKey .Listing (workers) =>
74+ if (workers.size == totalWorkers){
75+ workers.filter(i => i!= ctx.self).foreach(w => {
76+ w ! ReceiveAgentMap (workerId, local_sims.keys().toSeq.asInstanceOf [Iterable [java.lang.Long ]], ctx.self)
77+ })
78+ }
79+ Prepare ()
80+ }
81+
82+ ctx.system.receptionist ! Receptionist .Subscribe (WorkerUpdateAgentMapServiceKey , workerSub)
83+ } else {
84+ ctx.system.receptionist ! Receptionist .Register (WorkerStartServiceKey , ctx.self)
85+ ctx.system.receptionist ! Receptionist .Register (WorkerStopServiceKey , ctx.self)
86+ }
87+
8288 // ctx.system.receptionist ! Receptionist.Subscribe(TimeseriesController.tsControllerServiceKey, workerSub)
8389 worker()
8490 }
0 commit comments