Example usage for com.fasterxml.jackson.core JsonGenerator writeNumberField

List of usage examples for com.fasterxml.jackson.core JsonGenerator writeNumberField

Introduction

In this page you can find the example usage for com.fasterxml.jackson.core JsonGenerator writeNumberField.

Prototype

public final void writeNumberField(String fieldName, BigDecimal value)
        throws IOException, JsonGenerationException 

Source Link

Document

Convenience method for outputting a field entry ("member") that has the specified numeric value.

Usage

From source file:com.netflix.hystrix.contrib.sample.stream.HystrixUtilizationJsonStream.java

private static void writeCommandUtilizationJson(JsonGenerator json, HystrixCommandKey key,
        HystrixCommandUtilization utilization) throws IOException {
    json.writeObjectFieldStart(key.name());
    json.writeNumberField("activeCount", utilization.getConcurrentCommandCount());
    json.writeEndObject();//  ww  w .  ja  v a2  s. c  om
}

From source file:com.netflix.hystrix.contrib.sample.stream.HystrixUtilizationJsonStream.java

private static void writeThreadPoolUtilizationJson(JsonGenerator json, HystrixThreadPoolKey threadPoolKey,
        HystrixThreadPoolUtilization utilization) throws IOException {
    json.writeObjectFieldStart(threadPoolKey.name());
    json.writeNumberField("activeCount", utilization.getCurrentActiveCount());
    json.writeNumberField("queueSize", utilization.getCurrentQueueSize());
    json.writeNumberField("corePoolSize", utilization.getCurrentCorePoolSize());
    json.writeNumberField("poolSize", utilization.getCurrentPoolSize());
    json.writeEndObject();//w w w .  j  a va 2 s  .  c  o m
}

From source file:eu.project.ttc.readers.TermSuiteJsonCasSerializer.java

private static void writeLongField(JsonGenerator jg, String fieldName, Long value) throws IOException {
    if (value == null)
        return;// ww w.ja v a  2s.c  o  m
    jg.writeNumberField(fieldName, value);
}

From source file:com.netflix.hystrix.contrib.sample.stream.HystrixConfigurationJsonStream.java

private static void writeCollapserConfigJson(JsonGenerator json, HystrixCollapserKey collapserKey,
        HystrixCollapserConfiguration collapserConfig) throws IOException {
    json.writeObjectFieldStart(collapserKey.name());
    json.writeNumberField("maxRequestsInBatch", collapserConfig.getMaxRequestsInBatch());
    json.writeNumberField("timerDelayInMilliseconds", collapserConfig.getTimerDelayInMilliseconds());
    json.writeBooleanField("requestCacheEnabled", collapserConfig.isRequestCacheEnabled());
    json.writeObjectFieldStart("metrics");
    HystrixCollapserConfiguration.CollapserMetricsConfig metricsConfig = collapserConfig
            .getCollapserMetricsConfig();
    json.writeNumberField("percentileBucketSizeInMilliseconds",
            metricsConfig.getRollingPercentileBucketSizeInMilliseconds());
    json.writeNumberField("percentileBucketCount", metricsConfig.getRollingCounterNumberOfBuckets());
    json.writeBooleanField("percentileEnabled", metricsConfig.isRollingPercentileEnabled());
    json.writeNumberField("counterBucketSizeInMilliseconds",
            metricsConfig.getRollingCounterBucketSizeInMilliseconds());
    json.writeNumberField("counterBucketCount", metricsConfig.getRollingCounterNumberOfBuckets());
    json.writeEndObject();//from   ww  w .  ja  v  a2s. c om
    json.writeEndObject();
}

From source file:com.netflix.hystrix.contrib.sample.stream.HystrixConfigurationJsonStream.java

private static void writeThreadPoolConfigJson(JsonGenerator json, HystrixThreadPoolKey threadPoolKey,
        HystrixThreadPoolConfiguration threadPoolConfig) throws IOException {
    json.writeObjectFieldStart(threadPoolKey.name());
    json.writeNumberField("coreSize", threadPoolConfig.getCoreSize());
    json.writeNumberField("maximumSize", threadPoolConfig.getMaximumSize());
    json.writeNumberField("actualMaximumSize", threadPoolConfig.getActualMaximumSize());
    json.writeNumberField("maxQueueSize", threadPoolConfig.getMaxQueueSize());
    json.writeNumberField("queueRejectionThreshold", threadPoolConfig.getQueueRejectionThreshold());
    json.writeNumberField("keepAliveTimeInMinutes", threadPoolConfig.getKeepAliveTimeInMinutes());
    json.writeBooleanField("allowMaximumSizeToDivergeFromCoreSize",
            threadPoolConfig.getAllowMaximumSizeToDivergeFromCoreSize());
    json.writeNumberField("counterBucketSizeInMilliseconds",
            threadPoolConfig.getRollingCounterBucketSizeInMilliseconds());
    json.writeNumberField("counterBucketCount", threadPoolConfig.getRollingCounterNumberOfBuckets());
    json.writeEndObject();//www . ja  va2  s  .  c  om
}

From source file:io.seldon.spark.actions.JobUtils.java

public static String getJsonFromActionData(ActionData actionData) {
    JsonFactory jsonFactory = new JsonFactory();
    StringWriter sw = new StringWriter();
    try {//w ww  .  ja  v  a  2s . co  m
        JsonGenerator jg = jsonFactory.createGenerator(sw);
        jg.writeStartObject();
        jg.writeStringField("timestamp_utc", actionData.timestamp_utc);
        jg.writeStringField("client", actionData.client);
        jg.writeStringField("client_userid", actionData.client_userid);
        jg.writeNumberField("userid", actionData.userid);
        jg.writeNumberField("itemid", actionData.itemid);
        jg.writeStringField("client_itemid", actionData.client_itemid);
        jg.writeStringField("rectag", actionData.rectag);
        jg.writeNumberField("type", actionData.type);
        jg.writeNumberField("value", actionData.value);
        jg.writeEndObject();
        jg.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return sw.toString();
}

From source file:com.netflix.hystrix.serial.SerialHystrixDashboardData.java

protected static void safelyWriteNumberField(JsonGenerator json, String name, Func0<Long> metricGenerator)
        throws IOException {
    try {//from   w  ww. j  ava  2s  .com
        json.writeNumberField(name, metricGenerator.call());
    } catch (NoSuchFieldError error) {
        logger.error("While publishing Hystrix metrics stream, error looking up eventType for : " + name
                + ".  Please check that all Hystrix versions are the same!");
        json.writeNumberField(name, 0L);
    }
}

From source file:com.microsoft.azure.storage.table.TableEntitySerializer.java

private static void writeJsonProperty(JsonGenerator generator, Entry<String, EntityProperty> prop)
        throws JsonGenerationException, IOException {
    EdmType edmType = prop.getValue().getEdmType();
    if (prop.getValue().getIsNull()) {
        generator.writeNullField(prop.getKey());
    } else if (edmType == EdmType.BOOLEAN) {
        generator.writeBooleanField(prop.getKey(), prop.getValue().getValueAsBoolean());
    } else if (edmType == EdmType.DOUBLE) {
        generator.writeNumberField(prop.getKey(), prop.getValue().getValueAsDouble());
    } else if (edmType == EdmType.INT32) {
        generator.writeNumberField(prop.getKey(), prop.getValue().getValueAsInteger());
    } else {//  ww w  .  j a va 2 s. c  o  m
        generator.writeStringField(prop.getKey(), prop.getValue().getValueAsString());
    }
}

From source file:com.netflix.hystrix.serial.SerialHystrixDashboardData.java

private static void writeThreadPoolMetrics(final HystrixThreadPoolMetrics threadPoolMetrics, JsonGenerator json)
        throws IOException {
    HystrixThreadPoolKey key = threadPoolMetrics.getThreadPoolKey();

    json.writeStartObject();/*  w w w .  j  a va 2s  .c o  m*/

    json.writeStringField("type", "HystrixThreadPool");
    json.writeStringField("name", key.name());
    json.writeNumberField("currentTime", System.currentTimeMillis());

    json.writeNumberField("currentActiveCount", threadPoolMetrics.getCurrentActiveCount().intValue());
    json.writeNumberField("currentCompletedTaskCount",
            threadPoolMetrics.getCurrentCompletedTaskCount().longValue());
    json.writeNumberField("currentCorePoolSize", threadPoolMetrics.getCurrentCorePoolSize().intValue());
    json.writeNumberField("currentLargestPoolSize", threadPoolMetrics.getCurrentLargestPoolSize().intValue());
    json.writeNumberField("currentMaximumPoolSize", threadPoolMetrics.getCurrentMaximumPoolSize().intValue());
    json.writeNumberField("currentPoolSize", threadPoolMetrics.getCurrentPoolSize().intValue());
    json.writeNumberField("currentQueueSize", threadPoolMetrics.getCurrentQueueSize().intValue());
    json.writeNumberField("currentTaskCount", threadPoolMetrics.getCurrentTaskCount().longValue());
    safelyWriteNumberField(json, "rollingCountThreadsExecuted", new Func0<Long>() {
        @Override
        public Long call() {
            return threadPoolMetrics.getRollingCount(HystrixEventType.ThreadPool.EXECUTED);
        }
    });
    json.writeNumberField("rollingMaxActiveThreads", threadPoolMetrics.getRollingMaxActiveThreads());
    safelyWriteNumberField(json, "rollingCountCommandRejections", new Func0<Long>() {
        @Override
        public Long call() {
            return threadPoolMetrics.getRollingCount(HystrixEventType.ThreadPool.REJECTED);
        }
    });

    json.writeNumberField("propertyValue_queueSizeRejectionThreshold",
            threadPoolMetrics.getProperties().queueSizeRejectionThreshold().get());
    json.writeNumberField("propertyValue_metricsRollingStatisticalWindowInMilliseconds",
            threadPoolMetrics.getProperties().metricsRollingStatisticalWindowInMilliseconds().get());

    json.writeNumberField("reportingHosts", 1); // this will get summed across all instances in a cluster

    json.writeEndObject();
}

From source file:com.netflix.hystrix.serial.SerialHystrixDashboardData.java

private static void writeCollapserMetrics(final HystrixCollapserMetrics collapserMetrics, JsonGenerator json)
        throws IOException {
    HystrixCollapserKey key = collapserMetrics.getCollapserKey();

    json.writeStartObject();/*from w  ww. j  a  v a2 s  .  co  m*/

    json.writeStringField("type", "HystrixCollapser");
    json.writeStringField("name", key.name());
    json.writeNumberField("currentTime", System.currentTimeMillis());

    safelyWriteNumberField(json, "rollingCountRequestsBatched", new Func0<Long>() {
        @Override
        public Long call() {
            return collapserMetrics.getRollingCount(HystrixEventType.Collapser.ADDED_TO_BATCH);
        }
    });
    safelyWriteNumberField(json, "rollingCountBatches", new Func0<Long>() {
        @Override
        public Long call() {
            return collapserMetrics.getRollingCount(HystrixEventType.Collapser.BATCH_EXECUTED);
        }
    });
    safelyWriteNumberField(json, "rollingCountResponsesFromCache", new Func0<Long>() {
        @Override
        public Long call() {
            return collapserMetrics.getRollingCount(HystrixEventType.Collapser.RESPONSE_FROM_CACHE);
        }
    });

    // batch size percentiles
    json.writeNumberField("batchSize_mean", collapserMetrics.getBatchSizeMean());
    json.writeObjectFieldStart("batchSize");
    json.writeNumberField("25", collapserMetrics.getBatchSizePercentile(25));
    json.writeNumberField("50", collapserMetrics.getBatchSizePercentile(50));
    json.writeNumberField("75", collapserMetrics.getBatchSizePercentile(75));
    json.writeNumberField("90", collapserMetrics.getBatchSizePercentile(90));
    json.writeNumberField("95", collapserMetrics.getBatchSizePercentile(95));
    json.writeNumberField("99", collapserMetrics.getBatchSizePercentile(99));
    json.writeNumberField("99.5", collapserMetrics.getBatchSizePercentile(99.5));
    json.writeNumberField("100", collapserMetrics.getBatchSizePercentile(100));
    json.writeEndObject();

    // shard size percentiles (commented-out for now)
    //json.writeNumberField("shardSize_mean", collapserMetrics.getShardSizeMean());
    //json.writeObjectFieldStart("shardSize");
    //json.writeNumberField("25", collapserMetrics.getShardSizePercentile(25));
    //json.writeNumberField("50", collapserMetrics.getShardSizePercentile(50));
    //json.writeNumberField("75", collapserMetrics.getShardSizePercentile(75));
    //json.writeNumberField("90", collapserMetrics.getShardSizePercentile(90));
    //json.writeNumberField("95", collapserMetrics.getShardSizePercentile(95));
    //json.writeNumberField("99", collapserMetrics.getShardSizePercentile(99));
    //json.writeNumberField("99.5", collapserMetrics.getShardSizePercentile(99.5));
    //json.writeNumberField("100", collapserMetrics.getShardSizePercentile(100));
    //json.writeEndObject();

    //json.writeNumberField("propertyValue_metricsRollingStatisticalWindowInMilliseconds", collapserMetrics.getProperties().metricsRollingStatisticalWindowInMilliseconds().get());
    json.writeBooleanField("propertyValue_requestCacheEnabled",
            collapserMetrics.getProperties().requestCacheEnabled().get());
    json.writeNumberField("propertyValue_maxRequestsInBatch",
            collapserMetrics.getProperties().maxRequestsInBatch().get());
    json.writeNumberField("propertyValue_timerDelayInMilliseconds",
            collapserMetrics.getProperties().timerDelayInMilliseconds().get());

    json.writeNumberField("reportingHosts", 1); // this will get summed across all instances in a cluster

    json.writeEndObject();
}