public IncrementalSnapshot incrementalSnapshot() {
        try {
            SnapshotRequest.requestForFullSnapshot(false);
            Map<String, Map<String, byte[]>> incrementalSnapshotMap = new HashMap<>();
            Map<String, Map<String, byte[]>> incrementalBaseSnapshotMap = new HashMap<>();
            Map<String, Map<String, byte[]>> periodicSnapshotMap = new HashMap<>();
            if (log.isDebugEnabled()) {
                log.debug("Taking snapshot ...");
            }
            try {
                threadBarrier.lock();
                waitForSystemStabilization();
                for (Map.Entry<String, PartitionIdStateHolder> partitionIdState : partitionIdStates.entrySet()) {
                    for (Map.Entry<String, ElementStateHolder> queryState :
                            partitionIdState.getValue().queryStateHolderMap.entrySet()) {
                        for (Map.Entry<String, StateHolder> elementState :
                                queryState.getValue().elementHolderMap.entrySet()) {
                            Map<String, Map<String, State>> partitionKeyStates = elementState.getValue().getAllStates();
                            try {
                                for (Map.Entry<String, Map<String, State>> partitionKeyState :
                                        partitionKeyStates.entrySet()) {
                                    for (Map.Entry<String, State> groupByKeyState :
                                            partitionKeyState.getValue().entrySet()) {
                                        State state = groupByKeyState.getValue();
                                        Map<String, Object> itemStates = state.snapshot();
                                        if (itemStates != null) {
                                            Map<String, Object> itemSnapshotsIncremental = new HashMap<>();
                                            Map<String, Object> itemSnapshotsIncrementalBase = new HashMap<>();
                                            Map<String, Object> itemSnapshotsPeriodic = new HashMap<>();
                                            for (Map.Entry<String, Object> itemState : itemStates.entrySet()) {
                                                if (itemState.getValue() instanceof Snapshot) {
                                                    if (((Snapshot) itemState.getValue()).isIncrementalSnapshot()) {
                                                        itemSnapshotsIncremental.put(itemState.getKey(),
                                                                itemState.getValue());
                                                    } else {
                                                        itemSnapshotsIncrementalBase.put(
                                                                itemState.getKey(), itemState.getValue());
                                                    }
                                                } else {
                                                    itemSnapshotsPeriodic.put(itemState.getKey(), itemState.getValue());
                                                }
                                            }
                                            if (!itemSnapshotsIncremental.isEmpty()) {
                                                addToSnapshotIncrements(incrementalSnapshotMap, partitionIdState,
                                                        queryState, elementState, partitionKeyState, groupByKeyState,
                                                        itemSnapshotsIncremental);
                                            }
                                            if (!itemSnapshotsIncrementalBase.isEmpty()) {
                                                addToSnapshotIncrements(incrementalBaseSnapshotMap, partitionIdState,
                                                        queryState, elementState, partitionKeyState, groupByKeyState,
                                                        itemSnapshotsIncrementalBase);
                                            }
                                            if (!itemSnapshotsPeriodic.isEmpty()) {
                                                addToSnapshotIncrements(periodicSnapshotMap, partitionIdState,
                                                        queryState, elementState, partitionKeyState, groupByKeyState,
                                                        itemSnapshotsPeriodic);
                                            }
                                        }
                                    }
                                }
                            } finally {
                                elementState.getValue().returnAllStates(partitionKeyStates);
                            }
                        }
                    }
                }

            } finally {
                threadBarrier.unlock();
            }
            if (log.isDebugEnabled()) {
                log.debug("Snapshot taken for Siddhi app '" + siddhiAppContext.getName() + "'");
            }
            IncrementalSnapshot snapshot = new IncrementalSnapshot();
            if (!incrementalSnapshotMap.isEmpty()) {
                snapshot.setIncrementalState(incrementalSnapshotMap);
            }
            if (!incrementalBaseSnapshotMap.isEmpty()) {
                snapshot.setIncrementalStateBase(incrementalBaseSnapshotMap);
            }
            if (!periodicSnapshotMap.isEmpty()) {
                snapshot.setPeriodicState(periodicSnapshotMap);
            }
            return snapshot;
        } finally {
            SnapshotRequest.requestForFullSnapshot(false);
        }
    }
Service level implementation to take/restore snapshots of processing elements.
Memory   : PartitionId + QueryName + ElementId + PartitionGroupByKey + Item
Snapshot : PartitionId + PartitionGroupByKey + QueryName + ElementId + Item
modules/siddhi-core/src/main/java/io/siddhi/core/util/snapshot/SnapshotService.java