2 * Copyright (c) 2020 PANTHEON.tech, s.r.o. 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.akka.segjournal;
10 import static java.util.Objects.requireNonNull;
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;
18 * Abstraction of a data journal. This provides a unified interface towards {@link SegmentedJournalActor}, allowing
19 * specialization for various formats.
21 abstract class DataJournal {
22 // Mirrors fields from associated actor
23 final @NonNull String persistenceId;
24 private final Histogram messageSize;
26 // Tracks largest message size we have observed either during recovery or during write
27 private int largestObservedSize;
29 DataJournal(final String persistenceId, final Histogram messageSize) {
30 this.persistenceId = requireNonNull(persistenceId);
31 this.messageSize = requireNonNull(messageSize);
34 final void recordMessageSize(final int size) {
35 messageSize.update(size);
36 updateLargestSize(size);
39 final void updateLargestSize(final int size) {
40 if (size > largestObservedSize) {
41 largestObservedSize = size;
45 abstract long lastWrittenIndex();
47 abstract void commitTo(long index);
49 abstract void compactTo(long index);
51 abstract void close();
53 abstract void handleReplayMessages(ReplayMessages message, long from);
55 abstract void handleWriteMessages(WriteMessages message);