Removing 1 AtomicLong from all ActorCells

This commit is contained in:
Viktor Klang 2011-11-22 10:41:04 +01:00
parent 4fdf698611
commit ce6dd05ab9
4 changed files with 21 additions and 13 deletions

View file

@ -362,7 +362,7 @@ abstract class ActorModelSpec extends AkkaSpec {
}
System.err.println("Mailbox: " + mq.numberOfMessages + " " + mq.hasMessages + " ")
case _ =>
case _
}
throw e

View file

@ -9,6 +9,7 @@ import scala.annotation.tailrec
import scala.collection.immutable.{ Stack, TreeMap }
import java.util.concurrent.TimeUnit
import akka.event.Logging.{ Debug, Warning, Error }
import akka.util.Helpers
/**
* The actor context - the view of the actor cell from the actor.
@ -92,14 +93,23 @@ private[akka] class ActorCell(
var stopping = false
@volatile //This must be volatile since it isn't protected by the mailbox status
var mailbox: Mailbox = _
var nextNameSequence: Long = 0
//Not thread safe, so should only be used inside the actor that inhabits this ActorCell
override protected def randomName(): String = {
val n = nextNameSequence + 1
nextNameSequence = n
Helpers.base64(n)
}
@inline
final def dispatcher: MessageDispatcher = if (props.dispatcher == Props.defaultDispatcher) system.dispatcher else props.dispatcher
final def isShutdown: Boolean = mailbox.isClosed
@volatile //This must be volatile since it isn't protected by the mailbox status
var mailbox: Mailbox = _
def hasMessages: Boolean = mailbox.hasMessages
final def start(): Unit = {

View file

@ -94,14 +94,9 @@ trait ActorRefFactory {
*/
protected def guardian: ActorRef
private val number = new AtomicLong
protected def randomName(): String
private def randomName: String = {
val l = number.getAndIncrement()
Helpers.base64(l)
}
def actorOf(props: Props): ActorRef = provider.actorOf(systemImpl, props, guardian, randomName, false)
def actorOf(props: Props): ActorRef = provider.actorOf(systemImpl, props, guardian, randomName(), false)
/*
* TODO this will have to go at some point, because creating two actors with

View file

@ -10,8 +10,6 @@ import akka.dispatch._
import akka.util.duration._
import java.net.InetAddress
import com.eaio.uuid.UUID
import akka.util.Duration
import akka.util.ReflectiveAccess
import akka.serialization.Serialization
import akka.remote.RemoteAddress
import org.jboss.netty.akka.util.HashedWheelTimer
@ -25,6 +23,8 @@ import com.typesafe.config.ConfigRoot
import com.typesafe.config.ConfigFactory
import java.lang.reflect.InvocationTargetException
import java.util.concurrent.ConcurrentHashMap
import akka.util.{ Helpers, Duration, ReflectiveAccess }
import java.util.concurrent.atomic.AtomicLong
object ActorSystem {
@ -370,6 +370,9 @@ class ActorSystemImpl(val name: String, _config: Config) extends ActorSystem {
def deathWatch: DeathWatch = provider.deathWatch
def nodename: String = provider.nodename
private final val nextName = new AtomicLong
override protected def randomName(): String = Helpers.base64(nextName.incrementAndGet())
@volatile
private var _serialization: Serialization = _
def serialization = _serialization