use of org.apache.avro.io.JsonEncoder in project databus by linkedin.
the class ContainerStatsRequestProcessor method processInboundTrafficTotalStats.
private void processInboundTrafficTotalStats(DatabusRequest request) throws IOException {
ContainerTrafficTotalStatsMBean inboundTrafficTotalStatsMBean = _containerStatsCollector.getInboundTrafficTotalStats();
if (null == inboundTrafficTotalStatsMBean)
return;
//String json = inboundTrafficTotalStatsMBean.toJson();
JsonEncoder jsonEncoder = inboundTrafficTotalStatsMBean.createJsonEncoder(Channels.newOutputStream(request.getResponseContent()));
inboundTrafficTotalStatsMBean.toJson(jsonEncoder, null);
if (request.getRequestType() == HttpMethod.PUT || request.getRequestType() == HttpMethod.POST) {
enableOrResetStatsMBean(inboundTrafficTotalStatsMBean, request);
}
}
use of org.apache.avro.io.JsonEncoder in project databus by linkedin.
the class DbusEventAvroDecoder method dumpEventValueInJSON.
public void dumpEventValueInJSON(DbusEvent e, OutputStream out) {
byte[] md5 = new byte[16];
e.schemaId(md5);
SchemaId schemaId = new SchemaId(md5);
VersionedSchema sourceSchema = _schemaSet.getById(schemaId);
ByteBuffer valueBuffer = e.value();
byte[] valueBytes = new byte[valueBuffer.remaining()];
valueBuffer.get(valueBytes);
try {
Schema schema = sourceSchema.getSchema();
DatumReader<Object> reader = new GenericDatumReader<Object>(schema);
binDecoder.set(DecoderFactory.defaultFactory().createBinaryDecoder(valueBytes, binDecoder.get()));
Object datum = reader.read(null, binDecoder.get());
DatumWriter<Object> writer = new GenericDatumWriter<Object>(schema);
JsonGenerator g = new JsonFactory().createJsonGenerator(out, JsonEncoding.UTF8);
// write the src ID
g.writeStartObject();
g.writeFieldName(SRC_ID_FIELD_NAME);
g.writeNumber(e.getSourceId());
g.writeFieldName(OPCODE_FIELD_NAME);
g.writeString(e.getOpcode().toString());
g.writeFieldName("partId");
g.writeNumber(Integer.valueOf(e.getPartitionId()));
g.writeFieldName(VALUE_FIELD_NAME);
writer.write(datum, new JsonEncoder(schema, g));
g.writeEndObject();
g.writeEndObject();
try {
g.writeEndObject();
} catch (JsonGenerationException e_json) {
// ignore the error as some how avro JsonEncoder may some times missing two }
}
g.flush();
} catch (IOException e1) {
LOG.error("event value serialization error; event = " + e, e1);
}
}
use of org.apache.avro.io.JsonEncoder in project databus by linkedin.
the class AbstractMonitoringMBean method toJson.
@Override
public String toJson() {
ByteArrayOutputStream out = new ByteArrayOutputStream(10000);
try {
JsonEncoder jsonEncoder = createJsonEncoder(out);
toJson(jsonEncoder, null);
} catch (IOException ioe) {
LOG.error("JSON serialization error", ioe);
out.reset();
}
return out.toString();
}
Aggregations