!htt #19514 Update RouterSettings to be non case class

This commit is contained in:
Johan Andrén 2016-01-25 14:03:04 +01:00
parent 379a3a85b4
commit 61b375cec8
26 changed files with 188 additions and 64 deletions

View file

@ -0,0 +1,30 @@
/*
* Copyright (C) 2009-2014 Typesafe Inc. <http://www.typesafe.com>
*/
package akka.http.impl.settings
import akka.http.impl.util._
import com.typesafe.config.Config
/** INTERNAL API */
final case class RoutingSettingsImpl(
verboseErrorMessages: Boolean,
fileGetConditional: Boolean,
renderVanityFooter: Boolean,
rangeCountLimit: Int,
rangeCoalescingThreshold: Long,
decodeMaxBytesPerChunk: Int,
fileIODispatcher: String) extends akka.http.scaladsl.settings.RoutingSettings
object RoutingSettingsImpl extends SettingsCompanion[RoutingSettingsImpl]("akka.http.routing") {
def fromSubConfig(root: Config, c: Config) = new RoutingSettingsImpl(
c getBoolean "verbose-error-messages",
c getBoolean "file-get-conditional",
c getBoolean "render-vanity-footer",
c getInt "range-count-limit",
c getBytes "range-coalescing-threshold",
c getIntBytes "decode-max-bytes-per-chunk",
c getString "file-io-dispatcher")
}

View file

@ -15,7 +15,10 @@ import scala.collection.JavaConverters._
import scala.compat.java8.OptionConverters._
import scala.concurrent.duration.{ Duration, FiniteDuration }
abstract class ClientConnectionSettings {
/**
* Public API but not intended for subclassing
*/
abstract class ClientConnectionSettings private[akka] () { self: ClientConnectionSettingsImpl
def getUserAgentHeader: Optional[UserAgent]
def getConnectingTimeout: FiniteDuration
def getIdleTimeout: Duration
@ -34,8 +37,6 @@ abstract class ClientConnectionSettings {
def withSocketOptions(newValue: java.lang.Iterable[SocketOption]): ClientConnectionSettings = self.copy(socketOptions = newValue.asScala.toList)
def withParserSettings(newValue: ParserSettings): ClientConnectionSettings = self.copy(parserSettings = newValue.asScala)
/** INTERNAL API: safe by construction */
protected val self = this.asInstanceOf[ClientConnectionSettingsImpl]
}
object ClientConnectionSettings extends SettingsCompanion[ClientConnectionSettings] {

View file

@ -9,7 +9,10 @@ import com.typesafe.config.Config
import scala.concurrent.duration.Duration
import akka.http.impl.util.JavaMapping.Implicits._
abstract class ConnectionPoolSettings {
/**
* Public API but not intended for subclassing
*/
abstract class ConnectionPoolSettings private[akka] () { self: ConnectionPoolSettingsImpl
def getMaxConnections: Int
def getMaxRetries: Int
def getMaxOpenRequests: Int
@ -25,9 +28,6 @@ abstract class ConnectionPoolSettings {
def withPipeliningLimit(newValue: Int): ConnectionPoolSettings = self.copy(pipeliningLimit = newValue)
def withIdleTimeout(newValue: Duration): ConnectionPoolSettings = self.copy(idleTimeout = newValue)
def withConnectionSettings(newValue: ClientConnectionSettings): ConnectionPoolSettings = self.copy(connectionSettings = newValue.asScala)
/** INTERNAL API */
protected def self = this.asInstanceOf[ConnectionPoolSettingsImpl]
}
object ConnectionPoolSettings extends SettingsCompanion[ConnectionPoolSettings] {

View file

@ -16,7 +16,10 @@ import scala.compat.java8.OptionConverters
import akka.http.javadsl.model.{ HttpMethod, StatusCode, Uri }
import com.typesafe.config.Config
abstract class ParserSettings extends BodyPartParser.Settings {
/**
* Public API but not intended for subclassing
*/
abstract class ParserSettings private[akka] () extends BodyPartParser.Settings { self: ParserSettingsImpl
def getMaxUriLength: Int
def getMaxMethodLength: Int
def getMaxResponseReasonLength: Int
@ -56,17 +59,17 @@ abstract class ParserSettings extends BodyPartParser.Settings {
// special ---
@varargs
def withCustomMethods(methods: HttpMethod*): ParserSettings = {
val map = methods.map(m m.name -> m.asScala).toMap
self.copy(customMethods = map.get)
}
@varargs
def withCustomStatusCodes(codes: StatusCode*): ParserSettings = {
val map = codes.map(c c.intValue -> c.asScala).toMap
self.copy(customStatusCodes = map.get)
}
/** INTERNAL API */
protected def self = this.asInstanceOf[ParserSettingsImpl]
}
object ParserSettings extends SettingsCompanion[ParserSettings] {

View file

@ -0,0 +1,33 @@
/*
* Copyright (C) 2016 Typesafe Inc. <http://www.typesafe.com>
*/
package akka.http.javadsl.settings
import akka.http.impl.settings.RoutingSettingsImpl
import com.typesafe.config.Config
/**
* Public API but not intended for subclassing
*/
abstract class RoutingSettings private[akka] () { self: RoutingSettingsImpl
def getVerboseErrorMessages: Boolean
def getFileGetConditional: Boolean
def getRenderVanityFooter: Boolean
def getRangeCountLimit: Int
def getRangeCoalescingThreshold: Long
def getDecodeMaxBytesPerChunk: Int
def getFileIODispatcher: String
def withVerboseErrorMessages(verboseErrorMessages: Boolean): RoutingSettings = self.copy(verboseErrorMessages = verboseErrorMessages)
def withFileGetConditional(fileGetConditional: Boolean): RoutingSettings = self.copy(fileGetConditional = fileGetConditional)
def withRenderVanityFooter(renderVanityFooter: Boolean): RoutingSettings = self.copy(renderVanityFooter = renderVanityFooter)
def withRangeCountLimit(rangeCountLimit: Int): RoutingSettings = self.copy(rangeCountLimit = rangeCountLimit)
def withRangeCoalescingThreshold(rangeCoalescingThreshold: Long): RoutingSettings = self.copy(rangeCoalescingThreshold = rangeCoalescingThreshold)
def withDecodeMaxBytesPerChunk(decodeMaxBytesPerChunk: Int): RoutingSettings = self.copy(decodeMaxBytesPerChunk = decodeMaxBytesPerChunk)
def withFileIODispatcher(fileIODispatcher: String): RoutingSettings = self.copy(fileIODispatcher = fileIODispatcher)
}
object RoutingSettings extends SettingsCompanion[RoutingSettings] {
override def create(config: Config): RoutingSettings = RoutingSettingsImpl(config)
override def create(configOverrides: String): RoutingSettings = RoutingSettingsImpl(configOverrides)
}

View file

@ -15,7 +15,10 @@ import scala.compat.java8.OptionConverters._
import scala.concurrent.duration.{ Duration, FiniteDuration }
abstract class ServerSettings {
/**
* Public API but not intended for subclassing
*/
abstract class ServerSettings { self: ServerSettingsImpl
def getServerHeader: Optional[Server]
def getTimeouts: ServerSettings.Timeouts
def getMaxConnections: Int
@ -48,8 +51,6 @@ abstract class ServerSettings {
def withParserSettings(newValue: ParserSettings): ServerSettings = self.copy(parserSettings = newValue.asScala)
def withWebsocketRandomFactory(newValue: java.util.function.Supplier[Random]): ServerSettings = self.copy(websocketRandomFactory = () newValue.get())
/** INTERNAL API */
protected def self = this.asInstanceOf[ServerSettingsImpl]
}
object ServerSettings {

View file

@ -20,7 +20,10 @@ import scala.compat.java8.OptionConverters
import scala.concurrent.duration.{ FiniteDuration, Duration }
import scala.collection.JavaConverters._
abstract class ClientConnectionSettings extends akka.http.javadsl.settings.ClientConnectionSettings {
/**
* Public API but not intended for subclassing
*/
abstract class ClientConnectionSettings private[akka] () extends akka.http.javadsl.settings.ClientConnectionSettings { self: ClientConnectionSettingsImpl
def userAgentHeader: Option[`User-Agent`]
def connectingTimeout: FiniteDuration
def idleTimeout: Duration

View file

@ -3,14 +3,16 @@
*/
package akka.http.scaladsl.settings
import akka.actor.ActorSystem
import akka.http.impl.settings.ConnectionPoolSettingsImpl
import akka.http.javadsl.{ settings js }
import com.typesafe.config.Config
import scala.concurrent.duration.Duration
abstract class ConnectionPoolSettings extends js.ConnectionPoolSettings {
/**
* Public API but not intended for subclassing
*/
abstract class ConnectionPoolSettings extends js.ConnectionPoolSettings { self: ConnectionPoolSettingsImpl
def maxConnections: Int
def maxRetries: Int
def maxOpenRequests: Int

View file

@ -19,7 +19,10 @@ import scala.annotation.varargs
import scala.collection.JavaConverters._
import scala.compat.java8.OptionConverters
abstract class ParserSettings extends akka.http.javadsl.settings.ParserSettings {
/**
* Public API but not intended for subclassing
*/
abstract class ParserSettings private[akka] () extends akka.http.javadsl.settings.ParserSettings { self: ParserSettingsImpl
def maxUriLength: Int
def maxMethodLength: Int
def maxResponseReasonLength: Int

View file

@ -0,0 +1,43 @@
/*
* Copyright (C) 2016 Typesafe Inc. <http://www.typesafe.com>
*/
package akka.http.scaladsl.settings
import akka.http.impl.settings.RoutingSettingsImpl
import com.typesafe.config.Config
/**
* Public API but not intended for subclassing
*/
abstract class RoutingSettings private[akka] () extends akka.http.javadsl.settings.RoutingSettings { self: RoutingSettingsImpl
def verboseErrorMessages: Boolean
def fileGetConditional: Boolean
def renderVanityFooter: Boolean
def rangeCountLimit: Int
def rangeCoalescingThreshold: Long
def decodeMaxBytesPerChunk: Int
def fileIODispatcher: String
/* Java APIs */
def getVerboseErrorMessages: Boolean = verboseErrorMessages
def getFileGetConditional: Boolean = fileGetConditional
def getRenderVanityFooter: Boolean = renderVanityFooter
def getRangeCountLimit: Int = rangeCountLimit
def getRangeCoalescingThreshold: Long = rangeCoalescingThreshold
def getDecodeMaxBytesPerChunk: Int = decodeMaxBytesPerChunk
def getFileIODispatcher: String = fileIODispatcher
override def withVerboseErrorMessages(verboseErrorMessages: Boolean): RoutingSettings = self.copy(verboseErrorMessages = verboseErrorMessages)
override def withFileGetConditional(fileGetConditional: Boolean): RoutingSettings = self.copy(fileGetConditional = fileGetConditional)
override def withRenderVanityFooter(renderVanityFooter: Boolean): RoutingSettings = self.copy(renderVanityFooter = renderVanityFooter)
override def withRangeCountLimit(rangeCountLimit: Int): RoutingSettings = self.copy(rangeCountLimit = rangeCountLimit)
override def withRangeCoalescingThreshold(rangeCoalescingThreshold: Long): RoutingSettings = self.copy(rangeCoalescingThreshold = rangeCoalescingThreshold)
override def withDecodeMaxBytesPerChunk(decodeMaxBytesPerChunk: Int): RoutingSettings = self.copy(decodeMaxBytesPerChunk = decodeMaxBytesPerChunk)
override def withFileIODispatcher(fileIODispatcher: String): RoutingSettings = self.copy(fileIODispatcher = fileIODispatcher)
}
object RoutingSettings extends SettingsCompanion[RoutingSettings] {
override def apply(config: Config): RoutingSettings = RoutingSettingsImpl(config)
override def apply(configOverrides: String): RoutingSettings = RoutingSettingsImpl(configOverrides)
}

View file

@ -20,7 +20,10 @@ import scala.compat.java8.OptionConverters
import scala.concurrent.duration.{ FiniteDuration, Duration }
import scala.language.implicitConversions
abstract class ServerSettings extends akka.http.javadsl.settings.ServerSettings {
/**
* Public API but not intended for subclassing
*/
abstract class ServerSettings private[akka] () extends akka.http.javadsl.settings.ServerSettings { self: ServerSettingsImpl
def serverHeader: Option[Server]
def timeouts: ServerSettings.Timeouts
def maxConnections: Int