2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.cluster.raft;
10 import static java.util.Objects.requireNonNull;
12 import org.apache.pekko.japi.Procedure;
13 import org.apache.pekko.persistence.AbstractPersistentActor;
14 import org.apache.pekko.persistence.DeleteMessagesSuccess;
15 import org.apache.pekko.persistence.DeleteSnapshotsSuccess;
16 import org.apache.pekko.persistence.JournalProtocol;
17 import org.apache.pekko.persistence.SnapshotProtocol;
18 import org.apache.pekko.persistence.SnapshotSelectionCriteria;
19 import org.opendaylight.controller.cluster.raft.spi.DataPersistenceProvider;
22 * A DataPersistenceProvider implementation with persistence enabled.
24 // Non-final for testing
25 class PersistentDataProvider implements DataPersistenceProvider {
26 private final AbstractPersistentActor persistentActor;
28 PersistentDataProvider(final AbstractPersistentActor persistentActor) {
29 this.persistentActor = requireNonNull(persistentActor, "persistentActor can't be null");
33 public boolean isRecoveryApplicable() {
38 public <T> void persist(final T entry, final Procedure<T> procedure) {
39 persistentActor.persist(entry, procedure);
43 public <T> void persistAsync(final T entry, final Procedure<T> procedure) {
44 persistentActor.persistAsync(entry, procedure);
48 public void saveSnapshot(final Object snapshot) {
49 persistentActor.saveSnapshot(snapshot);
53 public void deleteSnapshots(final SnapshotSelectionCriteria criteria) {
54 persistentActor.deleteSnapshots(criteria);
58 public void deleteMessages(final long sequenceNumber) {
59 persistentActor.deleteMessages(sequenceNumber);
63 public long getLastSequenceNumber() {
64 return persistentActor.lastSequenceNr();
68 public boolean handleJournalResponse(final JournalProtocol.Response response) {
69 return response instanceof DeleteMessagesSuccess;
73 public boolean handleSnapshotResponse(final SnapshotProtocol.Response response) {
74 return response instanceof DeleteSnapshotsSuccess;