use of io.siddhi.core.util.snapshot.AsyncIncrementalSnapshotPersistor in project siddhi by wso2.
the class PersistenceHelper method persist.
public static PersistenceReference persist(IncrementalSnapshot serializeObj, SiddhiAppContext siddhiAppContext) {
long revisionTime = System.currentTimeMillis();
List<Future> incrementalFutures = new ArrayList<>();
// Periodic state
Map<String, Map<String, byte[]>> periodicStateBase = serializeObj.getPeriodicState();
if (periodicStateBase != null) {
periodicStateBase.forEach((partitionId, value) -> {
value.forEach((id, value1) -> {
String[] items = id.split(PersistenceConstants.REVISION_SEPARATOR);
AsyncIncrementalSnapshotPersistor asyncIncrementSnapshotPersistor = new AsyncIncrementalSnapshotPersistor(value1, siddhiAppContext.getSiddhiContext().getIncrementalPersistenceStore(), new IncrementalSnapshotInfo(siddhiAppContext.getName(), partitionId, items[1], items[2], revisionTime, IncrementalSnapshotInfo.SnapshotType.PERIODIC, items[0]));
Future future = siddhiAppContext.getExecutorService().submit(asyncIncrementSnapshotPersistor);
incrementalFutures.add(future);
});
});
}
// Incremental base state
Map<String, Map<String, byte[]>> incrementalStateBase = serializeObj.getIncrementalStateBase();
if (incrementalStateBase != null) {
incrementalStateBase.forEach((partitionId, value) -> {
value.forEach((id, value1) -> {
String[] items = id.split(PersistenceConstants.REVISION_SEPARATOR);
AsyncIncrementalSnapshotPersistor asyncIncrementSnapshotPersistor = new AsyncIncrementalSnapshotPersistor(value1, siddhiAppContext.getSiddhiContext().getIncrementalPersistenceStore(), new IncrementalSnapshotInfo(siddhiAppContext.getName(), partitionId, items[1], items[2], revisionTime, IncrementalSnapshotInfo.SnapshotType.BASE, items[0]));
Future future = siddhiAppContext.getExecutorService().submit(asyncIncrementSnapshotPersistor);
incrementalFutures.add(future);
});
});
}
// Next, handle the increment persistence scenarios
// Incremental state
Map<String, Map<String, byte[]>> incrementalState = serializeObj.getIncrementalState();
if (incrementalState != null) {
incrementalState.forEach((partitionId, value) -> {
value.forEach((id, value1) -> {
String[] items = id.split(PersistenceConstants.REVISION_SEPARATOR);
AsyncIncrementalSnapshotPersistor asyncIncrementSnapshotPersistor = new AsyncIncrementalSnapshotPersistor(value1, siddhiAppContext.getSiddhiContext().getIncrementalPersistenceStore(), new IncrementalSnapshotInfo(siddhiAppContext.getName(), partitionId, items[1], items[2], revisionTime, IncrementalSnapshotInfo.SnapshotType.INCREMENT, items[0]));
Future future = siddhiAppContext.getExecutorService().submit(asyncIncrementSnapshotPersistor);
incrementalFutures.add(future);
});
});
}
return new PersistenceReference(incrementalFutures, revisionTime + PersistenceConstants.REVISION_SEPARATOR + siddhiAppContext.getName());
}
Aggregations