Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 0 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,3 @@ on:
jobs:
test:
uses: evolution-gaming/scala-github-actions/.github/workflows/ci.yml@dde27b9bd793d41d5aacf8fb74403c9de5da1146 # v6.3.0
with:
scala_versions: '["2.13.18", "3.3.7"]'
# TODO sbt-scalafmt is in plugins.sbt but there is no .scalafmt.conf, so formatting was never checked
scalafmt_check: false
96 changes: 96 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Main goals:
# - nicer commit diffs (trailing commas, no alignment for pattern matching, force new lines)
# - better interop with default IntelliJ IDEA setup (matching import and modifiers sorting logic)
# - better developer experience on laptop screens (like 16' MBPs) with IntelliJ IDEA (line wraps)

version = 3.11.5

runner.dialect = scala213source3

# only format files tracked by git
project.git = true

maxColumn = 120
trailingCommas = always

preset = default
# do not align to make nicer commit diffs
align.preset = none

indent {
# altering defnSite and extendSite to have this:
# final class MyErr extends RuntimeException(
# "super error message",
# )
# instead of this:
# final class MyErr extends RuntimeException(
# "super error message",
# )
defnSite = 2
extendSite = 0
}

spaces {
# makes string interpolation with curlies more visually distinct
inInterpolatedStringCurlyBraces = true
}

newlines {
# keep author new lines where possible
source = keep
# force new line after "(implicit" for multi-line arg lists
implicitParamListModifierForce = [after]
avoidForSimpleOverflow = [
tooLong, # if the line would be too long even after newline inserted, do nothing
slc, # do nothing if overflow caused by single line comment
]
}

verticalMultiline {
atDefnSite = true
arityThreshold = 4 # more than 3 args in a list will be turned vertical
newlineAfterOpenParen = true # for nicer commit diffs
}

# for nicer commit diffs - forces new line before last parenthesis:
# class MyCls(
# arg1: String,
# arg2: String,
# ) extends MyTrait {
#
# without it:
# class MyCls(
# arg1: String,
# arg2: String) extends MyTrait {
danglingParentheses.exclude = []

docstrings {
# easier to view diffs in IDEA on 16' MBP screen if docs max line are shorter than code
wrapMaxColumn = 100
# next settings make it similar to the default IDEA javadoc formatting
style = Asterisk
oneline = unfold
blankFirstLine = unfold
}

rewrite.rules = [
Imports,
RedundantParens,
SortModifiers,
prefercurlyfors,
]

# put visibility modifier first
rewrite.sortModifiers.preset = styleGuide

# Import sorting as similar as possible to scalafix's "OrganizeImports.preset = INTELLIJ_2020_3".
# Scalafix is not used as its commands mess up "all .." build aliases and it takes long time to run,
# while its code semantic based features are not needed here.
# I.e. detection of unused imports is done with Scala compiler options.
rewrite.imports {
sort = ascii
groups = [
[".*"],
["java\\..*", "javax\\..*", "scala\\..*"],
]
}
16 changes: 9 additions & 7 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ name := "pubsub"

organization := "com.evolutiongaming"

homepage := Some(url("https://github.com/evolution-gaming/pubsub"))
homepage := Some(uri("https://github.com/evolution-gaming/pubsub"))

startYear := Some(2017)

organizationName := "Evolution"

organizationHomepage := Some(url("https://evolution.com"))
organizationHomepage := Some(uri("https://evolution.com"))

crossScalaVersions := Seq("2.13.18", "3.3.7")
crossScalaVersions := Seq("2.13.18", "3.3.8")

scalaVersion := crossScalaVersions.value.head

Expand Down Expand Up @@ -40,7 +40,7 @@ libraryDependencies ++= crossSettings(
if3 = Seq(Scodec.Scala3.Core),
)

licenses := Seq(("MIT", url("https://opensource.org/licenses/MIT")))
licenses := Seq(("MIT", uri("https://opensource.org/licenses/MIT")))

scalacOptions ++= Seq(
"-release:17",
Expand Down Expand Up @@ -69,9 +69,11 @@ scalacOptions ++= crossSettings(

Compile / doc / scalacOptions ++= Seq("-groups", "-implicits", "-no-link-warnings")

//addCommandAlias("check", "all versionPolicyCheck Compile/doc")
addCommandAlias("check", "show version")
addCommandAlias("build", "+all compile test")
versionPolicyIntention := Compatibility.BinaryCompatible

addCommandAlias("check", "all scalafmtCheckRepo versionPolicyCheck Compile/doc")
addCommandAlias("fmt", "scalafmtRepo")
addCommandAlias("build", "+all compile testFull")

def crossSettings[T](scalaVersion: String, if3: T, if2: T): T = {
scalaVersion match {
Expand Down
16 changes: 8 additions & 8 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ import sbt._
object Dependencies {

val `akka-serialization` = "com.evolutiongaming" %% "akka-serialization" % "1.1.0"
val `metric-tools` = "com.evolutiongaming" %% "metric-tools" % "3.0.0"
val `cats-helper` = "com.evolutiongaming" %% "cats-helper" % "3.12.2"
val scache = "com.evolution" %% "scache" % "6.0.1"
val scalatest = "org.scalatest" %% "scalatest" % "3.2.20"
val `metric-tools` = "com.evolutiongaming" %% "metric-tools" % "3.0.0"
val `cats-helper` = "com.evolutiongaming" %% "cats-helper" % "3.12.2"
val scache = "com.evolution" %% "scache" % "6.0.1"
val scalatest = "org.scalatest" %% "scalatest" % "3.2.20"

object Akka {
private val version = "2.6.21"
val Actor = "com.typesafe.akka" %% "akka-actor" % version
val Actor = "com.typesafe.akka" %% "akka-actor" % version
val ClusterTools = "com.typesafe.akka" %% "akka-cluster-tools" % version
val Testkit = "com.typesafe.akka" %% "akka-testkit" % version
val Stream = "com.typesafe.akka" %% "akka-stream" % version
val Testkit = "com.typesafe.akka" %% "akka-testkit" % version
val Stream = "com.typesafe.akka" %% "akka-stream" % version
}

object Scodec {
Expand All @@ -27,7 +27,7 @@ object Dependencies {
}

object Cats {
val core = "org.typelevel" %% "cats-core" % "2.13.0"
val core = "org.typelevel" %% "cats-core" % "2.13.0"
val effect = "org.typelevel" %% "cats-effect" % "3.7.0"
}
}
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.12.12
sbt.version = 2.0.6
8 changes: 3 additions & 5 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ addSbtPlugin("com.github.sbt" % "sbt-dynver" % "5.1.1")

addSbtPlugin("com.evolution" % "sbt-scalac-opts-plugin" % "0.2.0")

addSbtPlugin("com.evolution" % "sbt-artifactory-plugin" % "0.0.2")
addSbtPlugin("com.evolution" % "sbt-artifactory-plugin" % "0.1.2")

addSbtPlugin("ch.epfl.scala" % "sbt-version-policy" % "3.2.1")
addSbtPlugin("ch.epfl.scala" % "sbt-version-policy" % "3.3.0")

addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.6.1")

addDependencyTreePlugin
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.6.2")
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.evolutiongaming.cluster.pubsub

import java.io.NotSerializableException

import akka.serialization.SerializerWithStringManifest
import com.evolutiongaming.serialization.SerializedMsg
import scodec.bits.ByteVector
import scodec.codecs._

import java.io.NotSerializableException

class PubSubSerializer extends SerializerWithStringManifest {
import PubSubSerializer._

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.evolutiongaming.cluster.pubsub

import java.io.NotSerializableException

import akka.serialization.SerializerWithStringManifest
import com.evolutiongaming.serialization.SerializedMsg
import scodec.*
import scodec.Codec.*
import scodec.bits.*
import scodec.codecs.*

import java.io.NotSerializableException

class PubSubSerializer extends SerializerWithStringManifest {
import PubSubSerializer._

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ import scala.concurrent.{ExecutionContext, Future}
import scala.util.{Failure, Success}

/**
* Override to be able to serialize/deserialize msgs on PubSub level to offload akka remoting transport.
* Serialization performed if there are remote subscribers, once per msg, disregarding the number of subscribers
* Deserialization performed on every remote node once per message, disregarding the number of subscribers as well.
*/
* Override to be able to serialize/deserialize msgs on PubSub level to offload akka remoting
* transport. Serialization performed if there are remote subscribers, once per msg, disregarding
* the number of subscribers Deserialization performed on every remote node once per message,
* disregarding the number of subscribers as well.
*/
class DistributedPubSubMediatorSerializing(
settings: DistributedPubSubSettings,
serialize: String => Boolean,
metrics: PubSub.Metrics[Id]
metrics: PubSub.Metrics[Id],
) extends DistributedPubSubMediator(settings) with DistributedPubSubMediatorSerializing.StreamHelper {

import DistributedPubSubMediatorSerializing._
Expand Down Expand Up @@ -89,10 +90,10 @@ class DistributedPubSubMediatorSerializing(
}

msg match {
case _: PubSubMsg => forward()
case _: SerializedMsg => forward()
case _: PubSubMsg => forward()
case _: SerializedMsg => forward()
case x: AnyRef if serialize(topic) => serializeAndForward(x)
case _ => forward()
case _ => forward()
}
} else {
forward()
Expand All @@ -107,7 +108,8 @@ class DistributedPubSubMediatorSerializing(
}

private def ignoreOrSendToDeadLetters(msg: Any) =
if (settings.sendToDeadLettersWhenNoSubscribers) context.system.deadLetters ! DeadLetter(msg, sender(), context.self)
if (settings.sendToDeadLettersWhenNoSubscribers) context.system.deadLetters !
DeadLetter(msg, sender(), context.self)

case class SerializationTask(topic: String, serialize: Future[(SendToAll, ActorRef)])
}
Expand All @@ -119,7 +121,7 @@ object DistributedPubSubMediatorSerializing {
def props(
settings: DistributedPubSubSettings,
serialize: String => Boolean,
metrics: PubSub.Metrics[Id]
metrics: PubSub.Metrics[Id],
): Props = {

def actor = new DistributedPubSubMediatorSerializing(settings, serialize, metrics)
Expand All @@ -131,7 +133,7 @@ object DistributedPubSubMediatorSerializing {
system: ActorSystem,
serialize: String => Boolean,
metrics: PubSub.Metrics[Id],
name: String = "distributedPubSubMediatorOverride"
name: String = "distributedPubSubMediatorOverride",
): ActorRef = {

val settings = DistributedPubSubSettings(system)
Expand All @@ -144,10 +146,8 @@ object DistributedPubSubMediatorSerializing {
system.asInstanceOf[ExtendedActorSystem].systemActorOf(props, name)
}


private def toTopic(path: String) = path.split("/").last


class TopicSerializing(
emptyTimeToLive: FiniteDuration,
routingLogic: RoutingLogic,
Expand Down Expand Up @@ -203,7 +203,6 @@ object DistributedPubSubMediatorSerializing {
}
}


trait StreamHelper extends Actor with ActorLogging {

def selfSink[A]: Sink[(A, ActorRef), Future[Done]] = {
Expand All @@ -212,14 +211,19 @@ object DistributedPubSubMediatorSerializing {

implicit class SourceQueueWithCompleteOps[A](self: SourceQueueWithComplete[A]) {

def offerAndLog(elem: A, errorMsg: => String)(implicit ec: ExecutionContext): Unit = {
def offerAndLog(
elem: A,
errorMsg: => String,
)(implicit
ec: ExecutionContext,
): Unit = {
self.offer(elem) onComplete {
case Success(QueueOfferResult.Enqueued) =>
case Success(QueueOfferResult.Enqueued) =>
case Success(QueueOfferResult.Failure(failure)) => log.error(failure, errorMsg)
case Success(failure) => log.error(s"$errorMsg $failure")
case Failure(failure) => log.error(failure, s"$errorMsg $failure")
case Success(failure) => log.error(s"$errorMsg $failure")
case Failure(failure) => log.error(failure, s"$errorMsg $failure")
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ object LocalPubSub {

private[cluster] case object GetState
private[cluster] final case class State(value: Map[String, Set[ActorRef]])
}
}
Loading