Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 1 | package net.floodlightcontroller.perfmon; |
| 2 | |
| 3 | import java.io.IOException; |
| 4 | import java.sql.Timestamp; |
| 5 | |
| 6 | |
| 7 | import org.codehaus.jackson.JsonGenerator; |
| 8 | import org.codehaus.jackson.JsonProcessingException; |
| 9 | import org.codehaus.jackson.map.JsonSerializer; |
| 10 | import org.codehaus.jackson.map.SerializerProvider; |
| 11 | |
| 12 | public class CumulativeTimeBucketJSONSerializer |
| 13 | extends JsonSerializer<CumulativeTimeBucket> { |
| 14 | /** |
| 15 | * Performs the serialization of a OneComponentTime object |
| 16 | */ |
| 17 | @Override |
| 18 | public void serialize(CumulativeTimeBucket ctb, |
| 19 | JsonGenerator jGen, |
| 20 | SerializerProvider serializer) |
| 21 | throws IOException, JsonProcessingException { |
| 22 | jGen.writeStartObject(); |
| 23 | Timestamp ts = new Timestamp(ctb.getStartTimeNs()/1000000); |
| 24 | jGen.writeStringField("start-time", ts.toString()); |
| 25 | jGen.writeStringField("current-time", |
| 26 | new Timestamp(System.currentTimeMillis()).toString()); |
| 27 | jGen.writeNumberField("total-packets", ctb.getTotalPktCnt()); |
| 28 | jGen.writeNumberField("average", ctb.getAverageProcTimeNs()); |
| 29 | jGen.writeNumberField("min", ctb.getMinTotalProcTimeNs()); |
| 30 | jGen.writeNumberField("max", ctb.getMaxTotalProcTimeNs()); |
| 31 | jGen.writeNumberField("std-dev", ctb.getTotalSigmaProcTimeNs()); |
| 32 | jGen.writeArrayFieldStart("modules"); |
| 33 | for (OneComponentTime oct : ctb.getModules()) { |
| 34 | serializer.defaultSerializeValue(oct, jGen); |
| 35 | } |
| 36 | jGen.writeEndArray(); |
| 37 | jGen.writeEndObject(); |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * Tells SimpleModule that we are the serializer for OFMatch |
| 42 | */ |
| 43 | @Override |
| 44 | public Class<CumulativeTimeBucket> handledType() { |
| 45 | return CumulativeTimeBucket.class; |
| 46 | } |
| 47 | } |