diff options
Diffstat (limited to 'test/disabled/presentation/akka/src/akka/config')
6 files changed, 0 insertions, 552 deletions
diff --git a/test/disabled/presentation/akka/src/akka/config/Config.scala b/test/disabled/presentation/akka/src/akka/config/Config.scala deleted file mode 100644 index 6578c66f77..0000000000 --- a/test/disabled/presentation/akka/src/akka/config/Config.scala +++ /dev/null @@ -1,93 +0,0 @@ -/** - * Copyright (C) 2009-2011 Scalable Solutions AB <http://scalablesolutions.se> - */ - -package akka.config - -import akka.AkkaException - -class ConfigurationException(message: String, cause: Throwable = null) extends AkkaException(message, cause) -class ModuleNotAvailableException(message: String, cause: Throwable = null) extends AkkaException(message, cause) - -/** - * Loads up the configuration (from the akka.conf file). - * - * @author <a href="http://jonasboner.com">Jonas Bonér</a> - */ -object Config { - val VERSION = "1.1.3" - - val HOME = { - val envHome = System.getenv("AKKA_HOME") match { - case null | "" | "." => None - case value => Some(value) - } - - val systemHome = System.getProperty("akka.home") match { - case null | "" => None - case value => Some(value) - } - - envHome orElse systemHome - } - - val config: Configuration = try { - val confName = { - val envConf = System.getenv("AKKA_MODE") match { - case null | "" => None - case value => Some(value) - } - - val systemConf = System.getProperty("akka.mode") match { - case null | "" => None - case value => Some(value) - } - - (envConf orElse systemConf).map("akka." + _ + ".conf").getOrElse("akka.conf") - } - - val newInstance = - if (System.getProperty("akka.config", "") != "") { - val configFile = System.getProperty("akka.config", "") - println("Loading config from -Dakka.config=" + configFile) - Configuration.fromFile(configFile) - } else if (getClass.getClassLoader.getResource(confName) ne null) { - println("Loading config [" + confName + "] from the application classpath.") - Configuration.fromResource(confName, getClass.getClassLoader) - } else if (HOME.isDefined) { - val configFile = HOME.get + "/config/" + confName - println("AKKA_HOME is defined as [" + HOME.get + "], loading config from [" + configFile + "].") - Configuration.fromFile(configFile) - } else { - println( - "\nCan't load '" + confName + "'." + - "\nOne of the three ways of locating the '" + confName + "' file needs to be defined:" + - "\n\t1. Define the '-Dakka.config=...' system property option." + - "\n\t2. Put the '" + confName + "' file on the classpath." + - "\n\t3. Define 'AKKA_HOME' environment variable pointing to the root of the Akka distribution." + - "\nI have no way of finding the '" + confName + "' configuration file." + - "\nUsing default values everywhere.") - Configuration.fromString("akka {}") // default empty config - } - - val configVersion = newInstance.getString("akka.version", VERSION) - if (configVersion != VERSION) - throw new ConfigurationException( - "Akka JAR version [" + VERSION + "] is different than the provided config version [" + configVersion + "]") - - newInstance - } catch { - case e => - System.err.println("Couldn't parse config, fatal error.") - e.printStackTrace(System.err) - System.exit(-1) - throw e - } - - val CONFIG_VERSION = config.getString("akka.version", VERSION) - - val TIME_UNIT = config.getString("akka.time-unit", "seconds") - - val startTime = System.currentTimeMillis - def uptime = (System.currentTimeMillis - startTime) / 1000 -} diff --git a/test/disabled/presentation/akka/src/akka/config/ConfigParser.scala b/test/disabled/presentation/akka/src/akka/config/ConfigParser.scala deleted file mode 100644 index 73fac5e31b..0000000000 --- a/test/disabled/presentation/akka/src/akka/config/ConfigParser.scala +++ /dev/null @@ -1,74 +0,0 @@ -/** - * Copyright (C) 2009-2011 Scalable Solutions AB <http://scalablesolutions.se> - * - * Based on Configgy by Robey Pointer. - * Copyright 2009 Robey Pointer <robeypointer@gmail.com> - * http://www.apache.org/licenses/LICENSE-2.0 - */ - -package akka.config - -import scala.collection.mutable -import scala.util.parsing.combinator._ - -class ConfigParser(var prefix: String = "", map: mutable.Map[String, Any] = mutable.Map.empty[String, Any], importer: Importer) extends RegexParsers { - val sections = mutable.Stack[String]() - - def createPrefix = { - prefix = if (sections.isEmpty) "" else sections.toList.reverse.mkString("", ".", ".") - } - - override val whiteSpace = """(\s+|#[^\n]*\n)+""".r - - // tokens - - val numberToken: Parser[String] = """-?\d+(\.\d+)?""".r - val stringToken: Parser[String] = ("\"" + """([^\\\"]|\\[^ux]|\\\n|\\u[0-9a-fA-F]{4}|\\x[0-9a-fA-F]{2})*""" + "\"").r - val booleanToken: Parser[String] = "(true|on|false|off)".r - val identToken: Parser[String] = """([\da-zA-Z_][-\w]*)(\.[a-zA-Z_][-\w]*)*""".r - val assignToken: Parser[String] = "=".r - val sectionToken: Parser[String] = """[a-zA-Z][-\w]*""".r - - // values - - def value: Parser[Any] = number | string | list | boolean - def number = numberToken - def string = stringToken ^^ { s => s.substring(1, s.length - 1) } - def list = "[" ~> repsep(string | numberToken, opt(",")) <~ (opt(",") ~ "]") - def boolean = booleanToken - - // parser - - def root = rep(includeFile | assignment | sectionOpen | sectionClose) - - def includeFile = "include" ~> string ^^ { - case filename: String => - new ConfigParser(prefix, map, importer) parse importer.importFile(filename) - } - - def assignment = identToken ~ assignToken ~ value ^^ { - case k ~ a ~ v => map(prefix + k) = v - } - - def sectionOpen = sectionToken <~ "{" ^^ { name => - sections push name - createPrefix - } - - def sectionClose = "}" ^^ { _ => - if (sections.isEmpty) { - failure("dangling close tag") - } else { - sections.pop - createPrefix - } - } - - def parse(in: String): Map[String, Any] = { - parseAll(root, in) match { - case Success(result, _) => map.toMap - case x@Failure(msg, _) => throw new ConfigurationException(x.toString) - case x@Error(msg, _) => throw new ConfigurationException(x.toString) - } - } -} diff --git a/test/disabled/presentation/akka/src/akka/config/Configuration.scala b/test/disabled/presentation/akka/src/akka/config/Configuration.scala deleted file mode 100644 index 81c32fce90..0000000000 --- a/test/disabled/presentation/akka/src/akka/config/Configuration.scala +++ /dev/null @@ -1,166 +0,0 @@ -/** - * Copyright (C) 2009-2011 Scalable Solutions AB <http://scalablesolutions.se> - * - * Based on Configgy by Robey Pointer. - * Copyright 2009 Robey Pointer <robeypointer@gmail.com> - * http://www.apache.org/licenses/LICENSE-2.0 - */ - -package akka.config - -import java.io.File - -object Configuration { - val DefaultPath = new File(".").getCanonicalPath - val DefaultImporter = new FilesystemImporter(DefaultPath) - - def load(data: String, importer: Importer = DefaultImporter): Configuration = { - val parser = new ConfigParser(importer = importer) - new Configuration(parser parse data) - } - - def fromFile(filename: String, importer: Importer): Configuration = { - load(importer.importFile(filename), importer) - } - - def fromFile(path: String, filename: String): Configuration = { - val importer = new FilesystemImporter(path) - fromFile(filename, importer) - } - - def fromFile(filename: String): Configuration = { - val n = filename.lastIndexOf('/') - if (n < 0) { - fromFile(DefaultPath, filename) - } else { - fromFile(filename.substring(0, n), filename.substring(n + 1)) - } - } - - def fromResource(filename: String): Configuration = { - fromResource(filename, ClassLoader.getSystemClassLoader) - } - - def fromResource(filename: String, classLoader: ClassLoader): Configuration = { - val importer = new ResourceImporter(classLoader) - fromFile(filename, importer) - } - - def fromMap(map: Map[String, Any]) = { - new Configuration(map) - } - - def fromString(data: String): Configuration = { - load(data) - } -} - -class Configuration(val map: Map[String, Any]) { - private val trueValues = Set("true", "on") - private val falseValues = Set("false", "off") - - def contains(key: String): Boolean = map contains key - - def keys: Iterable[String] = map.keys - - def getAny(key: String): Option[Any] = { - try { - Some(map(key)) - } catch { - case _ => None - } - } - - def getAny(key: String, defaultValue: Any): Any = getAny(key).getOrElse(defaultValue) - - def getSeqAny(key: String): Seq[Any] = { - try { - map(key).asInstanceOf[Seq[Any]] - } catch { - case _ => Seq.empty[Any] - } - } - - def getString(key: String): Option[String] = map.get(key).map(_.toString) - - def getString(key: String, defaultValue: String): String = getString(key).getOrElse(defaultValue) - - def getList(key: String): Seq[String] = { - try { - map(key).asInstanceOf[Seq[String]] - } catch { - case _ => Seq.empty[String] - } - } - - def getInt(key: String): Option[Int] = { - try { - Some(map(key).toString.toInt) - } catch { - case _ => None - } - } - - def getInt(key: String, defaultValue: Int): Int = getInt(key).getOrElse(defaultValue) - - def getLong(key: String): Option[Long] = { - try { - Some(map(key).toString.toLong) - } catch { - case _ => None - } - } - - def getLong(key: String, defaultValue: Long): Long = getLong(key).getOrElse(defaultValue) - - def getFloat(key: String): Option[Float] = { - try { - Some(map(key).toString.toFloat) - } catch { - case _ => None - } - } - - def getFloat(key: String, defaultValue: Float): Float = getFloat(key).getOrElse(defaultValue) - - def getDouble(key: String): Option[Double] = { - try { - Some(map(key).toString.toDouble) - } catch { - case _ => None - } - } - - def getDouble(key: String, defaultValue: Double): Double = getDouble(key).getOrElse(defaultValue) - - def getBoolean(key: String): Option[Boolean] = { - getString(key) flatMap { s => - val isTrue = trueValues.contains(s) - if (!isTrue && !falseValues.contains(s)) None - else Some(isTrue) - } - } - - def getBoolean(key: String, defaultValue: Boolean): Boolean = getBool(key).getOrElse(defaultValue) - - def getBool(key: String): Option[Boolean] = getBoolean(key) - - def getBool(key: String, defaultValue: Boolean): Boolean = getBoolean(key, defaultValue) - - def apply(key: String): String = getString(key) match { - case None => throw new ConfigurationException("undefined config: " + key) - case Some(v) => v - } - - def apply(key: String, defaultValue: String) = getString(key, defaultValue) - def apply(key: String, defaultValue: Int) = getInt(key, defaultValue) - def apply(key: String, defaultValue: Long) = getLong(key, defaultValue) - def apply(key: String, defaultValue: Boolean) = getBool(key, defaultValue) - - def getSection(name: String): Option[Configuration] = { - val l = name.length + 1 - val m = map.collect { case (k, v) if k.startsWith(name) => (k.substring(l), v) } - if (m.isEmpty) None - else Some(new Configuration(m)) - } -} diff --git a/test/disabled/presentation/akka/src/akka/config/Configurator.scala b/test/disabled/presentation/akka/src/akka/config/Configurator.scala deleted file mode 100644 index 2818339b0f..0000000000 --- a/test/disabled/presentation/akka/src/akka/config/Configurator.scala +++ /dev/null @@ -1,21 +0,0 @@ -/** - * Copyright (C) 2009-2011 Scalable Solutions AB <http://scalablesolutions.se> - */ - -package akka.config - -import akka.config.Supervision.{ SuperviseTypedActor, FaultHandlingStrategy } - -private[akka] trait TypedActorConfiguratorBase { - def getExternalDependency[T](clazz: Class[T]): T - - def configure(restartStrategy: FaultHandlingStrategy, components: List[SuperviseTypedActor]): TypedActorConfiguratorBase - - def inject: TypedActorConfiguratorBase - - def supervise: TypedActorConfiguratorBase - - def reset - - def stop -} diff --git a/test/disabled/presentation/akka/src/akka/config/Importer.scala b/test/disabled/presentation/akka/src/akka/config/Importer.scala deleted file mode 100644 index eebda1d4fe..0000000000 --- a/test/disabled/presentation/akka/src/akka/config/Importer.scala +++ /dev/null @@ -1,64 +0,0 @@ -/** - * Copyright (C) 2009-2011 Scalable Solutions AB <http://scalablesolutions.se> - * - * Based on Configgy by Robey Pointer. - * Copyright 2009 Robey Pointer <robeypointer@gmail.com> - * http://www.apache.org/licenses/LICENSE-2.0 - */ - -package akka.config - -import java.io.{ BufferedReader, File, FileInputStream, InputStream, InputStreamReader } - -/** - * An interface for finding config files and reading them into strings for - * parsing. This is used to handle `include` directives in config files. - */ -trait Importer { - - def importFile(filename: String): String - - private val BUFFER_SIZE = 8192 - - protected def streamToString(in: InputStream): String = { - try { - val reader = new BufferedReader(new InputStreamReader(in, "UTF-8")) - val buffer = new Array[Char](BUFFER_SIZE) - val sb = new StringBuilder - var n = 0 - while (n >= 0) { - n = reader.read(buffer, 0, buffer.length) - if (n >= 0) { - sb.appendAll(buffer, 0, n) - } - } - in.close() - sb.toString - } catch { - case x => throw new ConfigurationException(x.toString) - } - } -} - -/** - * An Importer that looks for imported config files in the filesystem. - * This is the default importer. - */ -class FilesystemImporter(val baseDir: String) extends Importer { - def importFile(filename: String): String = { - val f = new File(filename) - val file = if (f.isAbsolute) f else new File(baseDir, filename) - streamToString(new FileInputStream(file)) - } -} - -/** - * An Importer that looks for imported config files in the java resources - * of the system class loader (usually the jar used to launch this app). - */ -class ResourceImporter(classLoader: ClassLoader) extends Importer { - def importFile(filename: String): String = { - val stream = classLoader.getResourceAsStream(filename) - streamToString(stream) - } -} diff --git a/test/disabled/presentation/akka/src/akka/config/SupervisionConfig.scala b/test/disabled/presentation/akka/src/akka/config/SupervisionConfig.scala deleted file mode 100644 index 40f61f615f..0000000000 --- a/test/disabled/presentation/akka/src/akka/config/SupervisionConfig.scala +++ /dev/null @@ -1,134 +0,0 @@ -/** - * Copyright (C) 2009-2011 Scalable Solutions AB <http://scalablesolutions.se> - */ - -package akka.config - -import akka.dispatch.MessageDispatcher -import akka.actor.{ MaximumNumberOfRestartsWithinTimeRangeReached, ActorRef } -import akka.japi.{ Procedure2, Procedure } - -case class RemoteAddress(val hostname: String, val port: Int) - -/** - * Configuration classes - not to be used as messages. - * - * @author <a href="http://jonasboner.com">Jonas Bonér</a> - */ -object Supervision { - sealed abstract class ConfigElement - - abstract class Server extends ConfigElement - sealed abstract class LifeCycle extends ConfigElement - sealed abstract class FaultHandlingStrategy(val trapExit: List[Class[_ <: Throwable]]) extends ConfigElement - - case class SupervisorConfig(restartStrategy: FaultHandlingStrategy, worker: List[Server], maxRestartsHandler: (ActorRef, MaximumNumberOfRestartsWithinTimeRangeReached) => Unit = { (aRef, max) => () }) extends Server { - //Java API - def this(restartStrategy: FaultHandlingStrategy, worker: Array[Server]) = this(restartStrategy, worker.toList) - def this(restartStrategy: FaultHandlingStrategy, worker: Array[Server], restartHandler: Procedure2[ActorRef, MaximumNumberOfRestartsWithinTimeRangeReached]) = this(restartStrategy, worker.toList, { (aRef, max) => restartHandler.apply(aRef, max) }) - } - - class Supervise(val actorRef: ActorRef, val lifeCycle: LifeCycle, val registerAsRemoteService: Boolean = false) extends Server { - //Java API - def this(actorRef: ActorRef, lifeCycle: LifeCycle) = - this(actorRef, lifeCycle, false) - } - - object Supervise { - def apply(actorRef: ActorRef, lifeCycle: LifeCycle, registerAsRemoteService: Boolean = false) = new Supervise(actorRef, lifeCycle, registerAsRemoteService) - def apply(actorRef: ActorRef, lifeCycle: LifeCycle) = new Supervise(actorRef, lifeCycle, false) - def unapply(supervise: Supervise) = Some((supervise.actorRef, supervise.lifeCycle, supervise.registerAsRemoteService)) - } - - object AllForOneStrategy { - def apply(trapExit: List[Class[_ <: Throwable]], maxNrOfRetries: Int, withinTimeRange: Int): AllForOneStrategy = - new AllForOneStrategy(trapExit, - if (maxNrOfRetries < 0) None else Some(maxNrOfRetries), if (withinTimeRange < 0) None else Some(withinTimeRange)) - } - - case class AllForOneStrategy(override val trapExit: List[Class[_ <: Throwable]], - maxNrOfRetries: Option[Int] = None, - withinTimeRange: Option[Int] = None) extends FaultHandlingStrategy(trapExit) { - def this(trapExit: List[Class[_ <: Throwable]], maxNrOfRetries: Int, withinTimeRange: Int) = - this(trapExit, - if (maxNrOfRetries < 0) None else Some(maxNrOfRetries), if (withinTimeRange < 0) None else Some(withinTimeRange)) - - def this(trapExit: Array[Class[_ <: Throwable]], maxNrOfRetries: Int, withinTimeRange: Int) = - this(trapExit.toList, - if (maxNrOfRetries < 0) None else Some(maxNrOfRetries), if (withinTimeRange < 0) None else Some(withinTimeRange)) - - def this(trapExit: java.util.List[Class[_ <: Throwable]], maxNrOfRetries: Int, withinTimeRange: Int) = - this(trapExit.toArray.toList.asInstanceOf[List[Class[_ <: Throwable]]], - if (maxNrOfRetries < 0) None else Some(maxNrOfRetries), if (withinTimeRange < 0) None else Some(withinTimeRange)) - } - - object OneForOneStrategy { - def apply(trapExit: List[Class[_ <: Throwable]], maxNrOfRetries: Int, withinTimeRange: Int): OneForOneStrategy = - new OneForOneStrategy(trapExit, - if (maxNrOfRetries < 0) None else Some(maxNrOfRetries), if (withinTimeRange < 0) None else Some(withinTimeRange)) - } - - case class OneForOneStrategy(override val trapExit: List[Class[_ <: Throwable]], - maxNrOfRetries: Option[Int] = None, - withinTimeRange: Option[Int] = None) extends FaultHandlingStrategy(trapExit) { - def this(trapExit: List[Class[_ <: Throwable]], maxNrOfRetries: Int, withinTimeRange: Int) = - this(trapExit, - if (maxNrOfRetries < 0) None else Some(maxNrOfRetries), if (withinTimeRange < 0) None else Some(withinTimeRange)) - - def this(trapExit: Array[Class[_ <: Throwable]], maxNrOfRetries: Int, withinTimeRange: Int) = - this(trapExit.toList, - if (maxNrOfRetries < 0) None else Some(maxNrOfRetries), if (withinTimeRange < 0) None else Some(withinTimeRange)) - - def this(trapExit: java.util.List[Class[_ <: Throwable]], maxNrOfRetries: Int, withinTimeRange: Int) = - this(trapExit.toArray.toList.asInstanceOf[List[Class[_ <: Throwable]]], - if (maxNrOfRetries < 0) None else Some(maxNrOfRetries), if (withinTimeRange < 0) None else Some(withinTimeRange)) - } - - case object NoFaultHandlingStrategy extends FaultHandlingStrategy(Nil) - - //Scala API - case object Permanent extends LifeCycle - case object Temporary extends LifeCycle - case object UndefinedLifeCycle extends LifeCycle - - //Java API (& Scala if you fancy) - def permanent(): LifeCycle = Permanent - def temporary(): LifeCycle = Temporary - def undefinedLifeCycle(): LifeCycle = UndefinedLifeCycle - - //Java API - def noFaultHandlingStrategy = NoFaultHandlingStrategy - - case class SuperviseTypedActor(_intf: Class[_], - val target: Class[_], - val lifeCycle: LifeCycle, - val timeout: Long, - _dispatcher: MessageDispatcher, // optional - _remoteAddress: RemoteAddress // optional - ) extends Server { - val intf: Option[Class[_]] = Option(_intf) - val dispatcher: Option[MessageDispatcher] = Option(_dispatcher) - val remoteAddress: Option[RemoteAddress] = Option(_remoteAddress) - - def this(target: Class[_], lifeCycle: LifeCycle, timeout: Long) = - this(null: Class[_], target, lifeCycle, timeout, null: MessageDispatcher, null: RemoteAddress) - - def this(intf: Class[_], target: Class[_], lifeCycle: LifeCycle, timeout: Long) = - this(intf, target, lifeCycle, timeout, null: MessageDispatcher, null: RemoteAddress) - - def this(intf: Class[_], target: Class[_], lifeCycle: LifeCycle, timeout: Long, dispatcher: MessageDispatcher) = - this(intf, target, lifeCycle, timeout, dispatcher, null: RemoteAddress) - - def this(target: Class[_], lifeCycle: LifeCycle, timeout: Long, dispatcher: MessageDispatcher) = - this(null: Class[_], target, lifeCycle, timeout, dispatcher, null: RemoteAddress) - - def this(intf: Class[_], target: Class[_], lifeCycle: LifeCycle, timeout: Long, remoteAddress: RemoteAddress) = - this(intf, target, lifeCycle, timeout, null: MessageDispatcher, remoteAddress) - - def this(target: Class[_], lifeCycle: LifeCycle, timeout: Long, remoteAddress: RemoteAddress) = - this(null: Class[_], target, lifeCycle, timeout, null: MessageDispatcher, remoteAddress) - - def this(target: Class[_], lifeCycle: LifeCycle, timeout: Long, dispatcher: MessageDispatcher, remoteAddress: RemoteAddress) = - this(null: Class[_], target, lifeCycle, timeout, dispatcher, remoteAddress) - } -} |