2013-04-11 09:18:12 +02:00
|
|
|
/**
|
2016-02-23 12:58:39 +01:00
|
|
|
* Copyright (C) 2009-2016 Lightbend Inc. <http://www.lightbend.com>
|
2013-04-11 09:18:12 +02:00
|
|
|
*/
|
|
|
|
|
package akka.remote
|
|
|
|
|
|
2015-09-25 08:39:02 +02:00
|
|
|
import java.util.concurrent.ThreadLocalRandom
|
2013-04-11 09:18:12 +02:00
|
|
|
import akka.actor.ActorSystem
|
|
|
|
|
import akka.actor.ExtendedActorSystem
|
|
|
|
|
import akka.actor.Extension
|
|
|
|
|
import akka.actor.ExtensionId
|
|
|
|
|
import akka.actor.ExtensionIdProvider
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Extension that holds a uid that is assigned as a random `Int`.
|
|
|
|
|
* The uid is intended to be used together with an [[akka.actor.Address]]
|
|
|
|
|
* to be able to distinguish restarted actor system using the same host
|
|
|
|
|
* and port.
|
|
|
|
|
*/
|
|
|
|
|
object AddressUidExtension extends ExtensionId[AddressUidExtension] with ExtensionIdProvider {
|
|
|
|
|
override def get(system: ActorSystem): AddressUidExtension = super.get(system)
|
|
|
|
|
|
|
|
|
|
override def lookup = AddressUidExtension
|
|
|
|
|
|
|
|
|
|
override def createExtension(system: ExtendedActorSystem): AddressUidExtension = new AddressUidExtension(system)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class AddressUidExtension(val system: ExtendedActorSystem) extends Extension {
|
2016-05-25 12:28:44 +02:00
|
|
|
val longAddressUid: Long = {
|
|
|
|
|
// FIXME we should use a long here, but then we need to change in Cluster and RemoteWatcher also
|
|
|
|
|
//ThreadLocalRandom.current.nextLong()
|
|
|
|
|
ThreadLocalRandom.current.nextInt()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@deprecated("Use longAddressUid instead", "2.4.x")
|
|
|
|
|
val addressUid: Int = longAddressUid.toInt
|
|
|
|
|
}
|