use of com.fasterxml.jackson.databind.ObjectWriter in project incubator-pulsar by apache.
the class ProducerStatsRecorderImpl method init.
private void init(ProducerConfigurationData conf) {
ObjectMapper m = new ObjectMapper();
m.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
ObjectWriter w = m.writerWithDefaultPrettyPrinter();
try {
log.info("Starting Pulsar producer perf with config: {}", w.writeValueAsString(conf));
log.info("Pulsar client config: {}", w.writeValueAsString(pulsarClient.getConfiguration()));
} catch (IOException e) {
log.error("Failed to dump config info: {}", e);
}
stat = (timeout) -> {
if (timeout.isCancelled()) {
return;
}
try {
long now = System.nanoTime();
double elapsed = (now - oldTime) / 1e9;
oldTime = now;
long currentNumMsgsSent = numMsgsSent.sumThenReset();
long currentNumBytesSent = numBytesSent.sumThenReset();
long currentNumSendFailedMsgs = numSendFailed.sumThenReset();
long currentNumAcksReceived = numAcksReceived.sumThenReset();
totalMsgsSent.add(currentNumMsgsSent);
totalBytesSent.add(currentNumBytesSent);
totalSendFailed.add(currentNumSendFailedMsgs);
totalAcksReceived.add(currentNumAcksReceived);
synchronized (ds) {
latencyPctValues = ds.getQuantiles(PERCENTILES);
ds.reset();
}
sendMsgsRate = currentNumMsgsSent / elapsed;
sendBytesRate = currentNumBytesSent / elapsed;
if ((currentNumMsgsSent | currentNumSendFailedMsgs | currentNumAcksReceived | currentNumMsgsSent) != 0) {
for (int i = 0; i < latencyPctValues.length; i++) {
if (latencyPctValues[i] == Double.NaN) {
latencyPctValues[i] = 0;
}
}
log.info("[{}] [{}] Pending messages: {} --- Publish throughput: {} msg/s --- {} Mbit/s --- " + "Latency: med: {} ms - 95pct: {} ms - 99pct: {} ms - 99.9pct: {} ms - max: {} ms --- " + "Ack received rate: {} ack/s --- Failed messages: {}", producer.getTopic(), producer.getProducerName(), producer.getPendingQueueSize(), THROUGHPUT_FORMAT.format(sendMsgsRate), THROUGHPUT_FORMAT.format(sendBytesRate / 1024 / 1024 * 8), DEC.format(latencyPctValues[0] / 1000.0), DEC.format(latencyPctValues[2] / 1000.0), DEC.format(latencyPctValues[3] / 1000.0), DEC.format(latencyPctValues[4] / 1000.0), DEC.format(latencyPctValues[5] / 1000.0), THROUGHPUT_FORMAT.format(currentNumAcksReceived / elapsed), currentNumSendFailedMsgs);
}
} catch (Exception e) {
log.error("[{}] [{}]: {}", producer.getTopic(), producer.getProducerName(), e.getMessage());
} finally {
// schedule the next stat info
statTimeout = pulsarClient.timer().newTimeout(stat, statsIntervalSeconds, TimeUnit.SECONDS);
}
};
oldTime = System.nanoTime();
statTimeout = pulsarClient.timer().newTimeout(stat, statsIntervalSeconds, TimeUnit.SECONDS);
}
use of com.fasterxml.jackson.databind.ObjectWriter in project incubator-pulsar by apache.
the class ConsumerConfigurationTest method testJsonIgnore.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testJsonIgnore() throws Exception {
ConsumerConfigurationData<?> conf = new ConsumerConfigurationData<>();
conf.setConsumerEventListener(new ConsumerEventListener() {
@Override
public void becameActive(Consumer<?> consumer, int partitionId) {
}
@Override
public void becameInactive(Consumer<?> consumer, int partitionId) {
}
});
conf.setMessageListener((MessageListener) (consumer, msg) -> {
});
conf.setCryptoKeyReader(mock(CryptoKeyReader.class));
ObjectMapper m = new ObjectMapper();
m.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
ObjectWriter w = m.writerWithDefaultPrettyPrinter();
String confAsString = w.writeValueAsString(conf);
log.info("conf : {}", confAsString);
assertFalse(confAsString.contains("messageListener"));
assertFalse(confAsString.contains("consumerEventListener"));
assertFalse(confAsString.contains("cryptoKeyReader"));
}
use of com.fasterxml.jackson.databind.ObjectWriter in project fabric8 by fabric8io.
the class JsonSchemaLookup method getSchemaForClass.
public String getSchemaForClass(Class<?> clazz) {
LOG.info("Looking up schema for " + clazz.getCanonicalName());
String name = clazz.getName();
try {
ObjectWriter writer = mapper.writer().with(new FourSpacePrettyPrinter());
JsonSchemaGenerator jsg = new JsonSchemaGenerator(mapper);
JsonSchema jsonSchema = jsg.generateSchema(clazz);
return writer.writeValueAsString(jsonSchema);
} catch (Exception e) {
LOG.log(Level.FINEST, "Failed to generate JSON schema for class " + name, e);
return "";
}
}
use of com.fasterxml.jackson.databind.ObjectWriter in project repseqio by repseqio.
the class VDJCGeneTest method jsonTestCurrentLibrary1.
@Test
public void jsonTestCurrentLibrary1() throws Exception {
VDJCLibrary library = VDJCLibraryRegistry.getDefaultLibrary("hs");
VDJCGene gene = library.getSafe("TRBV12-3*00");
ObjectWriter writer = GlobalObjectMappers.PRETTY.writerFor(VDJCGene.class).withAttribute(VDJCGene.JSON_CURRENT_LIBRARY_ATTRIBUTE_KEY, library);
ObjectReader reader = GlobalObjectMappers.PRETTY.readerFor(VDJCGene.class).withAttribute(VDJCGene.JSON_CURRENT_LIBRARY_ATTRIBUTE_KEY, library);
String str = writer.writeValueAsString(gene);
assertEquals("\"TRBV12-3*00\"", str);
Object geneDeserialized = reader.readValue(str);
assertTrue(geneDeserialized == gene);
}
use of com.fasterxml.jackson.databind.ObjectWriter in project batfish by batfish.
the class WorkMgr method getParsingResults.
public JSONObject getParsingResults(String containerName, String testrigName) throws JsonProcessingException, JSONException {
ParseVendorConfigurationAnswerElement pvcae = deserializeObject(getdirTestrig(containerName, testrigName).resolve(BfConsts.RELPATH_PARSE_ANSWER_PATH), ParseVendorConfigurationAnswerElement.class);
JSONObject warnings = new JSONObject();
SortedMap<String, Warnings> warningsMap = pvcae.getWarnings();
ObjectWriter writer = BatfishObjectMapper.prettyWriter();
for (String s : warningsMap.keySet()) {
warnings.put(s, writer.writeValueAsString(warningsMap.get(s)));
}
return warnings;
}
Aggregations