2a52eccb94e84c1035590004b9a051a3b57c15d2
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / persisted / FrontendHistoryMetadata.java
1 /*
2  * Copyright (c) 2016 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 package org.opendaylight.controller.cluster.datastore.persisted;
9
10 import com.google.common.base.MoreObjects;
11 import java.io.DataInput;
12 import java.io.DataOutput;
13 import java.io.IOException;
14 import org.opendaylight.yangtools.concepts.WritableObject;
15 import org.opendaylight.yangtools.concepts.WritableObjects;
16
17 public final class FrontendHistoryMetadata implements WritableObject {
18     private final long historyId;
19     private final long cookie;
20     private final long nextTransaction;
21     private final boolean closed;
22
23     public FrontendHistoryMetadata(final long historyId, final long cookie, final long nextTransaction,
24             final boolean closed) {
25         this.historyId = historyId;
26         this.cookie = cookie;
27         this.nextTransaction = nextTransaction;
28         this.closed = closed;
29     }
30
31     public long getHistoryId() {
32         return historyId;
33     }
34
35     public long getCookie() {
36         return cookie;
37     }
38
39     public long getNextTransaction() {
40         return nextTransaction;
41     }
42
43     public boolean isClosed() {
44         return closed;
45     }
46
47     @Override
48     public void writeTo(final DataOutput out) throws IOException {
49         WritableObjects.writeLongs(out, historyId, cookie);
50         WritableObjects.writeLong(out, nextTransaction);
51         out.writeBoolean(closed);
52     }
53
54     public static FrontendHistoryMetadata readFrom(final DataInput in) throws IOException {
55         final byte header = WritableObjects.readLongHeader(in);
56         final long historyId = WritableObjects.readFirstLong(in, header);
57         final long cookie = WritableObjects.readSecondLong(in, header);
58         final long nextTransaction = WritableObjects.readLong(in);
59         final boolean closed = in.readBoolean();
60
61         return new FrontendHistoryMetadata(historyId, cookie, nextTransaction, closed);
62     }
63
64     @Override
65     public String toString() {
66         return MoreObjects.toStringHelper(FrontendHistoryMetadata.class).add("historiId", historyId)
67                 .add("cookie", cookie).add("nextTransaction", nextTransaction).add("closed", closed).toString();
68     }
69 }