Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Foundation |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 3 | * |
| 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'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.store.serializers; |
Ayaka Koshibe | 8441136 | 2014-10-01 09:33:42 -0700 | [diff] [blame] | 17 | |
Yuta HIGUCHI | d08e2e9 | 2016-07-10 00:15:10 -0700 | [diff] [blame] | 18 | import static org.onosproject.store.serializers.NodeIdSerializer.nodeIdSerializer; |
| 19 | |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 20 | import org.onosproject.cluster.NodeId; |
| 21 | import org.onosproject.mastership.MastershipTerm; |
Yuta HIGUCHI | 80912e6 | 2014-10-12 00:15:47 -0700 | [diff] [blame] | 22 | |
Ayaka Koshibe | 8441136 | 2014-10-01 09:33:42 -0700 | [diff] [blame] | 23 | import com.esotericsoftware.kryo.Kryo; |
| 24 | import com.esotericsoftware.kryo.Serializer; |
| 25 | import com.esotericsoftware.kryo.io.Input; |
| 26 | import com.esotericsoftware.kryo.io.Output; |
| 27 | |
| 28 | /** |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 29 | * Kryo Serializer for {@link org.onosproject.mastership.MastershipTerm}. |
Ayaka Koshibe | 8441136 | 2014-10-01 09:33:42 -0700 | [diff] [blame] | 30 | */ |
Yuta HIGUCHI | d08e2e9 | 2016-07-10 00:15:10 -0700 | [diff] [blame] | 31 | public final class MastershipTermSerializer extends Serializer<MastershipTerm> { |
Ayaka Koshibe | 8441136 | 2014-10-01 09:33:42 -0700 | [diff] [blame] | 32 | |
Yuta HIGUCHI | 03fec1f | 2014-10-03 09:13:50 -0700 | [diff] [blame] | 33 | /** |
| 34 | * Creates {@link MastershipTerm} serializer instance. |
| 35 | */ |
| 36 | public MastershipTermSerializer() { |
| 37 | // non-null, immutable |
| 38 | super(false, true); |
| 39 | } |
| 40 | |
Ayaka Koshibe | 8441136 | 2014-10-01 09:33:42 -0700 | [diff] [blame] | 41 | @Override |
| 42 | public MastershipTerm read(Kryo kryo, Input input, Class<MastershipTerm> type) { |
Yuta HIGUCHI | d08e2e9 | 2016-07-10 00:15:10 -0700 | [diff] [blame] | 43 | final NodeId node = kryo.readObjectOrNull(input, NodeId.class, nodeIdSerializer()); |
Madan Jampani | 15d773c | 2015-02-25 15:31:55 -0800 | [diff] [blame] | 44 | final long term = input.readLong(); |
Ayaka Koshibe | 8441136 | 2014-10-01 09:33:42 -0700 | [diff] [blame] | 45 | return MastershipTerm.of(node, term); |
| 46 | } |
| 47 | |
| 48 | @Override |
| 49 | public void write(Kryo kryo, Output output, MastershipTerm object) { |
Yuta HIGUCHI | d08e2e9 | 2016-07-10 00:15:10 -0700 | [diff] [blame] | 50 | kryo.writeObjectOrNull(output, object.master(), nodeIdSerializer()); |
Madan Jampani | 15d773c | 2015-02-25 15:31:55 -0800 | [diff] [blame] | 51 | output.writeLong(object.termNumber()); |
Ayaka Koshibe | 8441136 | 2014-10-01 09:33:42 -0700 | [diff] [blame] | 52 | } |
Ayaka Koshibe | 8441136 | 2014-10-01 09:33:42 -0700 | [diff] [blame] | 53 | } |