Skip to content

Commit

Permalink
clean up micronaut framework integration
Browse files Browse the repository at this point in the history
Signed-off-by: Gabriel Harris-Rouquette <[email protected]>
  • Loading branch information
gabizou committed Sep 9, 2023
1 parent 8f5deb9 commit 1de9317
Show file tree
Hide file tree
Showing 327 changed files with 1,355 additions and 22,577 deletions.
2 changes: 1 addition & 1 deletion .java-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
graalvm64-17.0.4
20.0.1
1 change: 1 addition & 0 deletions .jvmopts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
-Xss6M
-XX:ReservedCodeCacheSize=256M
-Dfile.encoding=UTF-8
--enable-preview
--add-opens=java.base/java.lang=ALL-UNNAMED
32 changes: 10 additions & 22 deletions akka/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,16 @@
version = "0.1"
group = "org.spongepowered.downloads"


val akkaVersion: String by project
val scalaVersion: String by project
val akkaManagementVersion: String by project
val akkaProjection: String by project
plugins {
id("com.github.johnrengelman.shadow")
id("io.micronaut.library")
}

dependencies {
implementation("com.ongres.scram:client:2.1")
implementation("jakarta.annotation:jakarta.annotation-api")
implementation(platform("com.typesafe.akka:akka-bom_${scalaVersion}:${akkaVersion}"))
implementation("com.typesafe.akka:akka-actor-typed_${scalaVersion}")
implementation("com.typesafe.akka:akka-cluster-sharding-typed_${scalaVersion}")
implementation("com.typesafe.akka:akka-cluster-typed_${scalaVersion}")
implementation("com.typesafe.akka:akka-discovery_${scalaVersion}")
implementation("com.typesafe.akka:akka-discovery_${scalaVersion}")
implementation("com.lightbend.akka.management:akka-management_${scalaVersion}:${akkaManagementVersion}")
implementation("com.lightbend.akka.management:akka-management-cluster-bootstrap_${scalaVersion}:${akkaManagementVersion}")

runtimeOnly("ch.qos.logback:logback-classic")
compileOnly("org.graalvm.nativeimage:svm")

implementation("io.micronaut:micronaut-validation")
annotationProcessor("io.micronaut.serde:micronaut-serde-processor")
implementation("io.micronaut.serde:micronaut-serde-jackson")
api("io.micronaut:micronaut-inject")
api(platform(libs.akkaBom))
api(libs.bundles.actors)
implementation(libs.bundles.akkaManagement)
}


3 changes: 0 additions & 3 deletions akka/settings.gradle

This file was deleted.

5 changes: 0 additions & 5 deletions akka/src/main/java/module-info.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.spongepowered.downloads.akka;

import akka.actor.typed.ActorSystem;
import akka.actor.typed.Behavior;
import akka.actor.typed.Scheduler;
import akka.actor.typed.SpawnProtocol;
import akka.actor.typed.javadsl.Adapter;
Expand All @@ -12,35 +13,32 @@
import com.typesafe.config.ConfigFactory;
import io.micronaut.context.annotation.Bean;
import io.micronaut.context.annotation.Factory;
import io.micronaut.core.annotation.NonNull;
import jakarta.inject.Singleton;

@Factory
public class AkkaExtension {

@Bean
public Scheduler systemScheduler() {
return system().scheduler();
public Scheduler systemScheduler(@NonNull ActorSystem<?> system) {
return system.scheduler();
}

@Bean
public Config akkaConfig() {
return ConfigFactory.load();
return ConfigFactory.defaultApplication();
}

@Singleton
@Bean(preDestroy = "terminate")
public ActorSystem<SpawnProtocol.Command> system() {
Config config = akkaConfig();
return ActorSystem.create(
Behaviors.setup(ctx -> {
akka.actor.ActorSystem unTypedSystem = Adapter.toClassic(ctx.getSystem());
AkkaManagement.get(unTypedSystem).start();
ClusterBootstrap.get(unTypedSystem).start();
return SpawnProtocol.create();
}), config.getString("some.cluster.name"));
public ActorSystem<?> system(@NonNull Behavior<?> behavior, @NonNull Config config) {
return ActorSystem.create(behavior, "soad-master");
}

@Bean
public ClusterSharding clusterSharding() {
return ClusterSharding.get(system());
@Singleton
public ClusterSharding clusterSharding(@NonNull ActorSystem<?> system) {
return ClusterSharding.get(system);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.spongepowered.downloads.akka;

/**
* Marker interface for Akka serialization via Jackson
*/
public interface AkkaSerializable {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.spongepowered.downloads.akka;

import akka.actor.typed.ActorSystem;
import akka.actor.typed.Behavior;
import akka.actor.typed.SpawnProtocol;
import akka.actor.typed.javadsl.Behaviors;
import akka.management.cluster.bootstrap.ClusterBootstrap;
import akka.management.javadsl.AkkaManagement;
import io.micronaut.context.annotation.Bean;
import io.micronaut.context.annotation.Factory;
import io.micronaut.context.annotation.Requires;

@Factory
public class ProductionAkkaSystem {

@Bean
public Behavior<SpawnProtocol.Command> productionGuardian() {
return Behaviors.<SpawnProtocol.Command>setup(ctx -> {
final var system = ctx.getSystem();
ClusterBootstrap.get(system).start();
AkkaManagement.get(system).start();
return SpawnProtocol.create();
});
}

}
23 changes: 23 additions & 0 deletions akka/src/main/resources/refrerence.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

akka {
actor {
provider = "cluster"
serialization-bindings {
"org.spongepowered.downloads.akka.AkkaSerializable" = jackson-json
}
}
remote.artery {
canonical {
hostname = "127.0.0.1"
port = 2551
}
}

cluster {
seed-nodes = [
"akka://[email protected]:2551",
"akka://[email protected]:2552"]

downing-provider-class = "akka.cluster.sbr.SplitBrainResolverProvider"
}
}
14 changes: 14 additions & 0 deletions akka/testkit/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@



plugins {
id("com.github.johnrengelman.shadow")
id("io.micronaut.library")
}
dependencies {
annotationProcessor("io.micronaut.serde:micronaut-serde-processor")
implementation("io.micronaut.serde:micronaut-serde-jackson")
api("io.micronaut:micronaut-inject")
api(project(":akka"))
api(libs.akka.testkit)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.spongepowered.downloads.test.akka;

import akka.actor.testkit.typed.javadsl.ActorTestKit;
import akka.actor.testkit.typed.javadsl.BehaviorTestKit;
import akka.actor.typed.ActorSystem;
import akka.actor.typed.Behavior;
import akka.actor.typed.SpawnProtocol;
import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
import io.micronaut.context.annotation.Bean;
import io.micronaut.context.annotation.Factory;
import io.micronaut.context.annotation.Replaces;
import io.micronaut.core.annotation.NonNull;
import jakarta.inject.Singleton;

@Factory
public class AkkaTestExtension {

@Replaces
@Bean
public Behavior<SpawnProtocol.Command> testBehavior() {
return SpawnProtocol.create();
}

@Replaces
@Bean
public Config testConfig() {
return ConfigFactory.defaultApplication()
.withFallback(BehaviorTestKit.applicationTestConfig())
.resolve();
}

@Bean(preDestroy = "shutdownTestKit")
public ActorTestKit testKit() {
return ActorTestKit.create();
}

@Replaces(bean = ActorSystem.class)
@Singleton
public ActorSystem<?> system(@NonNull ActorTestKit kit) {
return kit.system();
}

}
3 changes: 3 additions & 0 deletions akka/testkit/src/main/resources/reference.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
systemofadownload {
clustering = false
}

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 1de9317

Please sign in to comment.