Improve segmented journal actor metrics
[controller.git] / opendaylight / md-sal / sal-akka-segmented-journal / src / main / java / org / opendaylight / controller / akka / segjournal / DataJournalEntry.java
1 /*
2  * Copyright (c) 2019 Pantheon Technologies, 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 akka.persistence.PersistentRepr;
13
14 /**
15  * A single entry in the data journal. We do not store {@code persistenceId} for each entry, as that is a
16  * journal-invariant, nor do we store {@code sequenceNr}, as that information is maintained by a particular journal
17  * segment's index.
18  */
19 abstract sealed class DataJournalEntry {
20     /**
21      * A single data journal entry on its way to the backing file.
22      */
23     static final class ToPersistence extends DataJournalEntry {
24         private final PersistentRepr repr;
25
26         ToPersistence(final PersistentRepr repr) {
27             this.repr = requireNonNull(repr);
28         }
29
30         PersistentRepr repr() {
31             return repr;
32         }
33     }
34
35     /**
36      * A single data journal entry on its way from the backing file.
37      */
38     static final class FromPersistence extends DataJournalEntry {
39         private final String manifest;
40         private final String writerUuid;
41         private final Object payload;
42
43         FromPersistence(final String manifest, final String writerUuid, final Object payload) {
44             this.manifest = manifest;
45             this.writerUuid = requireNonNull(writerUuid);
46             this.payload = requireNonNull(payload);
47         }
48
49         PersistentRepr toRepr(final String persistenceId, final long sequenceNr) {
50             return PersistentRepr.apply(payload, sequenceNr, persistenceId, manifest, false, null, writerUuid);
51         }
52     }
53 }