pekko/akka-remote/src/main/scala/akka/remote/netty/Settings.scala

141 lines
5.7 KiB
Scala
Raw Normal View History

/**
2012-05-21 16:45:15 +02:00
* Copyright (C) 2009-2012 Typesafe Inc. <http://www.typesafe.com>
*/
package akka.remote.netty
import com.typesafe.config.Config
import akka.util.Duration
import java.util.concurrent.TimeUnit._
import java.net.InetAddress
import akka.ConfigurationException
2012-05-24 11:44:39 +02:00
private[akka] class NettySettings(config: Config, val systemName: String) {
import config._
2012-05-24 11:44:39 +02:00
val BackoffTimeout: Duration = Duration(getMilliseconds("backoff-timeout"), MILLISECONDS)
val SecureCookie: Option[String] = getString("secure-cookie") match {
case "" None
case cookie Some(cookie)
}
2012-05-24 11:44:39 +02:00
val RequireCookie: Boolean = {
val requireCookie = getBoolean("require-cookie")
if (requireCookie && SecureCookie.isEmpty) throw new ConfigurationException(
"Configuration option 'akka.remote.netty.require-cookie' is turned on but no secure cookie is defined in 'akka.remote.netty.secure-cookie'.")
requireCookie
}
2012-05-24 11:44:39 +02:00
val UsePassiveConnections: Boolean = getBoolean("use-passive-connections")
val UseDispatcherForIO: Option[String] = getString("use-dispatcher-for-io") match {
case "" | null None
case dispatcher Some(dispatcher)
}
2012-05-24 11:44:39 +02:00
val ReconnectionTimeWindow: Duration = Duration(getMilliseconds("reconnection-time-window"), MILLISECONDS)
val ReadTimeout: Duration = Duration(getMilliseconds("read-timeout"), MILLISECONDS)
val WriteTimeout: Duration = Duration(getMilliseconds("write-timeout"), MILLISECONDS)
val AllTimeout: Duration = Duration(getMilliseconds("all-timeout"), MILLISECONDS)
val ReconnectDelay: Duration = Duration(getMilliseconds("reconnect-delay"), MILLISECONDS)
2012-05-24 11:44:39 +02:00
val MessageFrameSize: Int = getBytes("message-frame-size").toInt
private[this] def optionSize(s: String): Option[Int] = getBytes(s).toInt match {
case 0 None
case x if x < 0
throw new ConfigurationException("Setting '%s' must be 0 or positive (and fit in an Int)" format s)
case other Some(other)
}
val WriteBufferHighWaterMark: Option[Int] = optionSize("write-buffer-high-water-mark")
2012-06-01 21:47:14 +02:00
val WriteBufferLowWaterMark: Option[Int] = optionSize("write-buffer-low-water-mark")
val SendBufferSize: Option[Int] = optionSize("send-buffer-size")
val ReceiveBufferSize: Option[Int] = optionSize("receive-buffer-size")
2012-05-24 11:44:39 +02:00
val Hostname: String = getString("hostname") match {
case "" InetAddress.getLocalHost.getHostAddress
case value value
}
val OutboundLocalAddress: Option[String] = getString("outbound-local-address") match {
case "auto" | "" | null None
case some Some(some)
}
@deprecated("WARNING: This should only be used by professionals.", "2.0")
2012-05-24 11:44:39 +02:00
val PortSelector: Int = getInt("port")
2012-05-24 11:44:39 +02:00
val ConnectionTimeout: Duration = Duration(getMilliseconds("connection-timeout"), MILLISECONDS)
2012-05-24 11:44:39 +02:00
val Backlog: Int = getInt("backlog")
2012-05-24 11:44:39 +02:00
val ExecutionPoolKeepalive: Duration = Duration(getMilliseconds("execution-pool-keepalive"), MILLISECONDS)
2012-05-24 11:44:39 +02:00
val ExecutionPoolSize: Int = getInt("execution-pool-size") match {
case sz if sz < 1 throw new IllegalArgumentException("akka.remote.netty.execution-pool-size is less than 1")
case sz sz
}
2012-05-24 11:44:39 +02:00
val MaxChannelMemorySize: Long = getBytes("max-channel-memory-size") match {
case sz if sz < 0 throw new IllegalArgumentException("akka.remote.netty.max-channel-memory-size is less than 0 bytes")
case sz sz
}
2012-05-24 11:44:39 +02:00
val MaxTotalMemorySize: Long = getBytes("max-total-memory-size") match {
case sz if sz < 0 throw new IllegalArgumentException("akka.remote.netty.max-total-memory-size is less than 0 bytes")
case sz sz
}
val SSLKeyStore = getString("ssl.key-store") match {
case "" None
case keyStore Some(keyStore)
}
val SSLTrustStore = getString("ssl.trust-store") match {
case "" None
case trustStore Some(trustStore)
}
val SSLKeyStorePassword = getString("ssl.key-store-password") match {
case "" None
case password Some(password)
}
val SSLTrustStorePassword = getString("ssl.trust-store-password") match {
case "" None
case password Some(password)
}
val SSLSupportedAlgorithms = getStringList("ssl.supported-algorithms").toArray.toSet
val SSLProtocol = getString("ssl.protocol") match {
case "" None
case protocol Some(protocol)
}
val SSLRandomSource = getString("ssl.sha1prng-random-source") match {
case "" None
case path Some(path)
}
val SSLRandomNumberGenerator = getString("ssl.random-number-generator") match {
case "" None
case rng Some(rng)
}
val EnableSSL = {
val enableSSL = getBoolean("ssl.enable")
if (enableSSL) {
if (SSLProtocol.isEmpty) throw new ConfigurationException(
"Configuration option 'akka.remote.netty.ssl.enable is turned on but no protocol is defined in 'akka.remote.netty.ssl.protocol'.")
if (SSLKeyStore.isEmpty && SSLTrustStore.isEmpty) throw new ConfigurationException(
"Configuration option 'akka.remote.netty.ssl.enable is turned on but no key/trust store is defined in 'akka.remote.netty.ssl.key-store' / 'akka.remote.netty.ssl.trust-store'.")
if (SSLKeyStore.isDefined && SSLKeyStorePassword.isEmpty) throw new ConfigurationException(
"Configuration option 'akka.remote.netty.ssl.key-store' is defined but no key-store password is defined in 'akka.remote.netty.ssl.key-store-password'.")
if (SSLTrustStore.isDefined && SSLTrustStorePassword.isEmpty) throw new ConfigurationException(
"Configuration option 'akka.remote.netty.ssl.trust-store' is defined but no trust-store password is defined in 'akka.remote.netty.ssl.trust-store-password'.")
}
enableSSL
}
2012-05-21 16:45:15 +02:00
}