Java Code Examples for org.apache.tinkerpop.shaded.jackson.core.JsonGenerator#writeNumberField()

The following examples show how to use org.apache.tinkerpop.shaded.jackson.core.JsonGenerator#writeNumberField() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MetricsModule.java    From hugegraph with Apache License 2.0 6 votes vote down vote up
@Override
public void serialize(Histogram histogram, JsonGenerator json,
                      SerializerProvider provider) throws IOException {
    json.writeStartObject();
    final Snapshot snapshot = histogram.getSnapshot();
    json.writeNumberField("count", histogram.getCount());
    json.writeNumberField("max", snapshot.getMax());
    json.writeNumberField("mean", snapshot.getMean());
    json.writeNumberField("min", snapshot.getMin());
    json.writeNumberField("p50", snapshot.getMedian());
    json.writeNumberField("p75", snapshot.get75thPercentile());
    json.writeNumberField("p95", snapshot.get95thPercentile());
    json.writeNumberField("p98", snapshot.get98thPercentile());
    json.writeNumberField("p99", snapshot.get99thPercentile());
    json.writeNumberField("p999", snapshot.get999thPercentile());

    if (this.showSamples) {
        json.writeObjectField("values", snapshot.getValues());
    }

    json.writeNumberField("stddev", snapshot.getStdDev());
    json.writeEndObject();
}
 
Example 2
Source File: MetricsModule.java    From hugegraph with Apache License 2.0 6 votes vote down vote up
@Override
public void serialize(Meter meter, JsonGenerator json,
                      SerializerProvider provider) throws IOException {
    json.writeStartObject();
    json.writeNumberField("count", meter.getCount());
    json.writeNumberField("m15_rate", meter.getFifteenMinuteRate() *
                                      this.rateFactor);
    json.writeNumberField("m1_rate", meter.getOneMinuteRate() *
                                     this.rateFactor);
    json.writeNumberField("m5_rate", meter.getFiveMinuteRate() *
                                     this.rateFactor);
    json.writeNumberField("mean_rate", meter.getMeanRate() *
                                       this.rateFactor);
    json.writeStringField("units", this.rateUnit);
    json.writeEndObject();
}
 
Example 3
Source File: AbstractGraphSONMessageSerializerV1d0.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
public void ser(final ResponseMessage responseMessage, final JsonGenerator jsonGenerator,
                final SerializerProvider serializerProvider,
                final TypeSerializer typeSerializer) throws IOException, JsonProcessingException {
    jsonGenerator.writeStartObject();
    if (typeSerializer != null) jsonGenerator.writeStringField(GraphSONTokens.CLASS, HashMap.class.getName());

    jsonGenerator.writeStringField(SerTokens.TOKEN_REQUEST, responseMessage.getRequestId() != null ? responseMessage.getRequestId().toString() : null);
    jsonGenerator.writeObjectFieldStart(SerTokens.TOKEN_STATUS);

    if (typeSerializer != null) jsonGenerator.writeStringField(GraphSONTokens.CLASS, HashMap.class.getName());
    jsonGenerator.writeStringField(SerTokens.TOKEN_MESSAGE, responseMessage.getStatus().getMessage());
    jsonGenerator.writeNumberField(SerTokens.TOKEN_CODE, responseMessage.getStatus().getCode().getValue());
    jsonGenerator.writeObjectField(SerTokens.TOKEN_ATTRIBUTES, responseMessage.getStatus().getAttributes());
    jsonGenerator.writeEndObject();

    jsonGenerator.writeObjectFieldStart(SerTokens.TOKEN_RESULT);
    if (typeSerializer != null) jsonGenerator.writeStringField(GraphSONTokens.CLASS, HashMap.class.getName());
    if (null == responseMessage.getResult().getData())
        jsonGenerator.writeNullField(SerTokens.TOKEN_DATA);
    else
        GraphSONUtil.writeWithType(SerTokens.TOKEN_DATA, responseMessage.getResult().getData(), jsonGenerator, serializerProvider, typeSerializer);
    jsonGenerator.writeObjectField(SerTokens.TOKEN_META, responseMessage.getResult().getMeta());
    jsonGenerator.writeEndObject();

    jsonGenerator.writeEndObject();
}
 
Example 4
Source File: HugeGraphSONModule.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(Shard shard, JsonGenerator jsonGenerator,
                      SerializerProvider provider)
                      throws IOException {
    jsonGenerator.writeStartObject();
    jsonGenerator.writeStringField("start", shard.start());
    jsonGenerator.writeStringField("end", shard.end());
    jsonGenerator.writeNumberField("length", shard.length());
    jsonGenerator.writeEndObject();
}
 
Example 5
Source File: MetricsModule.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(Counter counter, JsonGenerator json,
                      SerializerProvider provider) throws IOException {
    json.writeStartObject();
    json.writeNumberField("count", counter.getCount());
    json.writeEndObject();
}
 
Example 6
Source File: AbstractGraphSONMessageSerializerV2d0.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
public void ser(final ResponseMessage responseMessage, final JsonGenerator jsonGenerator,
                final SerializerProvider serializerProvider,
                final TypeSerializer typeSerializer) throws IOException {
    GraphSONUtil.writeStartObject(responseMessage, jsonGenerator, typeSerializer);

    jsonGenerator.writeStringField(SerTokens.TOKEN_REQUEST, responseMessage.getRequestId() != null ? responseMessage.getRequestId().toString() : null);
    jsonGenerator.writeFieldName(SerTokens.TOKEN_STATUS);

    GraphSONUtil.writeStartObject(responseMessage, jsonGenerator, typeSerializer);
    jsonGenerator.writeStringField(SerTokens.TOKEN_MESSAGE, responseMessage.getStatus().getMessage());
    jsonGenerator.writeNumberField(SerTokens.TOKEN_CODE, responseMessage.getStatus().getCode().getValue());
    jsonGenerator.writeObjectField(SerTokens.TOKEN_ATTRIBUTES, responseMessage.getStatus().getAttributes());
    GraphSONUtil.writeEndObject(responseMessage, jsonGenerator, typeSerializer);

    jsonGenerator.writeFieldName(SerTokens.TOKEN_RESULT);

    GraphSONUtil.writeStartObject(responseMessage, jsonGenerator, typeSerializer);

    if (null == responseMessage.getResult().getData()){
        jsonGenerator.writeNullField(SerTokens.TOKEN_DATA);
    } else {
        jsonGenerator.writeFieldName(SerTokens.TOKEN_DATA);
        final Object result = responseMessage.getResult().getData();
        serializerProvider.findTypedValueSerializer(result.getClass(), true, null).serialize(result, jsonGenerator, serializerProvider);
    }

    jsonGenerator.writeObjectField(SerTokens.TOKEN_META, responseMessage.getResult().getMeta());
    GraphSONUtil.writeEndObject(responseMessage, jsonGenerator, typeSerializer);

    GraphSONUtil.writeEndObject(responseMessage, jsonGenerator, typeSerializer);
}
 
Example 7
Source File: TraversalSerializersV2d0.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(final Lambda lambda, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider)
        throws IOException {
    jsonGenerator.writeStartObject();
    jsonGenerator.writeStringField(GraphSONTokens.SCRIPT, lambda.getLambdaScript());
    jsonGenerator.writeStringField(GraphSONTokens.LANGUAGE, lambda.getLambdaLanguage());
    jsonGenerator.writeNumberField(GraphSONTokens.ARGUMENTS, lambda.getLambdaArguments());
    jsonGenerator.writeEndObject();
}
 
Example 8
Source File: TraversalSerializersV3d0.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(final Lambda lambda, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider)
        throws IOException {
    jsonGenerator.writeStartObject();
    jsonGenerator.writeStringField(GraphSONTokens.SCRIPT, lambda.getLambdaScript());
    jsonGenerator.writeStringField(GraphSONTokens.LANGUAGE, lambda.getLambdaLanguage());
    jsonGenerator.writeNumberField(GraphSONTokens.ARGUMENTS, lambda.getLambdaArguments());
    jsonGenerator.writeEndObject();
}
 
Example 9
Source File: MetricsModule.java    From hugegraph with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(Timer timer, JsonGenerator json,
                      SerializerProvider provider) throws IOException {
    json.writeStartObject();
    final Snapshot snapshot = timer.getSnapshot();
    json.writeNumberField("count", timer.getCount());
    json.writeNumberField("max", snapshot.getMax() *
                                 this.durationFactor);
    json.writeNumberField("mean", snapshot.getMean() *
                                  this.durationFactor);
    json.writeNumberField("min", snapshot.getMin() *
                                 this.durationFactor);

    json.writeNumberField("p50", snapshot.getMedian() *
                                 this.durationFactor);
    json.writeNumberField("p75", snapshot.get75thPercentile() *
                                 this.durationFactor);
    json.writeNumberField("p95", snapshot.get95thPercentile() *
                                 this.durationFactor);
    json.writeNumberField("p98", snapshot.get98thPercentile() *
                                 this.durationFactor);
    json.writeNumberField("p99", snapshot.get99thPercentile() *
                                 this.durationFactor);
    json.writeNumberField("p999", snapshot.get999thPercentile() *
                                  this.durationFactor);

    if (this.showSamples) {
        final long[] values = snapshot.getValues();
        final double[] scaledValues = new double[values.length];
        for (int i = 0; i < values.length; i++) {
            scaledValues[i] = values[i] * this.durationFactor;
        }
        json.writeObjectField("values", scaledValues);
    }

    json.writeNumberField("stddev", snapshot.getStdDev() *
                                    this.durationFactor);
    json.writeNumberField("m15_rate", timer.getFifteenMinuteRate() *
                                      this.rateFactor);
    json.writeNumberField("m1_rate", timer.getOneMinuteRate() *
                                     this.rateFactor);
    json.writeNumberField("m5_rate", timer.getFiveMinuteRate() *
                                     this.rateFactor);
    json.writeNumberField("mean_rate", timer.getMeanRate() *
                                       this.rateFactor);
    json.writeStringField("duration_units", this.durationUnit);
    json.writeStringField("rate_units", this.rateUnit);
    json.writeEndObject();
}