Search in sources :

Example 96 with ObjectWriter

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);
}
Also used : ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException)

Example 97 with ObjectWriter

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"));
}
Also used : Logger(org.slf4j.Logger) ConsumerConfigurationData(org.apache.pulsar.client.impl.conf.ConsumerConfigurationData) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) LoggerFactory(org.slf4j.LoggerFactory) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.testng.annotations.Test) SerializationFeature(com.fasterxml.jackson.databind.SerializationFeature) Assert.assertFalse(org.testng.Assert.assertFalse) Mockito.mock(org.mockito.Mockito.mock) ConsumerConfigurationData(org.apache.pulsar.client.impl.conf.ConsumerConfigurationData) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.testng.annotations.Test)

Example 98 with ObjectWriter

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 "";
    }
}
Also used : JsonSchema(com.fasterxml.jackson.module.jsonSchema.JsonSchema) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) JsonSchemaGenerator(com.fasterxml.jackson.module.jsonSchema.JsonSchemaGenerator)

Example 99 with ObjectWriter

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);
}
Also used : ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) Test(org.junit.Test)

Example 100 with ObjectWriter

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;
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) ParseVendorConfigurationAnswerElement(org.batfish.datamodel.answers.ParseVendorConfigurationAnswerElement) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) Warnings(org.batfish.common.Warnings)

Aggregations

ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)124 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)53 IOException (java.io.IOException)28 Test (org.junit.Test)27 File (java.io.File)13 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)12 JavaType (com.fasterxml.jackson.databind.JavaType)10 ObjectReader (com.fasterxml.jackson.databind.ObjectReader)10 ArrayList (java.util.ArrayList)10 FileOutputStream (java.io.FileOutputStream)7 Map (java.util.Map)7 JCommander (com.beust.jcommander.JCommander)6 ParameterException (com.beust.jcommander.ParameterException)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)6 RateLimiter (com.google.common.util.concurrent.RateLimiter)6 FileInputStream (java.io.FileInputStream)6 OutputStream (java.io.OutputStream)6 Writer (java.io.Writer)6 HashMap (java.util.HashMap)6 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)5