Merge branch 'master' of github.com:jboner/akka

This commit is contained in:
Viktor Klang 2011-03-09 13:26:30 +01:00
commit 1301e301ef
3 changed files with 36 additions and 16 deletions

View file

@ -729,21 +729,6 @@ trait NettyRemoteServerModule extends RemoteServerModule { self: RemoteModule =>
if (_isRunning.isOn) typedActorsFactories.remove(id) if (_isRunning.isOn) typedActorsFactories.remove(id)
} }
object RemoteServerSslContext {
import javax.net.ssl.SSLContext
val (client, server) = {
val protocol = "TLS"
//val algorithm = Option(Security.getProperty("ssl.KeyManagerFactory.algorithm")).getOrElse("SunX509")
//val store = KeyStore.getInstance("JKS")
val s = SSLContext.getInstance(protocol)
s.init(null, null, null)
val c = SSLContext.getInstance(protocol)
c.init(null, null, null)
(c, s)
}
}
/** /**
* @author <a href="http://jonasboner.com">Jonas Bon&#233;r</a> * @author <a href="http://jonasboner.com">Jonas Bon&#233;r</a>
*/ */

View file

@ -7,12 +7,13 @@ package akka.agent
import akka.stm._ import akka.stm._
import akka.actor.Actor import akka.actor.Actor
import akka.japi.{Function => JFunc, Procedure => JProc} import akka.japi.{Function => JFunc, Procedure => JProc}
import akka.dispatch.Dispatchers import akka.dispatch.{Dispatchers, Future}
/** /**
* Used internally to send functions. * Used internally to send functions.
*/ */
private[akka] case class Update[T](function: T => T) private[akka] case class Update[T](function: T => T)
private[akka] case object Get
/** /**
* Factory method for creating an Agent. * Factory method for creating an Agent.
@ -139,6 +140,17 @@ class Agent[T](initialValue: T) {
value value
}) })
/**
* A future to the current value that will be completed after any currently
* queued updates.
*/
def future(): Future[T] = (updater !!! Get).asInstanceOf[Future[T]]
/**
* Gets this agent's value after all currently queued updates have completed.
*/
def await(): T = future.await.result.get
/** /**
* Map this agent to a new agent, applying the function to the internal state. * Map this agent to a new agent, applying the function to the internal state.
* Does not change the value of this agent. * Does not change the value of this agent.
@ -221,6 +233,7 @@ class AgentUpdater[T](agent: Agent[T]) extends Actor {
def receive = { def receive = {
case update: Update[T] => case update: Update[T] =>
atomic(txFactory) { agent.ref alter update.function } atomic(txFactory) { agent.ref alter update.function }
case Get => self reply agent.get
case _ => () case _ => ()
} }
} }

View file

@ -113,6 +113,28 @@ class AgentSpec extends WordSpec with MustMatchers {
agent.close agent.close
} }
"be able to return a 'queued' future" in {
val agent = Agent("a")
agent send (_ + "b")
agent send (_ + "c")
val future = agent.future
future.await.result.get must be ("abc")
agent.close
}
"be able to await the value after updates have completed" in {
val agent = Agent("a")
agent send (_ + "b")
agent send (_ + "c")
agent.await must be ("abc")
agent.close
}
"be able to be mapped" in { "be able to be mapped" in {
val agent1 = Agent(5) val agent1 = Agent(5)
val agent2 = agent1 map (_ * 2) val agent2 = agent1 map (_ * 2)