Skip to content

Instantly share code, notes, and snippets.

@lucperkins
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucperkins/37ff38f45b319a23b823 to your computer and use it in GitHub Desktop.
Save lucperkins/37ff38f45b319a23b823 to your computer and use it in GitHub Desktop.
Conflict resolution example
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