2015-05-17 12:28:47 +02:00
|
|
|
/**
|
2017-01-04 17:37:10 +01:00
|
|
|
* Copyright (C) 2015-2017 Lightbend Inc. <http://www.lightbend.com>
|
2015-05-17 12:28:47 +02:00
|
|
|
*/
|
|
|
|
|
package akka.cluster.ddata
|
|
|
|
|
|
|
|
|
|
object Key {
|
|
|
|
|
/**
|
|
|
|
|
* Extract the [[Key#id]].
|
|
|
|
|
*/
|
|
|
|
|
def unapply(k: Key[_]): Option[String] = Some(k.id)
|
|
|
|
|
|
|
|
|
|
private[akka]type KeyR = Key[ReplicatedData]
|
|
|
|
|
|
2017-02-07 11:21:56 +01:00
|
|
|
type KeyId = String
|
|
|
|
|
|
2015-05-17 12:28:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Key for the key-value data in [[Replicator]]. The type of the data value
|
|
|
|
|
* is defined in the key. Keys are compared equal if the `id` strings are equal,
|
|
|
|
|
* i.e. use unique identifiers.
|
|
|
|
|
*
|
|
|
|
|
* Specific classes are provided for the built in data types, e.g. [[ORSetKey]],
|
|
|
|
|
* and you can create your own keys.
|
|
|
|
|
*/
|
2017-02-07 11:21:56 +01:00
|
|
|
abstract class Key[+T <: ReplicatedData](val id: Key.KeyId) extends Serializable {
|
2015-05-17 12:28:47 +02:00
|
|
|
|
|
|
|
|
override final def equals(o: Any): Boolean = o match {
|
|
|
|
|
case k: Key[_] ⇒ id == k.id
|
|
|
|
|
case _ ⇒ false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override final def hashCode: Int = id.hashCode
|
|
|
|
|
|
|
|
|
|
override def toString(): String = id
|
|
|
|
|
}
|
|
|
|
|
|