blob: 97fd60a52bbeede4dab6317c36db18e3f93ae38f [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2014-present Open Networking Laboratory
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.store.serializers;
Ayaka Koshibe84411362014-10-01 09:33:42 -070017
Yuta HIGUCHId08e2e92016-07-10 00:15:10 -070018import static org.onosproject.store.serializers.NodeIdSerializer.nodeIdSerializer;
19
Brian O'Connorabafb502014-12-02 22:26:20 -080020import org.onosproject.cluster.NodeId;
21import org.onosproject.mastership.MastershipTerm;
Yuta HIGUCHI80912e62014-10-12 00:15:47 -070022
Ayaka Koshibe84411362014-10-01 09:33:42 -070023import com.esotericsoftware.kryo.Kryo;
24import com.esotericsoftware.kryo.Serializer;
25import com.esotericsoftware.kryo.io.Input;
26import com.esotericsoftware.kryo.io.Output;
27
28/**
Brian O'Connorabafb502014-12-02 22:26:20 -080029 * Kryo Serializer for {@link org.onosproject.mastership.MastershipTerm}.
Ayaka Koshibe84411362014-10-01 09:33:42 -070030 */
Yuta HIGUCHId08e2e92016-07-10 00:15:10 -070031public final class MastershipTermSerializer extends Serializer<MastershipTerm> {
Ayaka Koshibe84411362014-10-01 09:33:42 -070032
Yuta HIGUCHI03fec1f2014-10-03 09:13:50 -070033 /**
34 * Creates {@link MastershipTerm} serializer instance.
35 */
36 public MastershipTermSerializer() {
37 // non-null, immutable
38 super(false, true);
39 }
40
Ayaka Koshibe84411362014-10-01 09:33:42 -070041 @Override
42 public MastershipTerm read(Kryo kryo, Input input, Class<MastershipTerm> type) {
Yuta HIGUCHId08e2e92016-07-10 00:15:10 -070043 final NodeId node = kryo.readObjectOrNull(input, NodeId.class, nodeIdSerializer());
Madan Jampani15d773c2015-02-25 15:31:55 -080044 final long term = input.readLong();
Ayaka Koshibe84411362014-10-01 09:33:42 -070045 return MastershipTerm.of(node, term);
46 }
47
48 @Override
49 public void write(Kryo kryo, Output output, MastershipTerm object) {
Yuta HIGUCHId08e2e92016-07-10 00:15:10 -070050 kryo.writeObjectOrNull(output, object.master(), nodeIdSerializer());
Madan Jampani15d773c2015-02-25 15:31:55 -080051 output.writeLong(object.termNumber());
Ayaka Koshibe84411362014-10-01 09:33:42 -070052 }
Ayaka Koshibe84411362014-10-01 09:33:42 -070053}