!cdd #17770 Use self recursive type in AbstractReplicatedData (Java API)
* complete the TwoPhaseSet java sample with serialization
This commit is contained in:
parent
49e6e7f38c
commit
da07a2e68e
9 changed files with 315 additions and 26 deletions
|
|
@ -24,6 +24,10 @@ import akka.cluster.UniqueAddress
|
|||
* a new instance.
|
||||
*/
|
||||
trait ReplicatedData {
|
||||
/**
|
||||
* The type of the concrete implementation, e.g. `GSet[A]`.
|
||||
* To be specified by subclass.
|
||||
*/
|
||||
type T <: ReplicatedData
|
||||
|
||||
/**
|
||||
|
|
@ -34,14 +38,26 @@ trait ReplicatedData {
|
|||
}
|
||||
|
||||
/**
|
||||
* Java API: Interface for implementing a [[ReplicatedData]] in
|
||||
* Java.
|
||||
* Java API: Interface for implementing a [[ReplicatedData]] in Java.
|
||||
*
|
||||
* The type parameter `D` is a self-recursive type to be defined by the
|
||||
* concrete implementation.
|
||||
* E.g. `class TwoPhaseSet extends AbstractReplicatedData<TwoPhaseSet>`
|
||||
*/
|
||||
abstract class AbstractReplicatedData extends ReplicatedData {
|
||||
// it is not possible to use a more strict type, because it is erased somehow, and
|
||||
// the implementation is anyway required to implement
|
||||
// merge(that: ReplicatedData): ReplicatedData
|
||||
type T = AbstractReplicatedData
|
||||
abstract class AbstractReplicatedData[D <: AbstractReplicatedData[D]] extends ReplicatedData {
|
||||
|
||||
override type T = ReplicatedData
|
||||
|
||||
/**
|
||||
* Delegates to [[#mergeData]], which must be implemented by subclass.
|
||||
*/
|
||||
final override def merge(that: ReplicatedData): ReplicatedData =
|
||||
mergeData(that.asInstanceOf[D])
|
||||
|
||||
/**
|
||||
* Java API: Monotonic merge function.
|
||||
*/
|
||||
def mergeData(that: D): D
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -52,7 +68,7 @@ abstract class AbstractReplicatedData extends ReplicatedData {
|
|||
* used by the [[Replicator]] to collapse data from the removed node
|
||||
* into some other node in the cluster.
|
||||
*/
|
||||
trait RemovedNodePruning { this: ReplicatedData ⇒
|
||||
trait RemovedNodePruning extends ReplicatedData {
|
||||
|
||||
/**
|
||||
* Does it have any state changes from a specific node,
|
||||
|
|
|
|||
|
|
@ -5,10 +5,11 @@ package akka.cluster.ddata;
|
|||
|
||||
import akka.cluster.UniqueAddress;
|
||||
|
||||
public class JavaImplOfReplicatedData extends AbstractReplicatedData implements RemovedNodePruning {
|
||||
public class JavaImplOfReplicatedData extends AbstractReplicatedData<JavaImplOfReplicatedData> implements
|
||||
RemovedNodePruning {
|
||||
|
||||
@Override
|
||||
public JavaImplOfReplicatedData merge(ReplicatedData other) {
|
||||
public JavaImplOfReplicatedData mergeData(JavaImplOfReplicatedData other) {
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue