Skip to content

Commit

Permalink
[PoC] Introduce support for Pekko
Browse files Browse the repository at this point in the history
  • Loading branch information
PawelLipski committed Aug 21, 2023
1 parent e985c2b commit 1803c7b
Show file tree
Hide file tree
Showing 192 changed files with 838 additions and 837 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/standard-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ jobs:
run: sbt scalafmtCheckAll scalafmtSbtCheck "scalafixAll --check"
working-directory: examples/event-migration

- name: Check code style - examples/akka-cluster-app
- name: Check code style - examples/pekko-cluster-app
run: sbt scalafmtCheckAll scalafmtSbtCheck "scalafixAll --check"
working-directory: examples/akka-cluster-app
working-directory: examples/pekko-cluster-app

- name: Check code style - examples/akka-persistence-app
- name: Check code style - examples/pekko-persistence-app
run: sbt scalafmtCheckAll scalafmtSbtCheck "scalafixAll --check"
working-directory: examples/akka-persistence-app
working-directory: examples/pekko-persistence-app

test-212:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -126,13 +126,13 @@ jobs:
run: sbt test
working-directory: examples/event-migration

- name: Compile akka-cluster-app
- name: Compile pekko-cluster-app
run: sbt compile
working-directory: examples/akka-cluster-app
working-directory: examples/pekko-cluster-app

- name: Test akka-persistence-app
- name: Test pekko-persistence-app
run: sbt test
working-directory: examples/akka-persistence-app
working-directory: examples/pekko-persistence-app

publish-maven-artifacts:
needs: [code-style-check, test-212, test-213-1, test-213-2, test-sbt-plugin, run-examples]
Expand Down
2 changes: 1 addition & 1 deletion .scalafix.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ OrganizeImports.groups = [
"java.",
"scala.",
"*",
"org.virtuslab.ash"
"org.virtuslab.psh"
]
16 changes: 8 additions & 8 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ and using it in another project. Make sure that `mavenLocal` is added to the res
sbt publishM2
```

You can find two example applications that use Akka Serialization Helper:
- [akka-cluster-app](examples/akka-cluster-app)
- [akka-persistence-app](examples/akka-persistence-app)
You can find two example applications that use Pekko Serialization Helper:
- [pekko-cluster-app](examples/pekko-cluster-app)
- [pekko-persistence-app](examples/pekko-persistence-app)
These apps can be used for basic runtime testing as well. First, go to the app's directory:
```shell
cd examples/akka-cluster-app
cd examples/pekko-cluster-app
```
or
```shell
cd examples/akka-persistence-app
cd examples/pekko-persistence-app
```
And follow instructions from their README files.

Expand Down Expand Up @@ -68,7 +68,7 @@ Otherwise, incremental compilation might determine there is nothing to compile a

### Profiling

To profile akka-serialization-helper compiler plugin used in another project - follow instructions from https://www.lightbend.com/blog/profiling-jvm-applications
To profile pekko-serialization-helper compiler plugin used in another project - follow instructions from https://www.lightbend.com/blog/profiling-jvm-applications
You might as well use any other profiler, but using https://github.com/jvm-profiling-tools/async-profiler with flamegraphs should be really effective and easy to achieve (+ no unexpected bugs / issues / errors).

### Code quality
Expand All @@ -88,7 +88,7 @@ Releasing is done automatically by `sbt-ci-release` sbt plugin (read more on the

### Snapshots

The new `SNAPSHOT` version is automatically published by GitHub Actions to [Sonatype OSS Snapshot repo](https://oss.sonatype.org/content/repositories/snapshots/org/virtuslab/ash/)
The new `SNAPSHOT` version is automatically published by GitHub Actions to [Sonatype OSS Snapshot repo](https://oss.sonatype.org/content/repositories/snapshots/org/virtuslab/psh/)
every time a new commit is pushed to `main`.

To depend on the newest version with sbt, add the following setting:
Expand All @@ -99,7 +99,7 @@ to both `build.sbt` **and** `project/build.sbt` (so that the sbt plugin added in

### Maven Central

Releases to [Maven Central](https://repo1.maven.org/maven2/org/virtuslab/ash/) are triggered by pushing a lightweight git tag with a version number.
Releases to [Maven Central](https://repo1.maven.org/maven2/org/virtuslab/psh/) are triggered by pushing a lightweight git tag with a version number.

To publish version x.y.z, type in the console (on main branch):
```shell
Expand Down
146 changes: 70 additions & 76 deletions README.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.virtuslab.ash.annotation
package org.virtuslab.psh.annotation

/**
* This annotation is used as a marker for Codec Registration Checker and Serializability Checker. Annotate Akka
* This annotation is used as a marker for Codec Registration Checker and Serializability Checker. Annotate Pekko
* serialization marker-trait, and the rest is done by compiler plugins.
*
* {{{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.virtuslab.ash.annotation
package org.virtuslab.psh.annotation

import scala.annotation.nowarn

Expand All @@ -16,7 +16,7 @@ import scala.annotation.nowarn
* For example, if we want to serialize `trait Command`, then type `Registration[Command]` is relevant, while
* `Option[Command]` is not.
*
* If you are using `circe-akka-serializer`, set `typeRegexPattern` to `Register.REGISTRATION_REGEX`
* If you are using `circe-pekko-serializer`, set `typeRegexPattern` to `Register.REGISTRATION_REGEX`
*
* @param clazz
* class literal of serializability marker trait, for example `classOf[MySerializable]`
Expand Down
42 changes: 21 additions & 21 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ lazy val testAgainstScalaVersions =
"2.13.10")

ThisBuild / scalaVersion := targetScalaVersions.head
ThisBuild / organization := "org.virtuslab.ash"
ThisBuild / organization := "org.virtuslab.psh"
ThisBuild / organizationName := "VirtusLab"
ThisBuild / versionScheme := Some("early-semver")
ThisBuild / homepage := Some(url("https://github.com/VirtusLab/akka-serialization-helper"))
ThisBuild / homepage := Some(url("https://github.com/VirtusLab/pekko-serialization-helper"))
ThisBuild / licenses := List(
"MIT License" -> url("https://github.com/VirtusLab/akka-serialization-helper/blob/main/LICENSE"))
"MIT License" -> url("https://github.com/VirtusLab/pekko-serialization-helper/blob/main/LICENSE"))
ThisBuild / developers := List(
Developer("MarconZet", "Marcin Złakowski", "[email protected]", url("https://github.com/MarconZet")),
Developer(
Expand Down Expand Up @@ -99,15 +99,15 @@ publish / skip := true

lazy val scalaVersionAxis = settingKey[Option[String]]("Project scala version")

lazy val circeAkkaSerializer = (projectMatrix in file("circe-akka-serializer"))
.settings(name := "circe-akka-serializer")
lazy val circePekkoSerializer = (projectMatrix in file("circe-pekko-serializer"))
.settings(name := "circe-pekko-serializer")
.settings(commonSettings)
.settings(crossScalaVersions := testAgainstScalaVersions)
.settings(libraryDependencies ++= Seq(
akkaActor % Provided,
akkaActorTyped % Provided,
akkaTestKitTyped % Test,
akkaStream % Provided,
pekkoActor % Provided,
pekkoActorTyped % Provided,
pekkoTestKitTyped % Test,
pekkoStream % Provided,
circeCore,
circeParser,
circeGeneric,
Expand Down Expand Up @@ -165,13 +165,13 @@ lazy val serializabilityCheckerCompilerPlugin = (projectMatrix in file("serializ
.getOrElse(Seq.empty)
},
libraryDependencies ++= Seq(
akkaActor % Test,
akkaActorTyped % Test,
akkaPersistenceTyped % Test,
akkaProjections % Test,
pekkoActor % Test,
pekkoActorTyped % Test,
pekkoPersistenceTyped % Test,
pekkoProjections % Test,
betterFiles % Test,
akkaGrpc % Test,
akkaHttpCors % Test))
pekkoGrpc % Test,
pekkoHttpCors % Test))
.dependsOn(annotation)
.jvmPlatform(scalaVersions = targetScalaVersions)

Expand All @@ -190,12 +190,12 @@ lazy val codecRegistrationCheckerCompilerPlugin = (projectMatrix in file("codec-
.getOrElse(Seq.empty)
},
libraryDependencies += betterFiles % Test)
.dependsOn(annotation, circeAkkaSerializer % Test)
.dependsOn(annotation, circePekkoSerializer % Test)
.jvmPlatform(scalaVersions = targetScalaVersions)

lazy val sbtAkkaSerializationHelper = (project in file("sbt-akka-serialization-helper"))
lazy val sbtPekkoSerializationHelper = (project in file("sbt-pekko-serialization-helper"))
.enablePlugins(SbtPlugin)
.settings(name := "sbt-akka-serialization-helper")
.settings(name := "sbt-pekko-serialization-helper")
.settings(commonSettings)
.settings(
pluginCrossBuild / sbtVersion := "1.2.8",
Expand All @@ -214,8 +214,8 @@ lazy val sbtAkkaSerializationHelper = (project in file("sbt-akka-serialization-h
// both head and tail.head must be published because they are separate projects, one for scala 2.13, one for 2.12
(annotation.projectRefs.head / publishLocal).value
(annotation.projectRefs.tail.head / publishLocal).value
(circeAkkaSerializer.projectRefs.head / publishLocal).value
(circeAkkaSerializer.projectRefs.tail.head / publishLocal).value
(circePekkoSerializer.projectRefs.head / publishLocal).value
(circePekkoSerializer.projectRefs.tail.head / publishLocal).value
(codecRegistrationCheckerCompilerPlugin.projectRefs.head / publishLocal).value
(codecRegistrationCheckerCompilerPlugin.projectRefs.tail.head / publishLocal).value
(dumpPersistenceSchemaCompilerPlugin.projectRefs.head / publishLocal).value
Expand All @@ -240,6 +240,6 @@ lazy val dumpPersistenceSchemaCompilerPlugin = (projectMatrix in file("dump-pers
}
.getOrElse(Seq.empty)
},
libraryDependencies ++= Seq(sprayJson, betterFiles, akkaActorTyped % Test, akkaPersistenceTyped % Test))
libraryDependencies ++= Seq(sprayJson, betterFiles, pekkoActorTyped % Test, pekkoPersistenceTyped % Test))
.settings(assemblySettings: _*)
.jvmPlatform(scalaVersions = targetScalaVersions)

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Default configuration

org.virtuslab.ash {
org.virtuslab.psh {
circe {
# enables debug logging
verbose-debug-logging = off
Expand Down Expand Up @@ -28,7 +28,7 @@ org.virtuslab.ash {
# (there might be some rare corner-cases where codec-registration-checker-compiler-plugin
# is not able to find missing codec registrations - but only if sbt incremental compilation is used).
#
# Beware: enabling this check will cause a negative impact on Circe Akka Serializer performance.
# Beware: enabling this check will cause a negative impact on Circe Pekko Serializer performance.
enable-missing-codecs-check = false
}
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
package org.virtuslab.ash.circe
package org.virtuslab.psh.circe

import java.io.NotSerializableException
import java.nio.charset.StandardCharsets.UTF_8

import scala.reflect.ClassTag

import akka.actor.ExtendedActorSystem
import akka.event.Logging
import akka.serialization.SerializerWithStringManifest
import io.circe._
import io.circe.jawn.JawnParser
import org.apache.pekko.actor.ExtendedActorSystem
import org.apache.pekko.event.Logging
import org.apache.pekko.serialization.SerializerWithStringManifest

/**
* An abstract class that is extended to create a custom serializer.
*
* After creating your subclass, don't forget to add your serializer and base trait to `application.conf` (for more info
* [[https://doc.akka.io/docs/akka/current/serialization.html]])
* [[https://pekko.apache.org/docs/pekko/current/serialization.html]])
*
* Example subclass:
* {{{
* class CustomSerializer(actorSystem: ExtendedActorSystem) extends CirceAkkaSerializer[MySerializable](actorSystem) {
* class CustomSerializer(actorSystem: ExtendedActorSystem) extends CircePekkoSerializer[MySerializable](actorSystem) {
*
* implicit private val serializabilityCodec: Codec[MySerializable] = genericCodec
*
Expand All @@ -37,17 +37,17 @@ import io.circe.jawn.JawnParser
* }
* }}}
* @param system
* ExtendedActorSystem that is provided by Akka
* ExtendedActorSystem that is provided by Pekko
* @tparam Ser
* base trait that is used to mark serialization
*/
abstract class CirceAkkaSerializer[Ser <: AnyRef: ClassTag](system: ExtendedActorSystem)
abstract class CircePekkoSerializer[Ser <: AnyRef: ClassTag](system: ExtendedActorSystem)
extends SerializerWithStringManifest
with CirceTraitCodec[Ser]
with AkkaCodecs {
with PekkoCodecs {

private lazy val log = Logging(system, getClass)
private lazy val conf = system.settings.config.getConfig("org.virtuslab.ash.circe")
private lazy val conf = system.settings.config.getConfig("org.virtuslab.psh.circe")
private lazy val isDebugEnabled = conf.getBoolean("verbose-debug-logging") && log.isDebugEnabled
override lazy val shouldDoMissingCodecsCheck: Boolean = conf.getBoolean("enable-missing-codecs-check")
private lazy val compressionAlgorithm: Compression.Algorithm = conf.getString("compression.algorithm") match {
Expand Down Expand Up @@ -98,7 +98,7 @@ abstract class CirceAkkaSerializer[Ser <: AnyRef: ClassTag](system: ExtendedActo
/**
* The intended usage of this method is to provide any form of support for generic classes.
*
* Because of type erasure, it's impossible to [[org.virtuslab.ash.circe.Register]] one generic class two times with
* Because of type erasure, it's impossible to [[org.virtuslab.psh.circe.Register]] one generic class two times with
* different type parameters.
*
* The trick for combating type erasure is to register generic class only once with type parameter being its upper
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.virtuslab.ash.circe
package org.virtuslab.psh.circe

import java.io.NotSerializableException
import java.util.NoSuchElementException
Expand All @@ -15,15 +15,15 @@ import org.reflections8.Reflections
trait CirceTraitCodec[Ser <: AnyRef] extends Codec[Ser] {

/**
* Sequence that must contain [[org.virtuslab.ash.circe.Registration]] for all direct subclasses of Ser.
* Sequence that must contain [[org.virtuslab.psh.circe.Registration]] for all direct subclasses of Ser.
*
* Each `Registration` is created using [[org.virtuslab.ash.circe.Register]]s
* [[org.virtuslab.ash.circe.Register#apply]] method.
* Each `Registration` is created using [[org.virtuslab.psh.circe.Register]]s
* [[org.virtuslab.psh.circe.Register#apply]] method.
*
* To check if all needed classes are registered, use Codec Registration Checker.
*
* @see
* [[org.virtuslab.ash.circe.Register]][[org.virtuslab.ash.circe.Register#apply]] for more information about type
* [[org.virtuslab.psh.circe.Register]][[org.virtuslab.psh.circe.Register#apply]] for more information about type
* derivation
*/
val codecs: Seq[Registration[_ <: Ser]]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.virtuslab.ash.circe
package org.virtuslab.psh.circe

import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package org.virtuslab.ash.circe
package org.virtuslab.psh.circe

import akka.actor
import akka.actor.typed.ActorRef
import akka.actor.typed.ActorRefResolver
import akka.actor.typed.ActorSystem
import akka.serialization.Serialization
import akka.stream.SinkRef
import akka.stream.SourceRef
import akka.stream.StreamRefResolver
import io.circe.Codec
import io.circe.Decoder
import io.circe.Encoder
import org.apache.pekko.actor
import org.apache.pekko.actor.typed.ActorRef
import org.apache.pekko.actor.typed.ActorRefResolver
import org.apache.pekko.actor.typed.ActorSystem
import org.apache.pekko.serialization.Serialization
import org.apache.pekko.stream.SinkRef
import org.apache.pekko.stream.SourceRef
import org.apache.pekko.stream.StreamRefResolver

/**
* Default codecs for serializing some of Akka types
* Default codecs for serializing some of Pekko types
*/
trait AkkaCodecs {
trait PekkoCodecs {
private def serializationSystem: actor.ActorSystem = Serialization.getCurrentTransportInformation().system

implicit def actorRefCodec[T](implicit system: actor.ActorSystem = serializationSystem): Codec[ActorRef[T]] = {
Expand All @@ -40,4 +40,4 @@ trait AkkaCodecs {
}
}

object AkkaCodecs extends AkkaCodecs
object PekkoCodecs extends PekkoCodecs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.virtuslab.ash.circe
package org.virtuslab.psh.circe

import scala.reflect.macros.blackbox
import scala.reflect.runtime.{universe => ru}
Expand Down Expand Up @@ -26,7 +26,7 @@ object Register {
* @tparam T
* Type for which implicits will be looked for
* @return
* [[org.virtuslab.ash.circe.Registration]]
* [[org.virtuslab.psh.circe.Registration]]
*/
def apply[T: ru.TypeTag: Encoder: Decoder]: Registration[T] =
Registration[T](implicitly[ru.TypeTag[T]], implicitly[Encoder[T]], implicitly[Decoder[T]])
Expand All @@ -35,7 +35,7 @@ object Register {
def REGISTRATION_REGEX: String = macro regexImpl

/**
* `circeRegex` is the preferred typeRegexPattern for Circe Akka Serializer usage. It contains leading and trailing
* `circeRegex` is the preferred typeRegexPattern for Circe Pekko Serializer usage. It contains leading and trailing
* `.*` - so that it matches both single Registration and multiple Registrations in a collection. It is used by the
* codec-registration-checker-compiler-plugin to collect properly registered codecs.
*
Expand All @@ -44,7 +44,7 @@ object Register {
* something like `Option[Register[User_Defined_Type]]` is in the AST and codec-registration-checker-compiler-plugin
* would still treat it as proper registration. However, such situations have not been encountered in real usages.
*/
private val circeRegex = """.*org\.virtuslab\.ash\.circe\.Registration\[.*\].*"""
private val circeRegex = """.*org\.virtuslab\.psh\.circe\.Registration\[.*\].*"""

def regexImpl(c: blackbox.Context): c.Expr[String] = {
import c.universe._
Expand Down
Loading

0 comments on commit 1803c7b

Please sign in to comment.