changed access modifier for RemoteServer.serverFor

This commit is contained in:
Jonas Bonér 2010-12-01 15:42:51 +01:00
parent 1aed36bcd7
commit bf4ed2b849
2 changed files with 69 additions and 20 deletions

View file

@ -116,6 +116,13 @@ object RemoteServer {
private val guard = new ReadWriteGuard
private val remoteServers = Map[Address, RemoteServer]()
def serverFor(address: InetSocketAddress): Option[RemoteServer] =
serverFor(address.getHostName, address.getPort)
def serverFor(hostname: String, port: Int): Option[RemoteServer] = guard.withReadGuard {
remoteServers.get(Address(hostname, port))
}
private[akka] def getOrCreateServer(address: InetSocketAddress): RemoteServer = guard.withWriteGuard {
serverFor(address) match {
case Some(server) => server
@ -123,13 +130,6 @@ object RemoteServer {
}
}
private[akka] def serverFor(address: InetSocketAddress): Option[RemoteServer] =
serverFor(address.getHostName, address.getPort)
private[akka] def serverFor(hostname: String, port: Int): Option[RemoteServer] = guard.withReadGuard {
remoteServers.get(Address(hostname, port))
}
private[akka] def register(hostname: String, port: Int, server: RemoteServer) = guard.withWriteGuard {
remoteServers.put(Address(hostname, port), server)
}
@ -139,7 +139,7 @@ object RemoteServer {
}
/**
* Used in REflectiveAccess
* Used in ReflectiveAccess
*/
private[akka] def registerActor(address: InetSocketAddress, actorRef: ActorRef) {
serverFor(address) foreach { _.register(actorRef) }

View file

@ -1,26 +1,75 @@
package akka.actor
import org.scalatest.junit.JUnitSuite
import org.junit.Test
import org.scalatest.WordSpec
import org.scalatest.matchers.MustMatchers
import akka.config.Supervision._
import akka.config._
object TypedActorRegistrySpec {
trait My
class MyImpl extends TypedActor with My
}
class TypedActorRegistrySpec extends JUnitSuite {
class TypedActorRegistrySpec extends WordSpec with MustMatchers {
import TypedActorRegistrySpec._
@Test def shouldGetTypedActorByClassFromActorRegistry {
ActorRegistry.shutdownAll
val my = TypedActor.newInstance[My](classOf[My], classOf[MyImpl], 3000)
"Typed Actor" should {
val actors = ActorRegistry.typedActorsFor(classOf[My])
assert(actors.length === 1)
"be able to be retreived from the registry by class" in {
ActorRegistry.shutdownAll
val my = TypedActor.newInstance[My](classOf[My], classOf[MyImpl], 3000)
val actors = ActorRegistry.typedActorsFor(classOf[My])
actors.length must be (1)
ActorRegistry.shutdownAll
}
val option = ActorRegistry.typedActorFor[My]
assert(option != null)
assert(option.isDefined)
ActorRegistry.shutdownAll
"be able to be retreived from the registry by manifest" in {
ActorRegistry.shutdownAll
val my = TypedActor.newInstance[My](classOf[My], classOf[MyImpl], 3000)
val option = ActorRegistry.typedActorFor[My]
option must not be (null)
option.isDefined must be (true)
ActorRegistry.shutdownAll
}
"be able to be retreived from the registry by class two times" in {
ActorRegistry.shutdownAll
val my = TypedActor.newInstance[My](classOf[My], classOf[MyImpl], 3000)
val actors1 = ActorRegistry.typedActorsFor(classOf[My])
actors1.length must be (1)
val actors2 = ActorRegistry.typedActorsFor(classOf[My])
actors2.length must be (1)
ActorRegistry.shutdownAll
}
"be able to be retreived from the registry by manifest two times" in {
ActorRegistry.shutdownAll
val my = TypedActor.newInstance[My](classOf[My], classOf[MyImpl], 3000)
val option1 = ActorRegistry.typedActorFor[My]
option1 must not be (null)
option1.isDefined must be (true)
val option2 = ActorRegistry.typedActorFor[My]
option2 must not be (null)
option2.isDefined must be (true)
ActorRegistry.shutdownAll
}
"be able to be retreived from the registry by manifest two times (even when created in supervisor)" in {
ActorRegistry.shutdownAll
val manager = new TypedActorConfigurator
manager.configure(
OneForOneStrategy(classOf[Exception] :: Nil, 3, 1000),
Array(new SuperviseTypedActor(classOf[My], classOf[MyImpl], Permanent, 6000))
).supervise
val option1 = ActorRegistry.typedActorFor[My]
option1 must not be (null)
option1.isDefined must be (true)
val option2 = ActorRegistry.typedActorFor[My]
option2 must not be (null)
option2.isDefined must be (true)
ActorRegistry.shutdownAll
}
}
}