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 com.google.common.base.Verify;
11 import java.io.DataInput;
12 import java.io.Externalizable;
13 import java.io.IOException;
14 import java.io.ObjectInput;
15 import java.io.ObjectOutput;
16 import javax.annotation.Nonnull;
17 import org.opendaylight.yangtools.concepts.WritableIdentifier;
18 import org.opendaylight.yangtools.concepts.WritableObjects;
21 * Abstract Externalizable proxy for use with {@link Message} subclasses.
23 * @author Robert Varga
25 * @param <T> Target identifier type
26 * @param <C> Message class
28 abstract class AbstractMessageProxy<T extends WritableIdentifier, C extends Message<T, C>> implements Externalizable {
29 private static final long serialVersionUID = 1L;
31 private long sequence;
33 protected AbstractMessageProxy() {
37 AbstractMessageProxy(final @Nonnull C message) {
38 this.target = message.getTarget();
39 this.sequence = message.getSequence();
43 public void writeExternal(final ObjectOutput out) throws IOException {
45 WritableObjects.writeLong(out, sequence);
49 public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
50 target = Verify.verifyNotNull(readTarget(in));
51 sequence = WritableObjects.readLong(in);
54 protected final Object readResolve() {
55 return Verify.verifyNotNull(createMessage(target, sequence));
58 protected abstract @Nonnull T readTarget(@Nonnull DataInput in) throws IOException;
59 abstract @Nonnull C createMessage(@Nonnull T target, long sequence);