summaryrefslogtreecommitdiff
path: root/test/disabled/presentation/akka/src/akka/util
diff options
context:
space:
mode:
Diffstat (limited to 'test/disabled/presentation/akka/src/akka/util')
-rw-r--r--test/disabled/presentation/akka/src/akka/util/Address.scala29
-rw-r--r--test/disabled/presentation/akka/src/akka/util/AkkaLoader.scala94
-rw-r--r--test/disabled/presentation/akka/src/akka/util/Bootable.scala10
-rw-r--r--test/disabled/presentation/akka/src/akka/util/BoundedBlockingQueue.scala326
-rw-r--r--test/disabled/presentation/akka/src/akka/util/Crypt.scala44
-rw-r--r--test/disabled/presentation/akka/src/akka/util/Duration.scala437
-rw-r--r--test/disabled/presentation/akka/src/akka/util/HashCode.scala57
-rw-r--r--test/disabled/presentation/akka/src/akka/util/Helpers.scala99
-rw-r--r--test/disabled/presentation/akka/src/akka/util/ListenerManagement.scala81
-rw-r--r--test/disabled/presentation/akka/src/akka/util/LockUtil.scala197
-rw-r--r--test/disabled/presentation/akka/src/akka/util/ReflectiveAccess.scala232
-rw-r--r--test/disabled/presentation/akka/src/akka/util/package.scala27
12 files changed, 0 insertions, 1633 deletions
diff --git a/test/disabled/presentation/akka/src/akka/util/Address.scala b/test/disabled/presentation/akka/src/akka/util/Address.scala
deleted file mode 100644
index 65b5c0a834..0000000000
--- a/test/disabled/presentation/akka/src/akka/util/Address.scala
+++ /dev/null
@@ -1,29 +0,0 @@
-/**
- * Copyright (C) 2009-2011 Scalable Solutions AB <http://scalablesolutions.se>
- */
-package akka.util
-
-import java.net.InetSocketAddress
-
-object Address {
- def apply(hostname: String, port: Int) = new Address(hostname, port)
- def apply(inetAddress: InetSocketAddress): Address = inetAddress match {
- case null => null
- case inet => new Address(inet.getAddress.getHostAddress, inet.getPort)
- }
-}
-
-class Address(val hostname: String, val port: Int) {
- override val hashCode: Int = {
- var result = HashCode.SEED
- result = HashCode.hash(result, hostname)
- result = HashCode.hash(result, port)
- result
- }
-
- override def equals(that: Any): Boolean = {
- that.isInstanceOf[Address] &&
- that.asInstanceOf[Address].hostname == hostname &&
- that.asInstanceOf[Address].port == port
- }
-}
diff --git a/test/disabled/presentation/akka/src/akka/util/AkkaLoader.scala b/test/disabled/presentation/akka/src/akka/util/AkkaLoader.scala
deleted file mode 100644
index cb246f2ecf..0000000000
--- a/test/disabled/presentation/akka/src/akka/util/AkkaLoader.scala
+++ /dev/null
@@ -1,94 +0,0 @@
-/**
- * Copyright (C) 2009-2011 Scalable Solutions AB <http://scalablesolutions.se>
- */
-
-package akka.util
-
-import akka.config.Config
-import akka.actor.Actor
-
-/*
- * This class is responsible for booting up a stack of bundles and then shutting them down
- */
-class AkkaLoader {
- private val hasBooted = new Switch(false)
-
- @volatile
- private var _bundles: Option[Bootable] = None
-
- def bundles = _bundles;
-
- /*
- * Boot initializes the specified bundles
- */
- def boot(withBanner: Boolean, b: Bootable): Unit = hasBooted switchOn {
- if (withBanner) printBanner()
- println("Starting Akka...")
- b.onLoad
- Thread.currentThread.setContextClassLoader(getClass.getClassLoader)
- _bundles = Some(b)
- println("Akka started successfully")
- }
-
- /*
- * Shutdown, well, shuts down the bundles used in boot
- */
- def shutdown() {
- hasBooted switchOff {
- println("Shutting down Akka...")
- _bundles.foreach(_.onUnload)
- _bundles = None
- Actor.shutdownHook.run
- println("Akka succesfully shut down")
- }
- }
-
- private def printBanner() {
- println("""
-==============================================================================
-
- ZZ:
- ZZZZ
- ZZZZZZ
- ZZZ' ZZZ
- ~7 7ZZ' ZZZ
- :ZZZ: IZZ' ZZZ
- ,OZZZZ.~ZZ? ZZZ
- ZZZZ' 'ZZZ$ ZZZ
- . $ZZZ ~ZZ$ ZZZ
- .=Z?. .ZZZO ~ZZ7 OZZ
- .ZZZZ7..:ZZZ~ 7ZZZ ZZZ~
- .$ZZZ$Z+.ZZZZ ZZZ: ZZZ$
- .,ZZZZ?' =ZZO= .OZZ 'ZZZ
- .$ZZZZ+ .ZZZZ IZZZ ZZZ$
- .ZZZZZ' .ZZZZ' .ZZZ$ ?ZZZ
- .ZZZZZZ' .OZZZ? ?ZZZ 'ZZZ$
- .?ZZZZZZ' .ZZZZ? .ZZZ? 'ZZZO
- .+ZZZZZZ?' .7ZZZZ' .ZZZZ :ZZZZ
- .ZZZZZZ$' .?ZZZZZ' .~ZZZZ 'ZZZZ.
-
-
- NNNNN $NNNN+
- NNNNN $NNNN+
- NNNNN $NNNN+
- NNNNN $NNNN+
- NNNNN $NNNN+
- =NNNNNNNNND$ NNNNN DDDDDD: $NNNN+ DDDDDN NDDNNNNNNNN,
- NNNNNNNNNNNNND NNNNN DNNNNN $NNNN+ 8NNNNN= :NNNNNNNNNNNNNN
- NNNNN$ DNNNNN NNNNN $NNNNN~ $NNNN+ NNNNNN NNNNN, :NNNNN+
- ?DN~ NNNNN NNNNN MNNNNN $NNNN+:NNNNN7 $ND =NNNNN
- DNNNNN NNNNNDNNNN$ $NNNNDNNNNN :DNNNNN
- ZNDNNNNNNNNND NNNNNNNNNND, $NNNNNNNNNNN DNDNNNNNNNNNN
- NNNNNNNDDINNNNN NNNNNNNNNNND $NNNNNNNNNNND ONNNNNNND8+NNNNN
- :NNNND NNNNN NNNNNN DNNNN, $NNNNNO 7NNNND NNNNNO :NNNNN
- DNNNN NNNNN NNNNN DNNNN $NNNN+ 8NNNNN NNNNN $NNNNN
- DNNNNO NNNNNN NNNNN NNNNN $NNNN+ NNNNN$ NNNND, ,NNNNND
- NNNNNNDDNNNNNNNN NNNNN =NNNNN $NNNN+ DNNNN? DNNNNNNDNNNNNNNND
- NNNNNNNNN NNNN$ NNNNN 8NNNND $NNNN+ NNNNN= ,DNNNNNNND NNNNN$
-
-==============================================================================
- Running version %s
-==============================================================================
-""".format(Config.VERSION))
- }
-}
diff --git a/test/disabled/presentation/akka/src/akka/util/Bootable.scala b/test/disabled/presentation/akka/src/akka/util/Bootable.scala
deleted file mode 100644
index d07643e1ac..0000000000
--- a/test/disabled/presentation/akka/src/akka/util/Bootable.scala
+++ /dev/null
@@ -1,10 +0,0 @@
-/**
- * Copyright (C) 2009-2011 Scalable Solutions AB <http://scalablesolutions.se>
- */
-
-package akka.util
-
-trait Bootable {
- def onLoad() {}
- def onUnload() {}
-}
diff --git a/test/disabled/presentation/akka/src/akka/util/BoundedBlockingQueue.scala b/test/disabled/presentation/akka/src/akka/util/BoundedBlockingQueue.scala
deleted file mode 100644
index f8deda746c..0000000000
--- a/test/disabled/presentation/akka/src/akka/util/BoundedBlockingQueue.scala
+++ /dev/null
@@ -1,326 +0,0 @@
-/**
- * Copyright (C) 2009-2011 Scalable Solutions AB <http://scalablesolutions.se>
- */
-
-package akka.util
-
-import java.util.concurrent.locks.ReentrantLock
-import java.util.concurrent.{ TimeUnit, BlockingQueue }
-import java.util.{ AbstractQueue, Queue, Collection, Iterator }
-
-class BoundedBlockingQueue[E <: AnyRef](
- val maxCapacity: Int, private val backing: Queue[E]) extends AbstractQueue[E] with BlockingQueue[E] {
-
- backing match {
- case null => throw new IllegalArgumentException("Backing Queue may not be null")
- case b: BlockingQueue[_] =>
- require(maxCapacity > 0)
- require(b.size() == 0)
- require(b.remainingCapacity >= maxCapacity)
- case b: Queue[_] =>
- require(b.size() == 0)
- require(maxCapacity > 0)
- }
-
- protected val lock = new ReentrantLock(false)
-
- private val notEmpty = lock.newCondition()
- private val notFull = lock.newCondition()
-
- def put(e: E): Unit = { //Blocks until not full
- if (e eq null) throw new NullPointerException
- lock.lock()
- try {
- while (backing.size() == maxCapacity)
- notFull.await()
- require(backing.offer(e))
- notEmpty.signal()
- } finally {
- lock.unlock()
- }
- }
-
- def take(): E = { //Blocks until not empty
- lock.lockInterruptibly()
- try {
- while (backing.size() == 0)
- notEmpty.await()
- val e = backing.poll()
- require(e ne null)
- notFull.signal()
- e
- } finally {
- lock.unlock()
- }
- }
-
- def offer(e: E): Boolean = { //Tries to do it immediately, if fail return false
- if (e eq null) throw new NullPointerException
- lock.lock()
- try {
- if (backing.size() == maxCapacity) false
- else {
- require(backing.offer(e)) //Should never fail
- notEmpty.signal()
- true
- }
- } finally {
- lock.unlock()
- }
- }
-
- def offer(e: E, timeout: Long, unit: TimeUnit): Boolean = { //Tries to do it within the timeout, return false if fail
- if (e eq null) throw new NullPointerException
- var nanos = unit.toNanos(timeout)
- lock.lockInterruptibly()
- try {
- while (backing.size() == maxCapacity) {
- if (nanos <= 0)
- return false
- else
- nanos = notFull.awaitNanos(nanos)
- }
- require(backing.offer(e)) //Should never fail
- notEmpty.signal()
- true
- } finally {
- lock.unlock()
- }
- }
-
- def poll(timeout: Long, unit: TimeUnit): E = { //Tries to do it within the timeout, returns null if fail
- var nanos = unit.toNanos(timeout)
- lock.lockInterruptibly()
- try {
- var result: E = null.asInstanceOf[E]
- var hasResult = false
- while (!hasResult) {
- hasResult = backing.poll() match {
- case null if nanos <= 0 =>
- result = null.asInstanceOf[E]
- true
- case null =>
- try {
- nanos = notEmpty.awaitNanos(nanos)
- } catch {
- case ie: InterruptedException =>
- notEmpty.signal()
- throw ie
- }
- false
- case e =>
- notFull.signal()
- result = e
- true
- }
- }
- result
- } finally {
- lock.unlock()
- }
- }
-
- def poll(): E = { //Tries to remove the head of the queue immediately, if fail, return null
- lock.lock()
- try {
- backing.poll() match {
- case null => null.asInstanceOf[E]
- case e =>
- notFull.signal()
- e
- }
- } finally {
- lock.unlock
- }
- }
-
- override def remove(e: AnyRef): Boolean = { //Tries to do it immediately, if fail, return false
- if (e eq null) throw new NullPointerException
- lock.lock()
- try {
- if (backing remove e) {
- notFull.signal()
- true
- } else false
- } finally {
- lock.unlock()
- }
- }
-
- override def contains(e: AnyRef): Boolean = {
- if (e eq null) throw new NullPointerException
- lock.lock()
- try {
- backing contains e
- } finally {
- lock.unlock()
- }
- }
-
- override def clear(): Unit = {
- lock.lock()
- try {
- backing.clear
- } finally {
- lock.unlock()
- }
- }
-
- def remainingCapacity(): Int = {
- lock.lock()
- try {
- maxCapacity - backing.size()
- } finally {
- lock.unlock()
- }
- }
-
- def size(): Int = {
- lock.lock()
- try {
- backing.size()
- } finally {
- lock.unlock()
- }
- }
-
- def peek(): E = {
- lock.lock()
- try {
- backing.peek()
- } finally {
- lock.unlock()
- }
- }
-
- def drainTo(c: Collection[_ >: E]): Int = drainTo(c, Int.MaxValue)
-
- def drainTo(c: Collection[_ >: E], maxElements: Int): Int = {
- if (c eq null) throw new NullPointerException
- if (c eq this) throw new IllegalArgumentException
- if (maxElements <= 0) 0
- else {
- lock.lock()
- try {
- var n = 0
- var e: E = null.asInstanceOf[E]
- while (n < maxElements) {
- backing.poll() match {
- case null => return n
- case e =>
- c add e
- n += 1
- }
- }
- n
- } finally {
- lock.unlock()
- }
- }
- }
-
- override def containsAll(c: Collection[_]): Boolean = {
- lock.lock()
- try {
- backing containsAll c
- } finally {
- lock.unlock()
- }
- }
-
- override def removeAll(c: Collection[_]): Boolean = {
- lock.lock()
- try {
- if (backing.removeAll(c)) {
- val sz = backing.size()
- if (sz < maxCapacity) notFull.signal()
- if (sz > 0) notEmpty.signal() //FIXME needed?
- true
- } else false
- } finally {
- lock.unlock()
- }
- }
-
- override def retainAll(c: Collection[_]): Boolean = {
- lock.lock()
- try {
- if (backing.retainAll(c)) {
- val sz = backing.size()
- if (sz < maxCapacity) notFull.signal() //FIXME needed?
- if (sz > 0) notEmpty.signal()
- true
- } else false
- } finally {
- lock.unlock()
- }
- }
-
- def iterator(): Iterator[E] = {
- lock.lock
- try {
- val elements = backing.toArray
- new Iterator[E] {
- var at = 0
- var last = -1
-
- def hasNext(): Boolean = at < elements.length
-
- def next(): E = {
- if (at >= elements.length) throw new NoSuchElementException
- last = at
- at += 1
- elements(last).asInstanceOf[E]
- }
-
- def remove(): Unit = {
- if (last < 0) throw new IllegalStateException
- val target = elements(last)
- last = -1 //To avoid 2 subsequent removes without a next in between
- lock.lock()
- try {
- val i = backing.iterator()
- while (i.hasNext) {
- if (i.next eq target) {
- i.remove()
- notFull.signal()
- return ()
- }
- }
- } finally {
- lock.unlock()
- }
- }
- }
- } finally {
- lock.unlock
- }
- }
-
- override def toArray(): Array[AnyRef] = {
- lock.lock()
- try {
- backing.toArray
- } finally {
- lock.unlock()
- }
- }
-
- override def isEmpty(): Boolean = {
- lock.lock()
- try {
- backing.isEmpty()
- } finally {
- lock.unlock()
- }
- }
-
- override def toArray[X](a: Array[X with AnyRef]) = {
- lock.lock()
- try {
- backing.toArray[X](a)
- } finally {
- lock.unlock()
- }
- }
-}
diff --git a/test/disabled/presentation/akka/src/akka/util/Crypt.scala b/test/disabled/presentation/akka/src/akka/util/Crypt.scala
deleted file mode 100644
index 3ce2d559a2..0000000000
--- a/test/disabled/presentation/akka/src/akka/util/Crypt.scala
+++ /dev/null
@@ -1,44 +0,0 @@
-/**
- * Copyright (C) 2009-2011 Scalable Solutions AB <http://scalablesolutions.se>
- */
-
-package akka.util
-
-import java.security.{ MessageDigest, SecureRandom }
-
-/**
- * @author <a href="http://jonasboner.com">Jonas Bon&#233;r</a>
- */
-object Crypt {
- val hex = "0123456789ABCDEF"
- val lineSeparator = System.getProperty("line.separator")
-
- lazy val random = SecureRandom.getInstance("SHA1PRNG")
-
- def md5(text: String): String = md5(unifyLineSeparator(text).getBytes("ASCII"))
-
- def md5(bytes: Array[Byte]): String = digest(bytes, MessageDigest.getInstance("MD5"))
-
- def sha1(text: String): String = sha1(unifyLineSeparator(text).getBytes("ASCII"))
-
- def sha1(bytes: Array[Byte]): String = digest(bytes, MessageDigest.getInstance("SHA1"))
-
- def generateSecureCookie: String = {
- val bytes = Array.fill(32)(0.byteValue)
- random.nextBytes(bytes)
- sha1(bytes)
- }
-
- def digest(bytes: Array[Byte], md: MessageDigest): String = {
- md.update(bytes)
- hexify(md.digest)
- }
-
- def hexify(bytes: Array[Byte]): String = {
- val builder = new StringBuilder
- bytes.foreach { byte => builder.append(hex.charAt((byte & 0xF) >> 4)).append(hex.charAt(byte & 0xF)) }
- builder.toString
- }
-
- private def unifyLineSeparator(text: String): String = text.replaceAll(lineSeparator, "\n")
-}
diff --git a/test/disabled/presentation/akka/src/akka/util/Duration.scala b/test/disabled/presentation/akka/src/akka/util/Duration.scala
deleted file mode 100644
index 316cb86689..0000000000
--- a/test/disabled/presentation/akka/src/akka/util/Duration.scala
+++ /dev/null
@@ -1,437 +0,0 @@
-/**
- * Copyright (C) 2009-2011 Scalable Solutions AB <http://scalablesolutions.se>
- */
-
-package akka.util
-
-import java.util.concurrent.TimeUnit
-import TimeUnit._
-import java.lang.{ Long => JLong, Double => JDouble }
-
-object Duration {
- def apply(length: Long, unit: TimeUnit): Duration = new FiniteDuration(length, unit)
- def apply(length: Double, unit: TimeUnit): Duration = fromNanos(unit.toNanos(1) * length)
- def apply(length: Long, unit: String): Duration = new FiniteDuration(length, timeUnit(unit))
-
- def fromNanos(nanos: Long): Duration = {
- if (nanos % 86400000000000L == 0) {
- Duration(nanos / 86400000000000L, DAYS)
- } else if (nanos % 3600000000000L == 0) {
- Duration(nanos / 3600000000000L, HOURS)
- } else if (nanos % 60000000000L == 0) {
- Duration(nanos / 60000000000L, MINUTES)
- } else if (nanos % 1000000000L == 0) {
- Duration(nanos / 1000000000L, SECONDS)
- } else if (nanos % 1000000L == 0) {
- Duration(nanos / 1000000L, MILLISECONDS)
- } else if (nanos % 1000L == 0) {
- Duration(nanos / 1000L, MICROSECONDS)
- } else {
- Duration(nanos, NANOSECONDS)
- }
- }
-
- def fromNanos(nanos: Double): Duration = fromNanos((nanos + 0.5).asInstanceOf[Long])
-
- /**
- * Construct a Duration by parsing a String. In case of a format error, a
- * RuntimeException is thrown. See `unapply(String)` for more information.
- */
- def apply(s: String): Duration = unapply(s) getOrElse sys.error("format error")
-
- /**
- * Deconstruct a Duration into length and unit if it is finite.
- */
- def unapply(d: Duration): Option[(Long, TimeUnit)] = {
- if (d.finite_?) {
- Some((d.length, d.unit))
- } else {
- None
- }
- }
-
- private val RE = ("""^\s*(\d+(?:\.\d+)?)\s*""" + // length part
- "(?:" + // units are distinguished in separate match groups
- "(d|day|days)|" +
- "(h|hour|hours)|" +
- "(min|minute|minutes)|" +
- "(s|sec|second|seconds)|" +
- "(ms|milli|millis|millisecond|milliseconds)|" +
- "(µs|micro|micros|microsecond|microseconds)|" +
- "(ns|nano|nanos|nanosecond|nanoseconds)" +
- """)\s*$""").r // close the non-capturing group
- private val REinf = """^\s*Inf\s*$""".r
- private val REminf = """^\s*(?:-\s*|Minus)Inf\s*""".r
-
- /**
- * Parse String, return None if no match. Format is `"<length><unit>"`, where
- * whitespace is allowed before, between and after the parts. Infinities are
- * designated by `"Inf"` and `"-Inf"` or `"MinusInf"`.
- */
- def unapply(s: String): Option[Duration] = s match {
- case RE(length, d, h, m, s, ms, mus, ns) =>
- if (d ne null) Some(Duration(JDouble.parseDouble(length), DAYS)) else if (h ne null) Some(Duration(JDouble.parseDouble(length), HOURS)) else if (m ne null) Some(Duration(JDouble.parseDouble(length), MINUTES)) else if (s ne null) Some(Duration(JDouble.parseDouble(length), SECONDS)) else if (ms ne null) Some(Duration(JDouble.parseDouble(length), MILLISECONDS)) else if (mus ne null) Some(Duration(JDouble.parseDouble(length), MICROSECONDS)) else if (ns ne null) Some(Duration(JDouble.parseDouble(length), NANOSECONDS)) else
- sys.error("made some error in regex (should not be possible)")
- case REinf() => Some(Inf)
- case REminf() => Some(MinusInf)
- case _ => None
- }
-
- /**
- * Parse TimeUnit from string representation.
- */
- def timeUnit(unit: String) = unit.toLowerCase match {
- case "d" | "day" | "days" => DAYS
- case "h" | "hour" | "hours" => HOURS
- case "min" | "minute" | "minutes" => MINUTES
- case "s" | "sec" | "second" | "seconds" => SECONDS
- case "ms" | "milli" | "millis" | "millisecond" | "milliseconds" => MILLISECONDS
- case "µs" | "micro" | "micros" | "microsecond" | "microseconds" => MICROSECONDS
- case "ns" | "nano" | "nanos" | "nanosecond" | "nanoseconds" => NANOSECONDS
- }
-
- val Zero: Duration = new FiniteDuration(0, NANOSECONDS)
-
- trait Infinite {
- this: Duration =>
-
- override def equals(other: Any) = false
-
- def +(other: Duration): Duration =
- other match {
- case _: this.type => this
- case _: Infinite => throw new IllegalArgumentException("illegal addition of infinities")
- case _ => this
- }
- def -(other: Duration): Duration =
- other match {
- case _: this.type => throw new IllegalArgumentException("illegal subtraction of infinities")
- case _ => this
- }
- def *(factor: Double): Duration = this
- def /(factor: Double): Duration = this
- def /(other: Duration): Double =
- other match {
- case _: Infinite => throw new IllegalArgumentException("illegal division of infinities")
- // maybe questionable but pragmatic: Inf / 0 => Inf
- case x => Double.PositiveInfinity * (if ((this > Zero) ^ (other >= Zero)) -1 else 1)
- }
-
- def finite_? = false
-
- def length: Long = throw new IllegalArgumentException("length not allowed on infinite Durations")
- def unit: TimeUnit = throw new IllegalArgumentException("unit not allowed on infinite Durations")
- def toNanos: Long = throw new IllegalArgumentException("toNanos not allowed on infinite Durations")
- def toMicros: Long = throw new IllegalArgumentException("toMicros not allowed on infinite Durations")
- def toMillis: Long = throw new IllegalArgumentException("toMillis not allowed on infinite Durations")
- def toSeconds: Long = throw new IllegalArgumentException("toSeconds not allowed on infinite Durations")
- def toMinutes: Long = throw new IllegalArgumentException("toMinutes not allowed on infinite Durations")
- def toHours: Long = throw new IllegalArgumentException("toHours not allowed on infinite Durations")
- def toDays: Long = throw new IllegalArgumentException("toDays not allowed on infinite Durations")
- def toUnit(unit: TimeUnit): Double = throw new IllegalArgumentException("toUnit not allowed on infinite Durations")
-
- def printHMS = toString
- }
-
- /**
- * Infinite duration: greater than any other and not equal to any other,
- * including itself.
- */
- val Inf: Duration = new Duration with Infinite {
- override def toString = "Duration.Inf"
- def >(other: Duration) = true
- def >=(other: Duration) = true
- def <(other: Duration) = false
- def <=(other: Duration) = false
- def unary_- : Duration = MinusInf
- }
-
- /**
- * Infinite negative duration: lesser than any other and not equal to any other,
- * including itself.
- */
- val MinusInf: Duration = new Duration with Infinite {
- override def toString = "Duration.MinusInf"
- def >(other: Duration) = false
- def >=(other: Duration) = false
- def <(other: Duration) = true
- def <=(other: Duration) = true
- def unary_- : Duration = Inf
- }
-
- // Java Factories
- def create(length: Long, unit: TimeUnit): Duration = apply(length, unit)
- def create(length: Double, unit: TimeUnit): Duration = apply(length, unit)
- def create(length: Long, unit: String): Duration = apply(length, unit)
- def parse(s: String): Duration = unapply(s).get
-}
-
-/**
- * Utility for working with java.util.concurrent.TimeUnit durations.
- *
- * <p/>
- * Examples of usage from Java:
- * <pre>
- * import akka.util.FiniteDuration;
- * import java.util.concurrent.TimeUnit;
- *
- * Duration duration = new FiniteDuration(100, MILLISECONDS);
- * Duration duration = new FiniteDuration(5, "seconds");
- *
- * duration.toNanos();
- * </pre>
- *
- * <p/>
- * Examples of usage from Scala:
- * <pre>
- * import akka.util.Duration
- * import java.util.concurrent.TimeUnit
- *
- * val duration = Duration(100, MILLISECONDS)
- * val duration = Duration(100, "millis")
- *
- * duration.toNanos
- * duration < 1.second
- * duration <= Duration.Inf
- * </pre>
- *
- * <p/>
- * Implicits are also provided for Int, Long and Double. Example usage:
- * <pre>
- * import akka.util.duration._
- *
- * val duration = 100 millis
- * </pre>
- *
- * Extractors, parsing and arithmetic are also included:
- * <pre>
- * val d = Duration("1.2 µs")
- * val Duration(length, unit) = 5 millis
- * val d2 = d * 2.5
- * val d3 = d2 + 1.millisecond
- * </pre>
- */
-abstract class Duration {
- def length: Long
- def unit: TimeUnit
- def toNanos: Long
- def toMicros: Long
- def toMillis: Long
- def toSeconds: Long
- def toMinutes: Long
- def toHours: Long
- def toDays: Long
- def toUnit(unit: TimeUnit): Double
- def printHMS: String
- def <(other: Duration): Boolean
- def <=(other: Duration): Boolean
- def >(other: Duration): Boolean
- def >=(other: Duration): Boolean
- def +(other: Duration): Duration
- def -(other: Duration): Duration
- def *(factor: Double): Duration
- def /(factor: Double): Duration
- def /(other: Duration): Double
- def unary_- : Duration
- def finite_? : Boolean
-
- // Java API
- def lt(other: Duration) = this < other
- def lteq(other: Duration) = this <= other
- def gt(other: Duration) = this > other
- def gteq(other: Duration) = this >= other
- def plus(other: Duration) = this + other
- def minus(other: Duration) = this - other
- def mul(factor: Double) = this * factor
- def div(factor: Double) = this / factor
- def div(other: Duration) = this / other
- def neg() = -this
- def isFinite() = finite_?
-}
-
-class FiniteDuration(val length: Long, val unit: TimeUnit) extends Duration {
- import Duration._
-
- def this(length: Long, unit: String) = this(length, Duration.timeUnit(unit))
-
- def toNanos = unit.toNanos(length)
- def toMicros = unit.toMicros(length)
- def toMillis = unit.toMillis(length)
- def toSeconds = unit.toSeconds(length)
- def toMinutes = unit.toMinutes(length)
- def toHours = unit.toHours(length)
- def toDays = unit.toDays(length)
- def toUnit(u: TimeUnit) = long2double(toNanos) / NANOSECONDS.convert(1, u)
-
- override def toString = this match {
- case Duration(1, DAYS) => "1 day"
- case Duration(x, DAYS) => x + " days"
- case Duration(1, HOURS) => "1 hour"
- case Duration(x, HOURS) => x + " hours"
- case Duration(1, MINUTES) => "1 minute"
- case Duration(x, MINUTES) => x + " minutes"
- case Duration(1, SECONDS) => "1 second"
- case Duration(x, SECONDS) => x + " seconds"
- case Duration(1, MILLISECONDS) => "1 millisecond"
- case Duration(x, MILLISECONDS) => x + " milliseconds"
- case Duration(1, MICROSECONDS) => "1 microsecond"
- case Duration(x, MICROSECONDS) => x + " microseconds"
- case Duration(1, NANOSECONDS) => "1 nanosecond"
- case Duration(x, NANOSECONDS) => x + " nanoseconds"
- }
-
- def printHMS = "%02d:%02d:%06.3f".format(toHours, toMinutes % 60, toMillis / 1000. % 60)
-
- def <(other: Duration) = {
- if (other.finite_?) {
- toNanos < other.asInstanceOf[FiniteDuration].toNanos
- } else {
- other > this
- }
- }
-
- def <=(other: Duration) = {
- if (other.finite_?) {
- toNanos <= other.asInstanceOf[FiniteDuration].toNanos
- } else {
- other >= this
- }
- }
-
- def >(other: Duration) = {
- if (other.finite_?) {
- toNanos > other.asInstanceOf[FiniteDuration].toNanos
- } else {
- other < this
- }
- }
-
- def >=(other: Duration) = {
- if (other.finite_?) {
- toNanos >= other.asInstanceOf[FiniteDuration].toNanos
- } else {
- other <= this
- }
- }
-
- def +(other: Duration) = {
- if (!other.finite_?) {
- other
- } else {
- val nanos = toNanos + other.asInstanceOf[FiniteDuration].toNanos
- fromNanos(nanos)
- }
- }
-
- def -(other: Duration) = {
- if (!other.finite_?) {
- other
- } else {
- val nanos = toNanos - other.asInstanceOf[FiniteDuration].toNanos
- fromNanos(nanos)
- }
- }
-
- def *(factor: Double) = fromNanos(long2double(toNanos) * factor)
-
- def /(factor: Double) = fromNanos(long2double(toNanos) / factor)
-
- def /(other: Duration) = if (other.finite_?) long2double(toNanos) / other.toNanos else 0
-
- def unary_- = Duration(-length, unit)
-
- def finite_? = true
-
- override def equals(other: Any) =
- other.isInstanceOf[FiniteDuration] &&
- toNanos == other.asInstanceOf[FiniteDuration].toNanos
-
- override def hashCode = toNanos.asInstanceOf[Int]
-}
-
-class DurationInt(n: Int) {
- def nanoseconds = Duration(n, NANOSECONDS)
- def nanos = Duration(n, NANOSECONDS)
- def nanosecond = Duration(n, NANOSECONDS)
- def nano = Duration(n, NANOSECONDS)
-
- def microseconds = Duration(n, MICROSECONDS)
- def micros = Duration(n, MICROSECONDS)
- def microsecond = Duration(n, MICROSECONDS)
- def micro = Duration(n, MICROSECONDS)
-
- def milliseconds = Duration(n, MILLISECONDS)
- def millis = Duration(n, MILLISECONDS)
- def millisecond = Duration(n, MILLISECONDS)
- def milli = Duration(n, MILLISECONDS)
-
- def seconds = Duration(n, SECONDS)
- def second = Duration(n, SECONDS)
-
- def minutes = Duration(n, MINUTES)
- def minute = Duration(n, MINUTES)
-
- def hours = Duration(n, HOURS)
- def hour = Duration(n, HOURS)
-
- def days = Duration(n, DAYS)
- def day = Duration(n, DAYS)
-}
-
-class DurationLong(n: Long) {
- def nanoseconds = Duration(n, NANOSECONDS)
- def nanos = Duration(n, NANOSECONDS)
- def nanosecond = Duration(n, NANOSECONDS)
- def nano = Duration(n, NANOSECONDS)
-
- def microseconds = Duration(n, MICROSECONDS)
- def micros = Duration(n, MICROSECONDS)
- def microsecond = Duration(n, MICROSECONDS)
- def micro = Duration(n, MICROSECONDS)
-
- def milliseconds = Duration(n, MILLISECONDS)
- def millis = Duration(n, MILLISECONDS)
- def millisecond = Duration(n, MILLISECONDS)
- def milli = Duration(n, MILLISECONDS)
-
- def seconds = Duration(n, SECONDS)
- def second = Duration(n, SECONDS)
-
- def minutes = Duration(n, MINUTES)
- def minute = Duration(n, MINUTES)
-
- def hours = Duration(n, HOURS)
- def hour = Duration(n, HOURS)
-
- def days = Duration(n, DAYS)
- def day = Duration(n, DAYS)
-}
-
-class DurationDouble(d: Double) {
- def nanoseconds = Duration(d, NANOSECONDS)
- def nanos = Duration(d, NANOSECONDS)
- def nanosecond = Duration(d, NANOSECONDS)
- def nano = Duration(d, NANOSECONDS)
-
- def microseconds = Duration(d, MICROSECONDS)
- def micros = Duration(d, MICROSECONDS)
- def microsecond = Duration(d, MICROSECONDS)
- def micro = Duration(d, MICROSECONDS)
-
- def milliseconds = Duration(d, MILLISECONDS)
- def millis = Duration(d, MILLISECONDS)
- def millisecond = Duration(d, MILLISECONDS)
- def milli = Duration(d, MILLISECONDS)
-
- def seconds = Duration(d, SECONDS)
- def second = Duration(d, SECONDS)
-
- def minutes = Duration(d, MINUTES)
- def minute = Duration(d, MINUTES)
-
- def hours = Duration(d, HOURS)
- def hour = Duration(d, HOURS)
-
- def days = Duration(d, DAYS)
- def day = Duration(d, DAYS)
-}
diff --git a/test/disabled/presentation/akka/src/akka/util/HashCode.scala b/test/disabled/presentation/akka/src/akka/util/HashCode.scala
deleted file mode 100644
index d015f12f5d..0000000000
--- a/test/disabled/presentation/akka/src/akka/util/HashCode.scala
+++ /dev/null
@@ -1,57 +0,0 @@
-/**
- * Copyright (C) 2009-2011 Scalable Solutions AB <http://scalablesolutions.se>
- */
-
-package akka.util
-
-import java.lang.reflect.{ Array => JArray }
-import java.lang.{ Float => JFloat, Double => JDouble }
-
-/**
- * Set of methods which allow easy implementation of <code>hashCode</code>.
- *
- * Example:
- * <pre>
- * override def hashCode: Int = {
- * var result = HashCode.SEED
- * //collect the contributions of various fields
- * result = HashCode.hash(result, fPrimitive)
- * result = HashCode.hash(result, fObject)
- * result = HashCode.hash(result, fArray)
- * result
- * }
- * </pre>
- *
- * @author <a href="http://jonasboner.com">Jonas Bon&#233;r</a>
- */
-object HashCode {
- val SEED = 23
-
- def hash(seed: Int, any: Any): Int = any match {
- case value: Boolean => hash(seed, value)
- case value: Char => hash(seed, value)
- case value: Short => hash(seed, value)
- case value: Int => hash(seed, value)
- case value: Long => hash(seed, value)
- case value: Float => hash(seed, value)
- case value: Double => hash(seed, value)
- case value: Byte => hash(seed, value)
- case value: AnyRef =>
- var result = seed
- if (value eq null) result = hash(result, 0)
- else if (!isArray(value)) result = hash(result, value.hashCode())
- else for (id ← 0 until JArray.getLength(value)) result = hash(result, JArray.get(value, id)) // is an array
- result
- }
- def hash(seed: Int, value: Boolean): Int = firstTerm(seed) + (if (value) 1 else 0)
- def hash(seed: Int, value: Char): Int = firstTerm(seed) + value.asInstanceOf[Int]
- def hash(seed: Int, value: Int): Int = firstTerm(seed) + value
- def hash(seed: Int, value: Long): Int = firstTerm(seed) + (value ^ (value >>> 32)).asInstanceOf[Int]
- def hash(seed: Int, value: Float): Int = hash(seed, JFloat.floatToIntBits(value))
- def hash(seed: Int, value: Double): Int = hash(seed, JDouble.doubleToLongBits(value))
-
- private def firstTerm(seed: Int): Int = PRIME * seed
- private def isArray(anyRef: AnyRef): Boolean = anyRef.getClass.isArray
- private val PRIME = 37
-}
-
diff --git a/test/disabled/presentation/akka/src/akka/util/Helpers.scala b/test/disabled/presentation/akka/src/akka/util/Helpers.scala
deleted file mode 100644
index 0ff45408d0..0000000000
--- a/test/disabled/presentation/akka/src/akka/util/Helpers.scala
+++ /dev/null
@@ -1,99 +0,0 @@
-/**
- * Copyright (C) 2009-2011 Scalable Solutions AB <http://scalablesolutions.se>
- */
-
-package akka.util
-
-/**
- * @author <a href="http://jonasboner.com">Jonas Bon&#233;r</a>
- */
-object Helpers {
-
- implicit def null2Option[T](t: T): Option[T] = Option(t)
-
- def intToBytes(value: Int): Array[Byte] = {
- val bytes = new Array[Byte](4)
- bytes(0) = (value >>> 24).asInstanceOf[Byte]
- bytes(1) = (value >>> 16).asInstanceOf[Byte]
- bytes(2) = (value >>> 8).asInstanceOf[Byte]
- bytes(3) = value.asInstanceOf[Byte]
- bytes
- }
-
- def bytesToInt(bytes: Array[Byte], offset: Int): Int = {
- (0 until 4).foldLeft(0)((value, index) => value + ((bytes(index + offset) & 0x000000FF) << ((4 - 1 - index) * 8)))
- }
-
- /**
- * Convenience helper to cast the given Option of Any to an Option of the given type. Will throw a ClassCastException
- * if the actual type is not assignable from the given one.
- */
- def narrow[T](o: Option[Any]): Option[T] = {
- require((o ne null), "Option to be narrowed must not be null!")
- o.asInstanceOf[Option[T]]
- }
-
- /**
- * Convenience helper to cast the given Option of Any to an Option of the given type. Will swallow a possible
- * ClassCastException and return None in that case.
- */
- def narrowSilently[T: ClassTag](o: Option[Any]): Option[T] =
- try {
- narrow(o)
- } catch {
- case e: ClassCastException =>
- None
- }
-
- /**
- * Reference that can hold either a typed value or an exception.
- *
- * Usage:
- * <pre>
- * scala> ResultOrError(1)
- * res0: ResultOrError[Int] = ResultOrError@a96606
- *
- * scala> res0()
- * res1: Int = 1
- *
- * scala> res0() = 3
- *
- * scala> res0()
- * res3: Int = 3
- *
- * scala> res0() = { println("Hello world"); 3}
- * Hello world
- *
- * scala> res0()
- * res5: Int = 3
- *
- * scala> res0() = error("Lets see what happens here...")
- *
- * scala> res0()
- * java.lang.RuntimeException: Lets see what happens here...
- * at ResultOrError.apply(Helper.scala:11)
- * at .<init>(<console>:6)
- * at .<clinit>(<console>)
- * at Re...
- * </pre>
- */
- class ResultOrError[R](result: R) {
- private[this] var contents: Either[R, Throwable] = Left(result)
-
- def update(value: => R) = {
- contents = try {
- Left(value)
- } catch {
- case (error: Throwable) => Right(error)
- }
- }
-
- def apply() = contents match {
- case Left(result) => result
- case Right(error) => throw error.fillInStackTrace
- }
- }
- object ResultOrError {
- def apply[R](result: R) = new ResultOrError(result)
- }
-}
diff --git a/test/disabled/presentation/akka/src/akka/util/ListenerManagement.scala b/test/disabled/presentation/akka/src/akka/util/ListenerManagement.scala
deleted file mode 100644
index 863e905d59..0000000000
--- a/test/disabled/presentation/akka/src/akka/util/ListenerManagement.scala
+++ /dev/null
@@ -1,81 +0,0 @@
-/**
- * Copyright (C) 2009-2011 Scalable Solutions AB <http://scalablesolutions.se>
- */
-
-package akka.util
-
-import java.util.concurrent.ConcurrentSkipListSet
-import akka.actor.{ ActorInitializationException, ActorRef }
-
-/**
- * A manager for listener actors. Intended for mixin by observables.
- *
- * @author Martin Krasser
- */
-trait ListenerManagement {
-
- private val listeners = new ConcurrentSkipListSet[ActorRef]
-
- /**
- * Specifies whether listeners should be started when added and stopped when removed or not
- */
- protected def manageLifeCycleOfListeners: Boolean = true
-
- /**
- * Adds the <code>listener</code> this registry's listener list.
- * The <code>listener</code> is started by this method if manageLifeCycleOfListeners yields true.
- */
- def addListener(listener: ActorRef) {
- if (manageLifeCycleOfListeners) listener.start()
- listeners add listener
- }
-
- /**
- * Removes the <code>listener</code> this registry's listener list.
- * The <code>listener</code> is stopped by this method if manageLifeCycleOfListeners yields true.
- */
- def removeListener(listener: ActorRef) {
- listeners remove listener
- if (manageLifeCycleOfListeners) listener.stop()
- }
-
- /*
- * Returns whether there are any listeners currently
- */
- def hasListeners: Boolean = !listeners.isEmpty
-
- /**
- * Checks if a specific listener is registered. ActorInitializationException leads to removal of listener if that
- * one isShutdown.
- */
- def hasListener(listener: ActorRef): Boolean = listeners.contains(listener)
-
- protected[akka] def notifyListeners(message: => Any) {
- if (hasListeners) {
- val msg = message
- val iterator = listeners.iterator
- while (iterator.hasNext) {
- val listener = iterator.next
- // Uncomment if those exceptions are so frequent as to bottleneck
- // if (listener.isShutdown) iterator.remove() else
- try {
- listener ! msg
- } catch {
- case e: ActorInitializationException =>
- if (listener.isShutdown) iterator.remove()
- }
- }
- }
- }
-
- /**
- * Execute <code>f</code> with each listener as argument. ActorInitializationException is not handled.
- */
- protected[akka] def foreachListener(f: (ActorRef) => Unit) {
- val iterator = listeners.iterator
- while (iterator.hasNext) {
- val listener = iterator.next
- if (listener.isRunning) f(listener)
- }
- }
-}
diff --git a/test/disabled/presentation/akka/src/akka/util/LockUtil.scala b/test/disabled/presentation/akka/src/akka/util/LockUtil.scala
deleted file mode 100644
index 4aaefadc4a..0000000000
--- a/test/disabled/presentation/akka/src/akka/util/LockUtil.scala
+++ /dev/null
@@ -1,197 +0,0 @@
-/**
- * Copyright (C) 2009-2011 Scalable Solutions AB <http://scalablesolutions.se>
- */
-
-package akka.util
-
-import java.util.concurrent.locks.{ ReentrantReadWriteLock, ReentrantLock }
-import java.util.concurrent.atomic.{ AtomicBoolean }
-import akka.event.EventHandler
-
-/**
- * @author <a href="http://jonasboner.com">Jonas Bon&#233;r</a>
- */
-final class ReentrantGuard {
- val lock = new ReentrantLock
-
- final def withGuard[T](body: => T): T = {
- lock.lock
- try {
- body
- } finally {
- lock.unlock
- }
- }
-
- final def tryWithGuard[T](body: => T): T = {
- while (!lock.tryLock) { Thread.sleep(10) } // wait on the monitor to be unlocked
- try {
- body
- } finally {
- lock.unlock
- }
- }
-}
-
-/**
- * @author <a href="http://jonasboner.com">Jonas Bon&#233;r</a>
- */
-class ReadWriteGuard {
- private val rwl = new ReentrantReadWriteLock
- val readLock = rwl.readLock
- val writeLock = rwl.writeLock
-
- def withWriteGuard[T](body: => T): T = {
- writeLock.lock
- try {
- body
- } finally {
- writeLock.unlock
- }
- }
-
- def withReadGuard[T](body: => T): T = {
- readLock.lock
- try {
- body
- } finally {
- readLock.unlock
- }
- }
-}
-
-/**
- * A very simple lock that uses CCAS (Compare Compare-And-Swap)
- * Does not keep track of the owner and isn't Reentrant, so don't nest and try to stick to the if*-methods
- */
-class SimpleLock {
- val acquired = new AtomicBoolean(false)
-
- def ifPossible(perform: () => Unit): Boolean = {
- if (tryLock()) {
- try {
- perform
- } finally {
- unlock()
- }
- true
- } else false
- }
-
- def ifPossibleYield[T](perform: () => T): Option[T] = {
- if (tryLock()) {
- try {
- Some(perform())
- } finally {
- unlock()
- }
- } else None
- }
-
- def ifPossibleApply[T, R](value: T)(function: (T) => R): Option[R] = {
- if (tryLock()) {
- try {
- Some(function(value))
- } finally {
- unlock()
- }
- } else None
- }
-
- def tryLock() = {
- if (acquired.get) false
- else acquired.compareAndSet(false, true)
- }
-
- def tryUnlock() = {
- acquired.compareAndSet(true, false)
- }
-
- def locked = acquired.get
-
- def unlock() {
- acquired.set(false)
- }
-}
-
-/**
- * An atomic switch that can be either on or off
- */
-class Switch(startAsOn: Boolean = false) {
- private val switch = new AtomicBoolean(startAsOn)
-
- protected def transcend(from: Boolean, action: => Unit): Boolean = synchronized {
- if (switch.compareAndSet(from, !from)) {
- try {
- action
- } catch {
- case e: Throwable =>
- EventHandler.error(e, this, e.getMessage)
- switch.compareAndSet(!from, from) // revert status
- throw e
- }
- true
- } else false
- }
-
- def switchOff(action: => Unit): Boolean = transcend(from = true, action)
- def switchOn(action: => Unit): Boolean = transcend(from = false, action)
-
- def switchOff: Boolean = synchronized { switch.compareAndSet(true, false) }
- def switchOn: Boolean = synchronized { switch.compareAndSet(false, true) }
-
- def ifOnYield[T](action: => T): Option[T] = {
- if (switch.get) Some(action)
- else None
- }
-
- def ifOffYield[T](action: => T): Option[T] = {
- if (!switch.get) Some(action)
- else None
- }
-
- def ifOn(action: => Unit): Boolean = {
- if (switch.get) {
- action
- true
- } else false
- }
-
- def ifOff(action: => Unit): Boolean = {
- if (!switch.get) {
- action
- true
- } else false
- }
-
- def whileOnYield[T](action: => T): Option[T] = synchronized {
- if (switch.get) Some(action)
- else None
- }
-
- def whileOffYield[T](action: => T): Option[T] = synchronized {
- if (!switch.get) Some(action)
- else None
- }
-
- def whileOn(action: => Unit): Boolean = synchronized {
- if (switch.get) {
- action
- true
- } else false
- }
-
- def whileOff(action: => Unit): Boolean = synchronized {
- if (switch.get) {
- action
- true
- } else false
- }
-
- def ifElseYield[T](on: => T)(off: => T) = synchronized {
- if (switch.get) on else off
- }
-
- def isOn = switch.get
- def isOff = !isOn
-}
diff --git a/test/disabled/presentation/akka/src/akka/util/ReflectiveAccess.scala b/test/disabled/presentation/akka/src/akka/util/ReflectiveAccess.scala
deleted file mode 100644
index f38d1f9b98..0000000000
--- a/test/disabled/presentation/akka/src/akka/util/ReflectiveAccess.scala
+++ /dev/null
@@ -1,232 +0,0 @@
-/**
- * Copyright (C) 2009-2011 Scalable Solutions AB <http://scalablesolutions.se>
- */
-
-package akka.util
-
-import akka.dispatch.{ Future, CompletableFuture, MessageInvocation }
-import akka.config.{ Config, ModuleNotAvailableException }
-
-import java.net.InetSocketAddress
-import akka.remoteinterface.RemoteSupport
-import akka.actor._
-import akka.event.EventHandler
-
-/**
- * Helper class for reflective access to different modules in order to allow optional loading of modules.
- *
- * @author <a href="http://jonasboner.com">Jonas Bon&#233;r</a>
- */
-object ReflectiveAccess {
-
- val loader = getClass.getClassLoader
-
- def isRemotingEnabled = Remote.isEnabled
- lazy val isTypedActorEnabled = TypedActorModule.isEnabled
-
- def ensureRemotingEnabled = Remote.ensureEnabled
- def ensureTypedActorEnabled = TypedActorModule.ensureEnabled
-
- /**
- * Reflective access to the RemoteClient module.
- *
- * @author <a href="http://jonasboner.com">Jonas Bon&#233;r</a>
- */
- object Remote {
- val TRANSPORT = Config.config.getString("akka.remote.layer", "akka.remote.netty.NettyRemoteSupport")
-
- private[akka] val configDefaultAddress =
- new InetSocketAddress(Config.config.getString("akka.remote.server.hostname", "localhost"),
- Config.config.getInt("akka.remote.server.port", 2552))
-
- lazy val isEnabled = remoteSupportClass.isDefined
-
- def ensureEnabled = if (!isEnabled) {
- val e = new ModuleNotAvailableException("Can't load the remoting module, make sure that akka-remote.jar is on the classpath")
- EventHandler.debug(this, e.toString)
- throw e
- }
- val remoteSupportClass = getClassFor[RemoteSupport](TRANSPORT) match {
- case Right(value) => Some(value)
- case Left(exception) =>
- EventHandler.debug(this, exception.toString)
- None
- }
-
- protected[akka] val defaultRemoteSupport: Option[() => RemoteSupport] =
- remoteSupportClass map { remoteClass =>
- () => createInstance[RemoteSupport](
- remoteClass,
- Array[Class[_]](),
- Array[AnyRef]()) match {
- case Right(value) => value
- case Left(exception) =>
- val e = new ModuleNotAvailableException(
- "Can't instantiate [%s] - make sure that akka-remote.jar is on the classpath".format(remoteClass.getName), exception)
- EventHandler.debug(this, e.toString)
- throw e
- }
- }
- }
-
- /**
- * Reflective access to the TypedActors module.
- *
- * @author <a href="http://jonasboner.com">Jonas Bon&#233;r</a>
- */
- object TypedActorModule {
-
- type TypedActorObject = {
- def isJoinPoint(message: Any): Boolean
- def isJoinPointAndOneWay(message: Any): Boolean
- def actorFor(proxy: AnyRef): Option[ActorRef]
- def proxyFor(actorRef: ActorRef): Option[AnyRef]
- def stop(anyRef: AnyRef): Unit
- }
-
- lazy val isEnabled = typedActorObjectInstance.isDefined
-
- def ensureEnabled = if (!isTypedActorEnabled) throw new ModuleNotAvailableException(
- "Can't load the typed actor module, make sure that akka-typed-actor.jar is on the classpath")
-
- val typedActorObjectInstance: Option[TypedActorObject] =
- getObjectFor[TypedActorObject]("akka.actor.TypedActor$") match {
- case Right(value) => Some(value)
- case Left(exception) =>
- EventHandler.debug(this, exception.toString)
- None
- }
-
- def resolveFutureIfMessageIsJoinPoint(message: Any, future: Future[_]): Boolean = {
- ensureEnabled
- if (typedActorObjectInstance.get.isJoinPointAndOneWay(message)) {
- future.asInstanceOf[CompletableFuture[Option[_]]].completeWithResult(None)
- }
- typedActorObjectInstance.get.isJoinPoint(message)
- }
- }
-
- object AkkaCloudModule {
-
- type Mailbox = {
- def enqueue(message: MessageInvocation)
- def dequeue: MessageInvocation
- }
-
- type Serializer = {
- def toBinary(obj: AnyRef): Array[Byte]
- def fromBinary(bytes: Array[Byte], clazz: Option[Class[_]]): AnyRef
- }
-
- lazy val isEnabled = clusterObjectInstance.isDefined
-
- val clusterObjectInstance: Option[AnyRef] =
- getObjectFor[AnyRef]("akka.cloud.cluster.Cluster$") match {
- case Right(value) => Some(value)
- case Left(exception) =>
- EventHandler.debug(this, exception.toString)
- None
- }
-
- val serializerClass: Option[Class[_]] =
- getClassFor("akka.serialization.Serializer") match {
- case Right(value) => Some(value)
- case Left(exception) =>
- EventHandler.debug(this, exception.toString)
- None
- }
-
- def ensureEnabled = if (!isEnabled) throw new ModuleNotAvailableException(
- "Feature is only available in Akka Cloud")
- }
-
- val noParams = Array[Class[_]]()
- val noArgs = Array[AnyRef]()
-
- def createInstance[T](clazz: Class[_],
- params: Array[Class[_]],
- args: Array[AnyRef]): Either[Exception, T] = try {
- assert(clazz ne null)
- assert(params ne null)
- assert(args ne null)
- val ctor = clazz.getDeclaredConstructor(params: _*)
- ctor.setAccessible(true)
- Right(ctor.newInstance(args: _*).asInstanceOf[T])
- } catch {
- case e: Exception => Left(e)
- }
-
- def createInstance[T](fqn: String,
- params: Array[Class[_]],
- args: Array[AnyRef],
- classloader: ClassLoader = loader): Either[Exception, T] = try {
- assert(params ne null)
- assert(args ne null)
- getClassFor(fqn) match {
- case Right(value) =>
- val ctor = value.getDeclaredConstructor(params: _*)
- ctor.setAccessible(true)
- Right(ctor.newInstance(args: _*).asInstanceOf[T])
- case Left(exception) => Left(exception) //We could just cast this to Either[Exception, T] but it's ugly
- }
- } catch {
- case e: Exception =>
- Left(e)
- }
-
- //Obtains a reference to fqn.MODULE$
- def getObjectFor[T](fqn: String, classloader: ClassLoader = loader): Either[Exception, T] = try {
- getClassFor(fqn) match {
- case Right(value) =>
- val instance = value.getDeclaredField("MODULE$")
- instance.setAccessible(true)
- val obj = instance.get(null)
- if (obj eq null) Left(new NullPointerException) else Right(obj.asInstanceOf[T])
- case Left(exception) => Left(exception) //We could just cast this to Either[Exception, T] but it's ugly
- }
- } catch {
- case e: Exception =>
- Left(e)
- }
-
- def getClassFor[T](fqn: String, classloader: ClassLoader = loader): Either[Exception, Class[T]] = try {
- assert(fqn ne null)
-
- // First, use the specified CL
- val first = try {
- Right(classloader.loadClass(fqn).asInstanceOf[Class[T]])
- } catch {
- case c: ClassNotFoundException => Left(c)
- }
-
- if (first.isRight) first
- else {
- // Second option is to use the ContextClassLoader
- val second = try {
- Right(Thread.currentThread.getContextClassLoader.loadClass(fqn).asInstanceOf[Class[T]])
- } catch {
- case c: ClassNotFoundException => Left(c)
- }
-
- if (second.isRight) second
- else {
- val third = try {
- if (classloader ne loader) Right(loader.loadClass(fqn).asInstanceOf[Class[T]]) else Left(null) //Horrid
- } catch {
- case c: ClassNotFoundException => Left(c)
- }
-
- if (third.isRight) third
- else {
- try {
- Right(Class.forName(fqn).asInstanceOf[Class[T]]) // Last option is Class.forName
- } catch {
- case c: ClassNotFoundException => Left(c)
- }
- }
- }
- }
- } catch {
- case e: Exception => Left(e)
- }
-}
diff --git a/test/disabled/presentation/akka/src/akka/util/package.scala b/test/disabled/presentation/akka/src/akka/util/package.scala
deleted file mode 100644
index 26a24929c9..0000000000
--- a/test/disabled/presentation/akka/src/akka/util/package.scala
+++ /dev/null
@@ -1,27 +0,0 @@
-/**
- * Copyright (C) 2009-2011 Scalable Solutions AB <http://scalablesolutions.se>
- */
-
-package akka.util
-
-import java.util.concurrent.TimeUnit
-
-package object duration {
- implicit def intToDurationInt(n: Int) = new DurationInt(n)
- implicit def longToDurationLong(n: Long) = new DurationLong(n)
- implicit def doubleToDurationDouble(d: Double) = new DurationDouble(d)
-
- implicit def pairIntToDuration(p: (Int, TimeUnit)) = Duration(p._1, p._2)
- implicit def pairLongToDuration(p: (Long, TimeUnit)) = Duration(p._1, p._2)
- implicit def durationToPair(d: Duration) = (d.length, d.unit)
-
- implicit def intMult(i: Int) = new {
- def *(d: Duration) = d * i
- }
- implicit def longMult(l: Long) = new {
- def *(d: Duration) = d * l
- }
- implicit def doubleMult(f: Double) = new {
- def *(d: Duration) = d * f
- }
-}