public interface Mutation<T>
Big thanks to Coda Hale from Yammer for this. Modelling your data as logically monotonic makes store operations more predictable in a distributed environment. Basically changing data *based on its contents* and your logic. As the simplest example: Rather than creating a riak object with a value of (say 25) you create a Mutation that adds 1 to whatever value comes from Riak
Allows for a store operation not to occur if the object it is being applied to is not modified.By implementing this interface you can avoid a store operation from occurring if the object it is be applied to is not modified.
For example:
Mutation<IRiakObject> m = new Mutation<IRiakObject>() {
private boolean modified;
@Override
IRiakObject apply(IRiakObject original) {
// I didn't do anything!
modifed = false;
}
@Overrive
boolean hasMutated() {
return modified;
}
};
| Modifier and Type | Method and Description |
|---|---|
T |
apply(T original)
Applies a mutation to the
original value passed in |
boolean |
hasMutated()
Returns true if the mutation has actually created a change that must
be stored back to Riak.
|
T apply(T original)
original value passed inoriginal - the value to update.boolean hasMutated()
Copyright © 2014. All rights reserved.