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 org.opendaylight.yangtools.concepts.WritableObjects;
16 abstract class AbstractEnvelopeProxy<T extends Message<?, ?>> implements Externalizable {
17 private static final long serialVersionUID = 1L;
19 private long sequence;
22 public AbstractEnvelopeProxy() {
26 AbstractEnvelopeProxy(final Envelope<T> envelope) {
27 message = envelope.getMessage();
28 sequence = envelope.getSequence();
29 retry = envelope.getRetry();
33 public final void writeExternal(final ObjectOutput out) throws IOException {
34 WritableObjects.writeLongs(out, sequence, retry);
35 out.writeObject(message);
38 @SuppressWarnings("unchecked")
40 public final void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
41 final byte header = WritableObjects.readLongHeader(in);
42 sequence = WritableObjects.readFirstLong(in, header);
43 retry = WritableObjects.readSecondLong(in, header);
44 message = (T) in.readObject();
47 abstract Envelope<T> createEnvelope(T message, long sequence, long retry);
49 final Object readResolve() {
50 return createEnvelope(message, sequence, retry);