forked from lagom/lagom
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support for compile time DI (MacWire), #1
* for scaladsl-persistence and scaladsl-persistence-jdbc * factory for PersistentEntity registration * factory for ReadSide registration * components trait for compile time DI * separate traits for write and read side * split up cluster module * remove guice
- Loading branch information
Showing
40 changed files
with
403 additions
and
339 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
1 change: 0 additions & 1 deletion
1
cluster/src/main/resources/reference.conf → ...er/core/src/main/resources/reference.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
play.modules.enabled += com.lightbend.lagom.internal.cluster.JoinClusterModule | ||
|
||
lagom.cluster { | ||
|
||
|
62 changes: 62 additions & 0 deletions
62
cluster/core/src/main/scala/com/lightbend/lagom/internal/cluster/JoinClusterImpl.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright (C) 2016 Lightbend Inc. <http://www.lightbend.com> | ||
*/ | ||
package com.lightbend.lagom.internal.cluster | ||
|
||
import java.util.concurrent.TimeUnit | ||
|
||
import scala.concurrent.Await | ||
import scala.concurrent.duration._ | ||
import scala.util.Try | ||
|
||
import akka.actor.ActorSystem | ||
import akka.cluster.Cluster | ||
|
||
private[lagom] object JoinClusterImpl { | ||
|
||
def join(system: ActorSystem): Unit = { | ||
|
||
val config = system.settings.config | ||
def joinSelf = config.getBoolean("lagom.cluster.join-self") | ||
def terminateSystemAfter = config.getDuration( | ||
"lagom.cluster.terminate-system-after-member-removed", TimeUnit.MILLISECONDS | ||
).millis | ||
def exitJvm = config.getBoolean("lagom.cluster.exit-jvm-when-system-terminated") | ||
|
||
// join self if seed-nodes are not configured in dev-mode, | ||
// otherwise it will join the seed-nodes automatically | ||
val cluster = Cluster(system) | ||
if (cluster.settings.SeedNodes.isEmpty && joinSelf) | ||
cluster.join(cluster.selfAddress) | ||
|
||
if (exitJvm) { | ||
// exit JVM when ActorSystem has been terminated | ||
system.registerOnTermination(System.exit(0)) | ||
} | ||
|
||
Cluster(system).registerOnMemberRemoved { | ||
// The delay is to give ClusterSingleton actors some time to stop gracefully. | ||
system.scheduler.scheduleOnce(terminateSystemAfter) { | ||
system.terminate() | ||
|
||
if (exitJvm) { | ||
// In case ActorSystem shutdown takes longer than 10 seconds, | ||
// exit the JVM forcefully anyway. | ||
// We must spawn a separate thread to not block current thread, | ||
// since that would have blocked the shutdown of the ActorSystem. | ||
val t = new Thread(new Runnable { | ||
override def run(): Unit = { | ||
if (Try(Await.ready(system.whenTerminated, 10.seconds)).isFailure) | ||
System.exit(-1) | ||
} | ||
}) | ||
t.setDaemon(true) | ||
t.start() | ||
} | ||
}(system.dispatcher) | ||
|
||
} | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
play.modules.enabled += com.lightbend.lagom.internal.javadsl.cluster.JoinClusterModule |
22 changes: 22 additions & 0 deletions
22
...ter/javadsl/src/main/scala/com/lightbend/lagom/internal/javadsl/cluster/JoinCluster.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright (C) 2016 Lightbend Inc. <http://www.lightbend.com> | ||
*/ | ||
package com.lightbend.lagom.internal.javadsl.cluster | ||
|
||
import scala.concurrent.duration._ | ||
|
||
import akka.actor.ActorSystem | ||
import com.google.inject.AbstractModule | ||
import com.google.inject.Inject | ||
import com.lightbend.lagom.internal.cluster.JoinClusterImpl | ||
|
||
class JoinClusterModule extends AbstractModule { | ||
override def configure(): Unit = { | ||
binder.bind(classOf[JoinCluster]).asEagerSingleton() | ||
} | ||
} | ||
|
||
private[lagom] class JoinCluster @Inject() (system: ActorSystem) { | ||
JoinClusterImpl.join(system) | ||
} | ||
|
File renamed without changes.
23 changes: 23 additions & 0 deletions
23
cluster/scaladsl/src/main/scala/com/lightbend/lagom/scaladsl/cluster/ClusterComponents.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright (C) 2016 Lightbend Inc. <http://www.lightbend.com> | ||
*/ | ||
package com.lightbend.lagom.scaladsl.cluster | ||
|
||
import scala.concurrent.ExecutionContext | ||
|
||
import akka.actor.ActorSystem | ||
import akka.cluster.Cluster | ||
import com.lightbend.lagom.internal.cluster.JoinClusterImpl | ||
|
||
/** | ||
* Cluster components (for compile-time injection). | ||
*/ | ||
trait ClusterComponents { | ||
def actorSystem: ActorSystem | ||
|
||
// eager initialization | ||
val cluster: Cluster = { | ||
JoinClusterImpl.join(actorSystem) | ||
Cluster(actorSystem) | ||
} | ||
} |
65 changes: 0 additions & 65 deletions
65
cluster/src/main/scala/com/lightbend/lagom/internal/cluster/JoinCluster.scala
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
.../src/main/scala/com/lightbend/lagom/internal/javadsl/persistence/jdbc/SlickProvider.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Copyright (C) 2016 Lightbend Inc. <http://www.lightbend.com> | ||
*/ | ||
package com.lightbend.lagom.internal.javadsl.persistence.jdbc | ||
|
||
import scala.concurrent.ExecutionContext | ||
import scala.concurrent.duration._ | ||
|
||
import akka.actor.ActorSystem | ||
|
||
import javax.inject.{ Inject, Singleton } | ||
import play.api.db.DBApi | ||
import slick.ast._ | ||
|
||
@Singleton | ||
class SlickProvider @Inject() ( | ||
system: ActorSystem, | ||
dbApi: DBApi /* Ensures database is initialised before we start anything that needs it */ )(implicit ec: ExecutionContext) | ||
extends com.lightbend.lagom.internal.persistence.jdbc.SlickProvider(system, dbApi)(ec) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.