refactoring of persistence implementation and its api
This commit is contained in:
parent
96d393b178
commit
e6222c7cee
19 changed files with 647 additions and 663 deletions
|
|
@ -12,18 +12,19 @@ public class PersistentStateful {
|
|||
|
||||
@inittransactionalstate
|
||||
public void init() {
|
||||
mapState = PersistentState.newMap(new CassandraStorageConfig());
|
||||
vectorState = PersistentState.newVector(new CassandraStorageConfig());
|
||||
refState = PersistentState.newRef(new CassandraStorageConfig());
|
||||
mapState = CassandraStorage.newMap();
|
||||
vectorState = CassandraStorage.newVector();
|
||||
refState = CassandraStorage.newRef();
|
||||
}
|
||||
|
||||
public String getMapState(String key) {
|
||||
return (String) mapState.get(key).get();
|
||||
byte[] bytes = (byte[]) mapState.get(key.getBytes()).get();
|
||||
return new String(bytes, 0, bytes.length);
|
||||
}
|
||||
|
||||
|
||||
public String getVectorState(int index) {
|
||||
return (String) vectorState.get(index);
|
||||
byte[] bytes = (byte[]) vectorState.get(index);
|
||||
return new String(bytes, 0, bytes.length);
|
||||
}
|
||||
|
||||
public int getVectorLength() {
|
||||
|
|
@ -32,62 +33,51 @@ public class PersistentStateful {
|
|||
|
||||
public String getRefState() {
|
||||
if (refState.isDefined()) {
|
||||
return (String) refState.get().get();
|
||||
byte[] bytes = (byte[]) refState.get().get();
|
||||
return new String(bytes, 0, bytes.length);
|
||||
} else throw new IllegalStateException("No such element");
|
||||
}
|
||||
|
||||
|
||||
public void setMapState(String key, String msg) {
|
||||
mapState.put(key, msg);
|
||||
mapState.put(key.getBytes(), msg.getBytes());
|
||||
}
|
||||
|
||||
|
||||
public void setVectorState(String msg) {
|
||||
vectorState.add(msg);
|
||||
vectorState.add(msg.getBytes());
|
||||
}
|
||||
|
||||
|
||||
public void setRefState(String msg) {
|
||||
refState.swap(msg);
|
||||
refState.swap(msg.getBytes());
|
||||
}
|
||||
|
||||
|
||||
public void success(String key, String msg) {
|
||||
mapState.put(key, msg);
|
||||
vectorState.add(msg);
|
||||
refState.swap(msg);
|
||||
mapState.put(key.getBytes(), msg.getBytes());
|
||||
vectorState.add(msg.getBytes());
|
||||
refState.swap(msg.getBytes());
|
||||
}
|
||||
|
||||
|
||||
public String failure(String key, String msg, PersistentFailer failer) {
|
||||
mapState.put(key, msg);
|
||||
vectorState.add(msg);
|
||||
refState.swap(msg);
|
||||
mapState.put(key.getBytes(), msg.getBytes());
|
||||
vectorState.add(msg.getBytes());
|
||||
refState.swap(msg.getBytes());
|
||||
failer.fail();
|
||||
return msg;
|
||||
}
|
||||
|
||||
public String success(String key, String msg, PersistentStatefulNested nested) {
|
||||
mapState.put(key, msg);
|
||||
vectorState.add(msg);
|
||||
refState.swap(msg);
|
||||
mapState.put(key.getBytes(), msg.getBytes());
|
||||
vectorState.add(msg.getBytes());
|
||||
refState.swap(msg.getBytes());
|
||||
nested.success(key, msg);
|
||||
return msg;
|
||||
}
|
||||
|
||||
|
||||
public String failure(String key, String msg, PersistentStatefulNested nested, PersistentFailer failer) {
|
||||
mapState.put(key, msg);
|
||||
vectorState.add(msg);
|
||||
refState.swap(msg);
|
||||
mapState.put(key.getBytes(), msg.getBytes());
|
||||
vectorState.add(msg.getBytes());
|
||||
refState.swap(msg.getBytes());
|
||||
nested.failure(key, msg, failer);
|
||||
return msg;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void thisMethodHangs(String key, String msg, PersistentFailer failer) {
|
||||
setMapState(key, msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue