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 static com.google.common.base.Verify.verifyNotNull;
12 import java.io.DataInput;
13 import java.io.Externalizable;
14 import java.io.IOException;
15 import java.io.ObjectInput;
16 import java.io.ObjectOutput;
17 import org.eclipse.jdt.annotation.NonNull;
18 import org.opendaylight.yangtools.concepts.WritableIdentifier;
19 import org.opendaylight.yangtools.concepts.WritableObjects;
22 * Abstract Externalizable proxy for use with {@link Message} subclasses.
24 * @author Robert Varga
26 * @param <T> Target identifier type
27 * @param <C> Message class
29 abstract class AbstractMessageProxy<T extends WritableIdentifier, C extends Message<T, C>> implements Externalizable {
30 private static final long serialVersionUID = 1L;
32 private long sequence;
34 protected AbstractMessageProxy() {
38 AbstractMessageProxy(final @NonNull C message) {
39 this.target = message.getTarget();
40 this.sequence = message.getSequence();
44 public void writeExternal(final ObjectOutput out) throws IOException {
46 WritableObjects.writeLong(out, sequence);
50 public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
51 target = verifyNotNull(readTarget(in));
52 sequence = WritableObjects.readLong(in);
55 protected final Object readResolve() {
56 return verifyNotNull(createMessage(target, sequence));
59 protected abstract @NonNull T readTarget(@NonNull DataInput in) throws IOException;
61 abstract @NonNull C createMessage(@NonNull T msgTarget, long msgSequence);