2 * Copyright (c) 2022 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.cluster.access.concepts;
10 import static com.google.common.base.Verify.verifyNotNull;
11 import static java.util.Objects.requireNonNull;
13 import java.io.Externalizable;
14 import java.io.IOException;
15 import java.io.ObjectInput;
16 import java.io.ObjectOutput;
17 import org.opendaylight.yangtools.concepts.WritableObjects;
20 * Serialization proxy for {@link LocalHistoryIdentifier}.
23 * cookie is currently required only for module-based sharding, which is implemented as part of normal
24 * DataBroker interfaces. For DOMDataTreeProducer cookie will always be zero, hence we may end up not needing
26 * We use WritableObjects.writeLongs() to output historyId and cookie (in that order). If we end up not needing
27 * the cookie at all, we can switch to writeLong() and use zero flags for compatibility.
29 final class HI implements Externalizable {
31 private static final long serialVersionUID = 1L;
33 private LocalHistoryIdentifier identifier;
35 @SuppressWarnings("checkstyle:RedundantModifier")
40 HI(final LocalHistoryIdentifier identifier) {
41 this.identifier = requireNonNull(identifier);
45 public void writeExternal(final ObjectOutput out) throws IOException {
46 identifier.getClientId().writeTo(out);
47 WritableObjects.writeLongs(out, identifier.getHistoryId(), identifier.getCookie());
51 public void readExternal(final ObjectInput in) throws IOException {
52 final var clientId = ClientIdentifier.readFrom(in);
53 final byte header = WritableObjects.readLongHeader(in);
54 final var historyId = WritableObjects.readFirstLong(in, header);
55 final var cookie = WritableObjects.readSecondLong(in, header);
56 identifier = new LocalHistoryIdentifier(clientId, historyId, cookie);
60 private Object readResolve() {
61 return verifyNotNull(identifier);