blob: 9beb929f0e69d92cf4c04cc5cf6ac409a54a7b98 [file] [log] [blame]
Jian Li80c12702016-02-20 08:58:19 +09001/*
2 * Copyright 2016 Open Networking Laboratory
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 */
16package org.onosproject.cpman.codec;
17
18import com.fasterxml.jackson.databind.node.ObjectNode;
19import org.onosproject.codec.CodecContext;
20import org.onosproject.codec.JsonCodec;
21import org.onosproject.cpman.ControlLoad;
22
23/**
24 * Control load codec.
25 */
26public final class ControlLoadCodec extends JsonCodec<ControlLoad> {
27
28 private static final String TIME = "time";
29 private static final String LATEST = "latest";
30 private static final String AVERAGE = "average";
31
32 @Override
33 public ObjectNode encode(ControlLoad controlLoad, CodecContext context) {
34 return context.mapper().createObjectNode()
35 .put(TIME, controlLoad.time())
36 .put(LATEST, controlLoad.latest())
37 .put(AVERAGE, controlLoad.average());
38 }
39}