Last active
August 29, 2015 14:06
-
-
Save lucperkins/37ff38f45b319a23b823 to your computer and use it in GitHub Desktop.
Conflict resolution example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Person { | |
private String name; | |
private int age; | |
public Person() {} | |
public Person(String name, int age) { | |
this.name = name; | |
this.age = age; | |
} | |
@JsonProperty | |
public String getName() { | |
return name; | |
} | |
@JsonProperty | |
public int getAge() { | |
return age; | |
} | |
@RiakVClock | |
VClock vClock; | |
} | |
public static class PersonResolver implements ConflictResolver<Person> { | |
@Override | |
public Person resolve(List<Person> siblings) { | |
if (siblings.size() == 0) { | |
return null; | |
} else if (siblings.size() == 1) { | |
return siblings.get(0); | |
} else { | |
int last = siblings.size() - 1; | |
return siblings.get(last); | |
} | |
} | |
} | |
public class Main { | |
public static void main(String[] args) { | |
RiakClient client = // build nodes, cluster, and client | |
ConflictResolverFactory.getInstance().registerConflictResolver(Person.class, new PersonResolver()); | |
FetchValue fetch = new FetchValue.Builder(location) | |
.build(); | |
Person p = client.execute(fetch).getValue(Person.class); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment