Skip to content

Commit

Permalink
add validations for config settings
Browse files Browse the repository at this point in the history
  • Loading branch information
pjfanning committed Feb 11, 2024
1 parent 49b89f0 commit f71e8fb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
6 changes: 5 additions & 1 deletion remote/src/main/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ pekko {
# By default, we only support "pekko" protocol.
# If you want to also support Akka, change this config to:
# pekko.remote.accept-protocol-names = ["pekko", "akka"]
# A ConfigurationException will be thrown at runtime if the array is empty
# or contains values other than "pekko" and/or "akka".
accept-protocol-names = ["pekko"]

# The protocol name to use when sending requests to other remote actors.
Expand All @@ -198,7 +200,9 @@ pekko {
# such as Lightbend's "akka" (whilst making sure accept-protocol-names
# contains "akka") so that you can gracefully migrate all nodes to Apache
# Pekko and then change the protocol-name back to "pekko" once all
# nodes have been are running on Apache Pekko
# nodes have been are running on Apache Pekko.
# A ConfigurationException will be thrown at runtime if the value is not
# set to "pekko" or "akka".
protocol-name = "pekko"

# When pekko.remote.accept-protocol-names contains "akka", then we
Expand Down
27 changes: 23 additions & 4 deletions remote/src/main/scala/org/apache/pekko/remote/RemoteSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,30 @@ final class RemoteSettings(val config: Config) {
@deprecated("Classic remoting is deprecated, use Artery", "Akka 2.6.0")
val Adapters: Map[String, String] = configToMap(getConfig("pekko.remote.classic.adapters"))

val ProtocolName: String = getString("pekko.remote.protocol-name")
private val AllowableProtocolNames = Set("pekko", "akka")

val AcceptProtocolNames: Set[String] =
immutableSeq(getStringList("pekko.remote.accept-protocol-names")).toSet.requiring(_.nonEmpty,
"accept-protocol-names must be non empty")
val ProtocolName: String = {
val setting = getString("pekko.remote.protocol-name")
if (!AllowableProtocolNames.contains(setting)) {
throw new ConfigurationException("The only allowed values for pekko.remote.protocol-name " +
"are \"pekko\" and \"akka\".")
}
setting
}

val AcceptProtocolNames: Set[String] = {
val set = immutableSeq(getStringList("pekko.remote.accept-protocol-names")).toSet
if (set.isEmpty) {
throw new ConfigurationException("pekko.remote.accept-protocol-names setting must not be empty. " +
"The setting is an array and the only acceptable values are \"pekko\" and \"akka\".")
}
val filteredSet = set.filterNot(s => s == "akka" || s == "pekko")
if (filteredSet.nonEmpty) {
throw new ConfigurationException("pekko.remote.accept-protocol-names is an array setting " +
"that only accepts the values \"pekko\" and \"akka\".")
}
set
}

private def transportNames: immutable.Seq[String] =
immutableSeq(getStringList("pekko.remote.classic.enabled-transports"))
Expand Down

0 comments on commit f71e8fb

Please sign in to comment.