Search in sources :

Example 1 with AsyncIncrementalSnapshotPersistor

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());
}
Also used : AsyncIncrementalSnapshotPersistor(io.siddhi.core.util.snapshot.AsyncIncrementalSnapshotPersistor) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) Map(java.util.Map) PersistenceReference(io.siddhi.core.util.snapshot.PersistenceReference)

Aggregations

AsyncIncrementalSnapshotPersistor (io.siddhi.core.util.snapshot.AsyncIncrementalSnapshotPersistor)1 PersistenceReference (io.siddhi.core.util.snapshot.PersistenceReference)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Future (java.util.concurrent.Future)1