2015-05-17 12:28:47 +02:00
|
|
|
/**
|
2018-01-04 17:26:29 +00:00
|
|
|
* Copyright (C) 2009-2018 Lightbend Inc. <https://www.lightbend.com>
|
2015-05-17 12:28:47 +02:00
|
|
|
*/
|
2018-03-13 23:45:55 +09:00
|
|
|
|
2015-05-17 12:28:47 +02:00
|
|
|
package akka.cluster.ddata
|
|
|
|
|
|
|
|
|
|
object Flag {
|
|
|
|
|
/**
|
|
|
|
|
* `Flag` that is initialized to `false`.
|
|
|
|
|
*/
|
2018-01-09 04:39:06 -05:00
|
|
|
val empty: Flag = new Flag(false)
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* `Flag` that is initialized to `false`.
|
|
|
|
|
*/
|
|
|
|
|
val Disabled: Flag = empty
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* `Flag` that is initialized to `true`.
|
|
|
|
|
*/
|
|
|
|
|
val Enabled: Flag = new Flag(true)
|
|
|
|
|
|
|
|
|
|
def apply(): Flag = Disabled
|
|
|
|
|
|
2015-05-17 12:28:47 +02:00
|
|
|
/**
|
|
|
|
|
* Java API: `Flag` that is initialized to `false`.
|
|
|
|
|
*/
|
2018-01-09 04:39:06 -05:00
|
|
|
def create(): Flag = Disabled
|
2015-05-17 12:28:47 +02:00
|
|
|
|
|
|
|
|
// unapply from case class
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Implements a boolean flag CRDT that is initialized to `false` and
|
|
|
|
|
* can be switched to `true`. `true` wins over `false` in merge.
|
|
|
|
|
*
|
|
|
|
|
* This class is immutable, i.e. "modifying" methods return a new instance.
|
|
|
|
|
*/
|
|
|
|
|
@SerialVersionUID(1L)
|
|
|
|
|
final case class Flag(enabled: Boolean) extends ReplicatedData with ReplicatedDataSerialization {
|
|
|
|
|
|
|
|
|
|
type T = Flag
|
|
|
|
|
|
|
|
|
|
def switchOn: Flag =
|
|
|
|
|
if (enabled) this
|
2018-01-09 04:39:06 -05:00
|
|
|
else Flag.Enabled
|
2015-05-17 12:28:47 +02:00
|
|
|
|
|
|
|
|
override def merge(that: Flag): Flag =
|
|
|
|
|
if (that.enabled) that
|
|
|
|
|
else this
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
object FlagKey {
|
|
|
|
|
def create(id: String): Key[Flag] = FlagKey(id)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SerialVersionUID(1L)
|
|
|
|
|
final case class FlagKey(_id: String) extends Key[Flag](_id) with ReplicatedDataSerialization
|