2 * Copyright (c) 2016 Cisco Systems, Inc. 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 java.io.Externalizable;
11 import java.io.IOException;
12 import java.io.ObjectInput;
13 import java.io.ObjectOutput;
14 import java.io.Serial;
15 import org.opendaylight.yangtools.concepts.WritableObjects;
17 abstract class AbstractEnvelopeProxy<T extends Message<?, ?>> implements Externalizable {
19 private static final long serialVersionUID = 1L;
22 private long sessionId;
23 private long txSequence;
25 AbstractEnvelopeProxy() {
29 AbstractEnvelopeProxy(final Envelope<T> envelope) {
30 message = envelope.getMessage();
31 txSequence = envelope.getTxSequence();
32 sessionId = envelope.getSessionId();
36 public void writeExternal(final ObjectOutput out) throws IOException {
37 WritableObjects.writeLongs(out, sessionId, txSequence);
38 out.writeObject(message);
41 @SuppressWarnings("unchecked")
43 public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
44 final byte header = WritableObjects.readLongHeader(in);
45 sessionId = WritableObjects.readFirstLong(in, header);
46 txSequence = WritableObjects.readSecondLong(in, header);
47 message = (T) in.readObject();
50 @SuppressWarnings("checkstyle:hiddenField")
51 abstract Envelope<T> createEnvelope(T wrappedNessage, long sessionId, long txSequence);
54 final Object readResolve() {
55 return createEnvelope(message, sessionId, txSequence);