2012-01-20 14:29:50 +01:00
/* *
2012-05-21 16:45:15 +02:00
* Copyright ( C ) 2009 - 2012 Typesafe Inc . < http : //www.typesafe.com>
2012-01-20 14:29:50 +01:00
*/
package akka.remote.netty
import com.typesafe.config.Config
2012-09-21 14:50:06 +02:00
import scala.concurrent.duration.Duration
2012-01-20 14:29:50 +01:00
import java.util.concurrent.TimeUnit._
import java.net.InetAddress
2012-05-16 17:04:13 +02:00
import akka.ConfigurationException
2012-06-20 00:47:11 +02:00
import scala.collection.JavaConverters.iterableAsScalaIterableConverter
2012-09-21 14:50:06 +02:00
import scala.concurrent.duration.FiniteDuration
2012-01-20 14:29:50 +01:00
2012-05-24 11:44:39 +02:00
private [ akka ] class NettySettings ( config : Config , val systemName : String ) {
2012-01-20 14:29:50 +01:00
import config._
2012-08-21 09:22:09 +02:00
val BackoffTimeout : FiniteDuration = Duration ( getMilliseconds ( "backoff-timeout" ) , MILLISECONDS )
2012-01-20 14:29:50 +01:00
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 = {
2012-01-20 14:29:50 +01:00
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 {
2012-04-27 01:10:20 +02:00
case "" | null ⇒ None
case dispatcher ⇒ Some ( dispatcher )
}
2012-01-20 14:29:50 +01:00
2012-08-21 09:22:09 +02:00
val ReconnectionTimeWindow : FiniteDuration = Duration ( getMilliseconds ( "reconnection-time-window" ) , MILLISECONDS )
val ReadTimeout : FiniteDuration = Duration ( getMilliseconds ( "read-timeout" ) , MILLISECONDS )
val WriteTimeout : FiniteDuration = Duration ( getMilliseconds ( "write-timeout" ) , MILLISECONDS )
val AllTimeout : FiniteDuration = Duration ( getMilliseconds ( "all-timeout" ) , MILLISECONDS )
val ReconnectDelay : FiniteDuration = Duration ( getMilliseconds ( "reconnect-delay" ) , MILLISECONDS )
2012-06-01 21:29:47 +02:00
2012-05-24 11:44:39 +02:00
val MessageFrameSize : Int = getBytes ( "message-frame-size" ) . toInt
2012-01-20 14:29:50 +01:00
2012-06-01 21:29:47 +02:00
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" )
2012-06-01 21:29:47 +02:00
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 {
2012-01-20 14:29:50 +01:00
case "" ⇒ InetAddress . getLocalHost . getHostAddress
case value ⇒ value
}
2012-02-01 16:06:30 +01:00
2012-02-18 17:39:20 +01:00
val OutboundLocalAddress : Option [ String ] = getString ( "outbound-local-address" ) match {
case "auto" | "" | null ⇒ None
case some ⇒ Some ( some )
}
2012-02-10 08:20:36 +01:00
@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-01-27 12:14:28 +01:00
2012-08-21 09:22:09 +02:00
val ConnectionTimeout : FiniteDuration = Duration ( getMilliseconds ( "connection-timeout" ) , MILLISECONDS )
2012-01-20 14:29:50 +01:00
2012-05-24 11:44:39 +02:00
val Backlog : Int = getInt ( "backlog" )
2012-01-20 14:29:50 +01:00
2012-08-21 09:22:09 +02:00
val ExecutionPoolKeepalive : FiniteDuration = Duration ( getMilliseconds ( "execution-pool-keepalive" ) , MILLISECONDS )
2012-01-20 14:29:50 +01:00
2012-05-24 11:44:39 +02:00
val ExecutionPoolSize : Int = getInt ( "execution-pool-size" ) match {
2012-06-20 14:29:41 +02:00
case sz if sz < 0 ⇒ throw new IllegalArgumentException ( "akka.remote.netty.execution-pool-size is less than 0" )
2012-01-20 14:29:50 +01:00
case sz ⇒ sz
}
2012-05-24 11:44:39 +02:00
val MaxChannelMemorySize : Long = getBytes ( "max-channel-memory-size" ) match {
2012-01-20 14:29:50 +01:00
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 {
2012-01-20 14:29:50 +01:00
case sz if sz < 0 ⇒ throw new IllegalArgumentException ( "akka.remote.netty.max-total-memory-size is less than 0 bytes" )
case sz ⇒ sz
}
2012-05-28 23:51:47 +02:00
val SSLKeyStore = getString ( "ssl.key-store" ) match {
2012-05-25 00:59:17 +02:00
case "" ⇒ None
case keyStore ⇒ Some ( keyStore )
}
2012-05-28 23:51:47 +02:00
val SSLTrustStore = getString ( "ssl.trust-store" ) match {
2012-05-25 00:59:17 +02:00
case "" ⇒ None
case trustStore ⇒ Some ( trustStore )
}
2012-05-28 23:51:47 +02:00
val SSLKeyStorePassword = getString ( "ssl.key-store-password" ) match {
2012-05-25 00:59:17 +02:00
case "" ⇒ None
case password ⇒ Some ( password )
}
2012-05-28 23:51:47 +02:00
val SSLTrustStorePassword = getString ( "ssl.trust-store-password" ) match {
2012-05-25 00:59:17 +02:00
case "" ⇒ None
case password ⇒ Some ( password )
}
2012-06-20 00:47:11 +02:00
val SSLEnabledAlgorithms = iterableAsScalaIterableConverter ( getStringList ( "ssl.enabled-algorithms" ) ) . asScala . toSet [ String ]
2012-05-25 00:59:17 +02:00
2012-05-28 23:51:47 +02:00
val SSLProtocol = getString ( "ssl.protocol" ) match {
2012-05-25 00:59:17 +02:00
case "" ⇒ None
case protocol ⇒ Some ( protocol )
}
2012-06-05 13:44:05 +02:00
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 )
}
2012-05-25 00:59:17 +02:00
val EnableSSL = {
2012-05-28 23:51:47 +02:00
val enableSSL = getBoolean ( "ssl.enable" )
2012-05-25 00:59:17 +02:00
if ( enableSSL ) {
if ( SSLProtocol . isEmpty ) throw new ConfigurationException (
2012-05-28 23:51:47 +02:00
"Configuration option 'akka.remote.netty.ssl.enable is turned on but no protocol is defined in 'akka.remote.netty.ssl.protocol'." )
2012-05-25 00:59:17 +02:00
if ( SSLKeyStore . isEmpty && SSLTrustStore . isEmpty ) throw new ConfigurationException (
2012-05-28 23:51:47 +02:00
"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'." )
2012-05-25 00:59:17 +02:00
if ( SSLKeyStore . isDefined && SSLKeyStorePassword . isEmpty ) throw new ConfigurationException (
2012-05-28 23:51:47 +02:00
"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'." )
2012-05-25 00:59:17 +02:00
if ( SSLTrustStore . isDefined && SSLTrustStorePassword . isEmpty ) throw new ConfigurationException (
2012-05-28 23:51:47 +02:00
"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'." )
2012-05-25 00:59:17 +02:00
}
enableSSL
}
2012-05-21 16:45:15 +02:00
}