Fix followerDistributedDataStore tear down
[controller.git] / opendaylight / md-sal / sal-clustering-commons / src / main / java / org / opendaylight / controller / cluster / DataPersistenceProvider.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.controller.cluster;
10
11 import akka.japi.Procedure;
12 import akka.persistence.JournalProtocol;
13 import akka.persistence.SnapshotProtocol;
14 import akka.persistence.SnapshotSelectionCriteria;
15 import org.eclipse.jdt.annotation.NonNull;
16
17 /**
18  * DataPersistenceProvider provides methods to persist data and is an abstraction of the akka-persistence persistence
19  * API.
20  */
21 public interface DataPersistenceProvider {
22
23     /**
24      * Returns whether or not persistence recovery is applicable/enabled.
25      *
26      * @return true if recovery is applicable, otherwise false, in which case the provider is not persistent and may
27      *         not have anything to be recovered
28      */
29     boolean isRecoveryApplicable();
30
31     /**
32      * Persists an entry to the applicable journal synchronously.
33      *
34      * @param entry the journal entry to persist
35      * @param procedure the callback when persistence is complete
36      * @param <T> the type of the journal entry
37      */
38     <T> void persist(T entry, Procedure<T> procedure);
39
40     /**
41      * Persists an entry to the applicable journal asynchronously.
42      *
43      * @param entry the journal entry to persist
44      * @param procedure the callback when persistence is complete
45      * @param <T> the type of the journal entry
46      */
47     <T> void persistAsync(T entry, Procedure<T> procedure);
48
49     /**
50      * Saves a snapshot.
51      *
52      * @param snapshot the snapshot object to save
53      */
54     void saveSnapshot(Object snapshot);
55
56     /**
57      * Deletes snapshots based on the given criteria.
58      *
59      * @param criteria the search criteria
60      */
61     void deleteSnapshots(SnapshotSelectionCriteria criteria);
62
63     /**
64      * Deletes journal entries up to the given sequence number.
65      *
66      * @param sequenceNumber the sequence number
67      */
68     void deleteMessages(long sequenceNumber);
69
70     /**
71      * Returns the last sequence number contained in the journal.
72      *
73      * @return the last sequence number
74      */
75     long getLastSequenceNumber();
76
77     /**
78      * Receive and potentially handle a {@link JournalProtocol} response.
79      *
80      * @param response A {@link JournalProtocol} response
81      * @return {@code true} if the response was handled
82      */
83     boolean handleJournalResponse(JournalProtocol.@NonNull Response response);
84
85     /**
86      * Receive and potentially handle a {@link SnapshotProtocol} response.
87      *
88      * @param response A {@link SnapshotProtocol} response
89      * @return {@code true} if the response was handled
90      */
91     boolean handleSnapshotResponse(SnapshotProtocol.@NonNull Response response);
92 }