use of actor4j.core.persistence.ActorPersistenceObject in project actor4j-core by relvaner.
the class ActorCell method saveSnapshot.
@SuppressWarnings("unchecked")
public <S extends ActorPersistenceObject> void saveSnapshot(Consumer<S> onSuccess, Consumer<Exception> onFailure, S state) {
if (system.persistenceMode && state != null) {
state.persistenceId = persistenceId();
List<ActorPersistenceObject> list = new ArrayList<>();
list.add(state);
PersistenceTuple tuple = new PersistenceTuple((Consumer<ActorPersistenceObject>) onSuccess, onFailure, list);
try {
system.messageDispatcher.postPersistence(new ActorMessage<String>(new ObjectMapper().writeValueAsString(state), PersistenceServiceActor.PERSIST_STATE, id, null));
persistenceTuples.offer(tuple);
} catch (JsonProcessingException e) {
e.printStackTrace();
onFailure.accept(e);
}
}
}
use of actor4j.core.persistence.ActorPersistenceObject in project actor4j-core by relvaner.
the class ActorCell method persist.
@SuppressWarnings("unchecked")
public <E extends ActorPersistenceObject> void persist(Consumer<E> onSuccess, Consumer<Exception> onFailure, E... events) {
if (system.persistenceMode && events != null) {
List<ActorPersistenceObject> list = new ArrayList<>(Arrays.asList(events));
for (ActorPersistenceObject obj : list) obj.persistenceId = persistenceId();
PersistenceTuple tuple = new PersistenceTuple((Consumer<ActorPersistenceObject>) onSuccess, onFailure, list);
try {
system.messageDispatcher.postPersistence(new ActorMessage<String>(new ObjectMapper().writeValueAsString(events), PersistenceServiceActor.PERSIST_EVENTS, id, null));
persistenceTuples.offer(tuple);
} catch (JsonProcessingException e) {
e.printStackTrace();
onFailure.accept(e);
}
}
}
Aggregations