2015-05-17 12:28:47 +02:00
|
|
|
/**
|
2017-01-04 17:37:10 +01:00
|
|
|
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
|
2015-05-17 12:28:47 +02:00
|
|
|
*/
|
|
|
|
|
package akka.cluster.ddata
|
|
|
|
|
|
|
|
|
|
import akka.actor.Address
|
|
|
|
|
import akka.cluster.Member
|
|
|
|
|
import akka.cluster.UniqueAddress
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* INTERNAL API
|
|
|
|
|
*/
|
|
|
|
|
private[akka] object PruningState {
|
2017-01-11 13:19:45 +01:00
|
|
|
final case class PruningInitialized(owner: UniqueAddress, seen: Set[Address]) extends PruningState {
|
|
|
|
|
override def addSeen(node: Address): PruningState = {
|
|
|
|
|
if (seen(node) || owner.address == node) this
|
|
|
|
|
else copy(seen = seen + node)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
final case class PruningPerformed(obsoleteTime: Long) extends PruningState {
|
|
|
|
|
def isObsolete(currentTime: Long): Boolean = obsoleteTime <= currentTime
|
|
|
|
|
}
|
2015-05-17 12:28:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* INTERNAL API
|
|
|
|
|
*/
|
2017-01-11 13:19:45 +01:00
|
|
|
private[akka] sealed trait PruningState {
|
2015-05-17 12:28:47 +02:00
|
|
|
import PruningState._
|
|
|
|
|
|
|
|
|
|
def merge(that: PruningState): PruningState =
|
2017-01-11 13:19:45 +01:00
|
|
|
(this, that) match {
|
|
|
|
|
case (p1: PruningPerformed, p2: PruningPerformed) ⇒ if (p1.obsoleteTime >= p2.obsoleteTime) this else that
|
|
|
|
|
case (_: PruningPerformed, _) ⇒ this
|
|
|
|
|
case (_, _: PruningPerformed) ⇒ that
|
|
|
|
|
case (PruningInitialized(thisOwner, thisSeen), PruningInitialized(thatOwner, thatSeen)) ⇒
|
|
|
|
|
if (thisOwner == thatOwner)
|
|
|
|
|
PruningInitialized(thisOwner, thisSeen union thatSeen)
|
|
|
|
|
else if (Member.addressOrdering.compare(thisOwner.address, thatOwner.address) > 0)
|
2015-05-17 12:28:47 +02:00
|
|
|
that
|
|
|
|
|
else
|
|
|
|
|
this
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-11 13:19:45 +01:00
|
|
|
def addSeen(node: Address): PruningState = this
|
2015-05-17 12:28:47 +02:00
|
|
|
}
|
|
|
|
|
|