blob: eb1b2b55ecef9ad1edcf70a4381df1ff9a38e047 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
Ray Milkey34c95902015-04-15 09:47:53 -07002 * Copyright 2014-2015 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'Connor6de2e202015-05-21 14:30:41 -070016package org.onosproject.store.serializers.custom;
Yuta HIGUCHI273dcc82014-10-03 00:32:12 -070017
Brian O'Connorabafb502014-12-02 22:26:20 -080018import org.onosproject.store.impl.MastershipBasedTimestamp;
Yuta HIGUCHI273dcc82014-10-03 00:32:12 -070019
20import com.esotericsoftware.kryo.Kryo;
21import com.esotericsoftware.kryo.Serializer;
22import com.esotericsoftware.kryo.io.Input;
23import com.esotericsoftware.kryo.io.Output;
24
25// To be used if Timestamp ever needs to cross bundle boundary.
26/**
27 * Kryo Serializer for {@link MastershipBasedTimestamp}.
28 */
29public class MastershipBasedTimestampSerializer extends Serializer<MastershipBasedTimestamp> {
30
31 /**
Yuta HIGUCHI3e0b6512014-10-07 17:43:56 -070032 * Creates a serializer for {@link MastershipBasedTimestamp}.
Yuta HIGUCHI273dcc82014-10-03 00:32:12 -070033 */
34 public MastershipBasedTimestampSerializer() {
35 // non-null, immutable
36 super(false, true);
37 }
38
39 @Override
40 public void write(Kryo kryo, Output output, MastershipBasedTimestamp object) {
Madan Jampani15d773c2015-02-25 15:31:55 -080041 output.writeLong(object.termNumber());
42 output.writeLong(object.sequenceNumber());
Yuta HIGUCHI273dcc82014-10-03 00:32:12 -070043 }
44
45 @Override
46 public MastershipBasedTimestamp read(Kryo kryo, Input input, Class<MastershipBasedTimestamp> type) {
Madan Jampani15d773c2015-02-25 15:31:55 -080047 final long term = input.readLong();
48 final long sequence = input.readLong();
Yuta HIGUCHI273dcc82014-10-03 00:32:12 -070049 return new MastershipBasedTimestamp(term, sequence);
50 }
51}