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);
}
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[] {});
}
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);
}
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"));
}
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();
}
Aggregations