Search in sources :

Example 11 with ObjectWriter

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectWriter in project pulsar by yahoo.

the class ProducerStats method init.

private void init(ProducerConfiguration 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);
            double[] percentileValues;
            synchronized (ds) {
                percentileValues = ds.getQuantiles(percentiles);
                ds.reset();
            }
            if ((currentNumMsgsSent | currentNumSendFailedMsgs | currentNumAcksReceived | currentNumMsgsSent) != 0) {
                for (int i = 0; i < percentileValues.length; i++) {
                    if (percentileValues[i] == Double.NaN) {
                        percentileValues[i] = 0;
                    }
                }
                log.info("[{}] [{}] Pending messages: {} --- Publish throughput: {} msg/s --- {} Mbit/s --- " + "Latency: med: {} ms - 95pct: {} ms - 99pct: {} ms - 99.9pct: {} ms - 99.99pct: {} ms --- " + "Ack received rate: {} ack/s --- Failed messages: {}", producer.getTopic(), producer.getProducerName(), producer.getPendingQueueSize(), throughputFormat.format(currentNumMsgsSent / elapsed), throughputFormat.format(currentNumBytesSent / elapsed / 1024 / 1024 * 8), dec.format(percentileValues[0] / 1000.0), dec.format(percentileValues[1] / 1000.0), dec.format(percentileValues[2] / 1000.0), dec.format(percentileValues[3] / 1000.0), dec.format(percentileValues[4] / 1000.0), throughputFormat.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 12 with ObjectWriter

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectWriter in project cas by apereo.

the class TicketValidationResourceResolver method resolveFrom.

@Override
public String[] resolveFrom(final JoinPoint joinPoint, final Object object) {
    final List<String> auditResourceResults = new ArrayList<>();
    final String ticketId = AopUtils.unWrapJoinPoint(joinPoint).getArgs()[0].toString();
    auditResourceResults.add(ticketId);
    if (object instanceof Assertion) {
        final Assertion assertion = Assertion.class.cast(object);
        final Authentication authn = assertion.getPrimaryAuthentication();
        try (StringWriter writer = new StringWriter()) {
            final ObjectWriter objectWriter = mapper.writer();
            final Map<String, Object> results = new LinkedHashMap<>();
            results.put("principal", authn.getPrincipal().getId());
            final Map<String, Object> attributes = new LinkedHashMap<>(authn.getAttributes());
            attributes.putAll(authn.getPrincipal().getAttributes());
            results.put("attributes", attributes);
            objectWriter.writeValue(writer, results);
            auditResourceResults.add(writer.toString());
        } catch (final Exception e) {
            LOGGER.error(e.getMessage(), e);
        }
    }
    return auditResourceResults.toArray(new String[] {});
}
Also used : StringWriter(java.io.StringWriter) Authentication(org.apereo.cas.authentication.Authentication) ArrayList(java.util.ArrayList) Assertion(org.apereo.cas.validation.Assertion) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) LinkedHashMap(java.util.LinkedHashMap)

Example 13 with ObjectWriter

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectWriter in project dhis2-core by dhis2.

the class DefaultCsvEventService method writeEvents.

@Override
public void writeEvents(OutputStream outputStream, Events events, boolean withHeader) throws IOException {
    ObjectWriter writer = CSV_MAPPER.writer(CSV_SCHEMA.withUseHeader(withHeader));
    List<CsvEventDataValue> dataValues = new ArrayList<>();
    for (Event event : events.getEvents()) {
        CsvEventDataValue templateDataValue = new CsvEventDataValue();
        templateDataValue.setEvent(event.getEvent());
        templateDataValue.setStatus(event.getStatus() != null ? event.getStatus().name() : null);
        templateDataValue.setProgram(event.getProgram());
        templateDataValue.setProgramStage(event.getProgramStage());
        templateDataValue.setEnrollment(event.getEnrollment());
        templateDataValue.setOrgUnit(event.getOrgUnit());
        templateDataValue.setEventDate(event.getEventDate());
        templateDataValue.setDueDate(event.getDueDate());
        templateDataValue.setStoredBy(event.getStoredBy());
        if (event.getCoordinate() != null) {
            templateDataValue.setLatitude(event.getCoordinate().getLatitude());
            templateDataValue.setLongitude(event.getCoordinate().getLongitude());
        }
        for (DataValue value : event.getDataValues()) {
            CsvEventDataValue dataValue = new CsvEventDataValue(templateDataValue);
            dataValue.setDataElement(value.getDataElement());
            dataValue.setValue(value.getValue());
            dataValue.setProvidedElsewhere(value.getProvidedElsewhere());
            if (value.getStoredBy() != null) {
                dataValue.setStoredBy(value.getStoredBy());
            }
            dataValues.add(dataValue);
        }
    }
    writer.writeValue(outputStream, dataValues);
}
Also used : DataValue(org.hisp.dhis.dxf2.events.event.DataValue) ArrayList(java.util.ArrayList) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) Event(org.hisp.dhis.dxf2.events.event.Event)

Example 14 with ObjectWriter

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectWriter in project topjava10 by JavaWebinar.

the class JsonUtilTest method testRestReadWriteValue.

@Test
public void testRestReadWriteValue() throws Exception {
    ObjectWriter uiWriter = JacksonObjectMapper.getMapper().writerWithView(View.JsonUI.class);
    String json = JsonUtil.writeValue(MealTestData.ADMIN_MEAL1, uiWriter);
    System.out.println(json);
    assertThat(json, containsString("dateTimeUI"));
}
Also used : ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) Matchers.containsString(org.hamcrest.Matchers.containsString) View(ru.javawebinar.topjava.View) Test(org.junit.Test)

Example 15 with ObjectWriter

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectWriter in project CzechIdMng by bcvsolutions.

the class LoginControllerRestTest method serialize.

private String serialize(Map<String, String> login) throws IOException {
    ObjectMapper m = new ObjectMapper();
    StringWriter sw = new StringWriter();
    ObjectWriter writer = m.writerFor(HashMap.class);
    writer.writeValue(sw, login);
    // 
    return sw.toString();
}
Also used : StringWriter(java.io.StringWriter) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)140 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)61 IOException (java.io.IOException)31 Test (org.junit.Test)30 File (java.io.File)17 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)15 ArrayList (java.util.ArrayList)12 ObjectReader (com.fasterxml.jackson.databind.ObjectReader)11 JavaType (com.fasterxml.jackson.databind.JavaType)10 JsonNode (com.fasterxml.jackson.databind.JsonNode)10 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)7 FileOutputStream (java.io.FileOutputStream)7 OutputStream (java.io.OutputStream)7 StringWriter (java.io.StringWriter)7 Map (java.util.Map)7 JCommander (com.beust.jcommander.JCommander)6 ParameterException (com.beust.jcommander.ParameterException)6 SimpleFilterProvider (com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider)6 RateLimiter (com.google.common.util.concurrent.RateLimiter)6 FileInputStream (java.io.FileInputStream)6