Add a segmented DataJournal abstraction
[controller.git] / opendaylight / md-sal / sal-akka-segmented-journal / src / main / java / org / opendaylight / controller / akka / segjournal / DataJournal.java
1 /*
2  * Copyright (c) 2020 PANTHEON.tech, s.r.o. 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 package org.opendaylight.controller.akka.segjournal;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.codahale.metrics.Histogram;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.opendaylight.controller.akka.segjournal.SegmentedJournalActor.ReplayMessages;
15 import org.opendaylight.controller.akka.segjournal.SegmentedJournalActor.WriteMessages;
16
17 /**
18  * Abstraction of a data journal. This provides a unified interface towards {@link SegmentedJournalActor}, allowing
19  * specialization for various formats.
20  */
21 abstract class DataJournal {
22     // Mirrors fields from associated actor
23     final @NonNull String persistenceId;
24     private final Histogram messageSize;
25
26     // Tracks largest message size we have observed either during recovery or during write
27     private int largestObservedSize;
28
29     DataJournal(final String persistenceId, final Histogram messageSize) {
30         this.persistenceId = requireNonNull(persistenceId);
31         this.messageSize = requireNonNull(messageSize);
32     }
33
34     final void recordMessageSize(final int size) {
35         messageSize.update(size);
36         updateLargestSize(size);
37     }
38
39     final void updateLargestSize(final int size) {
40         if (size > largestObservedSize) {
41             largestObservedSize = size;
42         }
43     }
44
45     abstract long lastWrittenIndex();
46
47     abstract void commitTo(long index);
48
49     abstract void compactTo(long index);
50
51     abstract void close();
52
53     abstract void handleReplayMessages(ReplayMessages message, long from);
54
55     abstract void handleWriteMessages(WriteMessages message);
56 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.