1 /*
2  *  Make.org Core API
3  *  Copyright (C) 2020 Make.org
4  *
5  * This program is free software: you can redistribute it and/or modify
6  *  it under the terms of the GNU Affero General Public License as
7  *  published by the Free Software Foundation, either version 3 of the
8  *  License, or (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU Affero General Public License for more details.
14  *
15  *  You should have received a copy of the GNU Affero General Public License
16  *  along with this program.  If not, see <https://www.gnu.org/licenses/>.
17  *
18  */
19 
20 package org.make.api.technical.job
21 
22 import akka.actor.typed.receptionist.ServiceKey
23 import akka.actor.typed.{ActorRef, ActorSystem}
24 import akka.cluster.sharding.typed.scaladsl.{ClusterSharding, Entity, EntityTypeKey}
25 import org.make.api.technical.ShardingNoEnvelopeMessageExtractor
26 
27 import scala.concurrent.duration.Duration
28 
29 object JobCoordinator {
30   private val name = "job-coordinator"
31 
32   private val TypeKey: EntityTypeKey[JobActor.Protocol.Command] =
33     EntityTypeKey[JobActor.Protocol.Command]("job")
34 
35   val Key: ServiceKey[JobActor.Protocol.Command] = ServiceKey(name)
36 
37   def apply(system: ActorSystem[_], heartRate: Duration): ActorRef[JobActor.Protocol.Command] = {
38     ClusterSharding(system).init(
39       Entity(TypeKey)(_ => JobActor(heartRate))
40         .withMessageExtractor(ShardingNoEnvelopeMessageExtractor[JobActor.Protocol.Command](numberOfShards = 5))
41     )
42   }
43 }
Line Stmt Id Pos Tree Symbol Tests Code
30 14735 1116 - 1133 Literal <nosymbol> org.make.api.technical.job.jobcoordinatorservicetest "job-coordinator"
33 10987 1246 - 1251 Literal <nosymbol> org.make.api.technical.job.jobcoordinatorservicetest "job"
33 9398 1205 - 1252 ApplyToImplicitArgs akka.cluster.sharding.typed.scaladsl.EntityTypeKey.apply org.make.api.technical.job.jobcoordinatorservicetest akka.cluster.sharding.typed.scaladsl.EntityTypeKey.apply[org.make.api.technical.job.JobActor.Protocol.Command]("job")((ClassTag.apply[org.make.api.technical.job.JobActor.Protocol.Command](classOf[org.make.api.technical.job.JobActor$$Protocol$Command]): scala.reflect.ClassTag[org.make.api.technical.job.JobActor.Protocol.Command]))
35 15274 1316 - 1320 Select org.make.api.technical.job.JobCoordinator.name org.make.api.technical.job.jobcoordinatorservicetest JobCoordinator.this.name
35 11765 1305 - 1321 ApplyToImplicitArgs akka.actor.typed.receptionist.ServiceKey.apply org.make.api.technical.job.jobcoordinatorservicetest akka.actor.typed.receptionist.ServiceKey.apply[org.make.api.technical.job.JobActor.Protocol.Command](JobCoordinator.this.name)((ClassTag.apply[org.make.api.technical.job.JobActor.Protocol.Command](classOf[org.make.api.technical.job.JobActor$$Protocol$Command]): scala.reflect.ClassTag[org.make.api.technical.job.JobActor.Protocol.Command]))
38 14753 1425 - 1621 Apply akka.cluster.sharding.typed.scaladsl.ClusterSharding.init org.make.api.technical.job.jobcoordinatorservicetest akka.cluster.sharding.typed.scaladsl.ClusterSharding.apply(system).init[org.make.api.technical.job.JobActor.Protocol.Command, org.make.api.technical.job.JobActor.Protocol.Command](akka.cluster.sharding.typed.scaladsl.Entity.apply[org.make.api.technical.job.JobActor.Protocol.Command](JobCoordinator.this.TypeKey)(((x$1: akka.cluster.sharding.typed.scaladsl.EntityContext[org.make.api.technical.job.JobActor.Protocol.Command]) => JobActor.apply(heartRate))).withMessageExtractor[org.make.api.technical.job.JobActor.Protocol.Command](org.make.api.technical.ShardingNoEnvelopeMessageExtractor.apply[org.make.api.technical.job.JobActor.Protocol.Command](5)))
39 14007 1482 - 1501 Apply org.make.api.technical.job.JobActor.apply JobActor.apply(heartRate)
39 17697 1468 - 1475 Select org.make.api.technical.job.JobCoordinator.TypeKey org.make.api.technical.job.jobcoordinatorservicetest JobCoordinator.this.TypeKey
40 12404 1533 - 1614 Apply org.make.api.technical.ShardingNoEnvelopeMessageExtractor.apply org.make.api.technical.job.jobcoordinatorservicetest org.make.api.technical.ShardingNoEnvelopeMessageExtractor.apply[org.make.api.technical.job.JobActor.Protocol.Command](5)
40 18231 1461 - 1615 Apply akka.cluster.sharding.typed.scaladsl.Entity.withMessageExtractor org.make.api.technical.job.jobcoordinatorservicetest akka.cluster.sharding.typed.scaladsl.Entity.apply[org.make.api.technical.job.JobActor.Protocol.Command](JobCoordinator.this.TypeKey)(((x$1: akka.cluster.sharding.typed.scaladsl.EntityContext[org.make.api.technical.job.JobActor.Protocol.Command]) => JobActor.apply(heartRate))).withMessageExtractor[org.make.api.technical.job.JobActor.Protocol.Command](org.make.api.technical.ShardingNoEnvelopeMessageExtractor.apply[org.make.api.technical.job.JobActor.Protocol.Command](5))