Bug 7521: Convert byte[] to ShardManagerSnapshot in DatastoreSnapshot
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / messages / CloseTransactionChain.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.controller.cluster.datastore.messages;
10
11 import com.google.common.base.Preconditions;
12 import java.io.IOException;
13 import java.io.ObjectInput;
14 import java.io.ObjectOutput;
15 import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier;
16 import org.opendaylight.yangtools.concepts.Identifiable;
17
18 public class CloseTransactionChain extends VersionedExternalizableMessage
19         implements Identifiable<LocalHistoryIdentifier> {
20     private static final long serialVersionUID = 1L;
21
22     private LocalHistoryIdentifier transactionChainId;
23
24     public CloseTransactionChain() {
25     }
26
27     public CloseTransactionChain(final LocalHistoryIdentifier transactionChainId, final short version) {
28         super(version);
29         this.transactionChainId = Preconditions.checkNotNull(transactionChainId);
30     }
31
32     @Override
33     public LocalHistoryIdentifier getIdentifier() {
34         return transactionChainId;
35     }
36
37     @Override
38     public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
39         super.readExternal(in);
40         transactionChainId = LocalHistoryIdentifier.readFrom(in);
41     }
42
43     @Override
44     public void writeExternal(ObjectOutput out) throws IOException {
45         super.writeExternal(out);
46         transactionChainId.writeTo(out);
47     }
48
49     public static CloseTransactionChain fromSerializable(final Object serializable) {
50         Preconditions.checkArgument(serializable instanceof CloseTransactionChain);
51         return (CloseTransactionChain)serializable;
52     }
53
54     public static boolean isSerializedType(Object message) {
55         return message instanceof CloseTransactionChain;
56     }
57 }