Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Native-image support #529

Merged
merged 6 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion native-image-tests/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ fork := true
enablePlugins(NativeImagePlugin)
nativeImageJvm := "graalvm-community"
nativeImageVersion := "21.0.2"
nativeImageOptions := Seq("--no-fallback", "--verbose", "-Dakka.native-image.debug=true")
nativeImageOptions := Seq(
"--no-fallback",
"--verbose",
"--initialize-at-build-time=ch.qos.logback",
"-Dakka.native-image.debug=true")

libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-actor-typed" % akkaVersion,
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,18 @@ import akka.persistence.typed.PersistenceId
import akka.persistence.typed.state.scaladsl.DurableStateBehavior
import akka.persistence.typed.state.scaladsl.Effect
import akka.serialization.jackson.JsonSerializable
import com.fasterxml.jackson.annotation.JsonCreator

import scala.concurrent.duration.DurationInt

object DurableStateCounter {
sealed trait Command extends JsonSerializable
final case class Increase(amount: Int, replyTo: ActorRef[Increased]) extends Command

// FIXME why doesn't @JsonCreator work as usual? is it something missing from the jackson feature?
final case class GetState @JsonCreator() (replyTo: ActorRef[State]) extends Command
final case class GetState(replyTo: ActorRef[State]) extends Command
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏼 great that it works out-of-the-box now


final case class Increased @JsonCreator() (newValue: Int) extends JsonSerializable
final case class Increased(newValue: Int) extends JsonSerializable

final case class State @JsonCreator() (value: Int) extends JsonSerializable
final case class State(value: Int) extends JsonSerializable
def apply(id: String): Behavior[Command] =
DurableStateBehavior[Command, State](
PersistenceId("DSCounter", id),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,21 @@ import akka.persistence.typed.PersistenceId
import akka.persistence.typed.scaladsl.Effect
import akka.persistence.typed.scaladsl.EventSourcedBehavior
import akka.serialization.jackson.JsonSerializable
import com.fasterxml.jackson.annotation.JsonCreator

import scala.concurrent.duration.DurationInt

object EventSourcedCounter {
sealed trait Command extends JsonSerializable

final case class Increase(amount: Int, replyTo: ActorRef[StatusReply[Increased]]) extends Command
final case class GetValue @JsonCreator() (replyTo: ActorRef[StatusReply[GetValueResponse]]) extends Command
final case class GetValue(replyTo: ActorRef[StatusReply[GetValueResponse]]) extends Command
final case class GetValueResponse(value: Int)

sealed trait Event extends JsonSerializable

final case class Increased @JsonCreator() (amount: Int) extends Event
final case class Increased(amount: Int) extends Event

final case class State @JsonCreator() (value: Int) extends JsonSerializable
final case class State(value: Int) extends JsonSerializable

def apply(id: String): Behavior[Command] = EventSourcedBehavior[Command, Event, State](
PersistenceId("EventSourcedHelloWorld", id),
Expand Down
Loading