Java Code Examples for org.codehaus.jackson.JsonGenerator#writeBooleanField()

The following examples show how to use org.codehaus.jackson.JsonGenerator#writeBooleanField() . 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: Configuration.java    From RDFS with Apache License 2.0 6 votes vote down vote up
/**
 *  Writes out all the parameters and their properties (final and resource) to
 *  the given {@link Writer}
 *  The format of the output would be 
 *  { "properties" : [ {key1,value1,key1.isFinal,key1.resource}, {key2,value2,
 *  key2.isFinal,key2.resource}... ] } 
 *  It does not output the parameters of the configuration object which is 
 *  loaded from an input stream.
 * @param out the Writer to write to
 * @throws IOException
 */
public static void dumpConfiguration(Configuration config,
    Writer out) throws IOException {
  JsonFactory dumpFactory = new JsonFactory();
  JsonGenerator dumpGenerator = dumpFactory.createJsonGenerator(out);
  dumpGenerator.writeStartObject();
  dumpGenerator.writeFieldName("properties");
  dumpGenerator.writeStartArray();
  dumpGenerator.flush();
  synchronized (config) {
    for (Map.Entry<Object,Object> item: config.getProps().entrySet()) {
      dumpGenerator.writeStartObject();
      dumpGenerator.writeStringField("key", (String) item.getKey());
      dumpGenerator.writeStringField("value",
                                     config.get((String) item.getKey()));
      dumpGenerator.writeBooleanField("isFinal",
                                      config.finalParameters.contains(item.getKey()));
      dumpGenerator.writeStringField("resource",
                                     config.updatingResource.get(item.getKey()));
      dumpGenerator.writeEndObject();
    }
  }
  dumpGenerator.writeEndArray();
  dumpGenerator.writeEndObject();
  dumpGenerator.flush();
}
 
Example 2
Source File: Configuration.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 *  Writes out all the parameters and their properties (final and resource) to
 *  the given {@link Writer}
 *  The format of the output would be
 *  { "properties" : [ {key1,value1,key1.isFinal,key1.resource}, {key2,value2,
 *  key2.isFinal,key2.resource}... ] }
 *  It does not output the parameters of the configuration object which is
 *  loaded from an input stream.
 * @param out the Writer to write to
 * @throws IOException
 */
public static void dumpConfiguration(Configuration config,
    Writer out) throws IOException {
  JsonFactory dumpFactory = new JsonFactory();
  JsonGenerator dumpGenerator = dumpFactory.createJsonGenerator(out);
  dumpGenerator.writeStartObject();
  dumpGenerator.writeFieldName("properties");
  dumpGenerator.writeStartArray();
  dumpGenerator.flush();
  synchronized (config) {
    for (Entry<Object,Object> item: config.getProps().entrySet()) {
      dumpGenerator.writeStartObject();
      dumpGenerator.writeStringField("key", (String) item.getKey());
      dumpGenerator.writeStringField("value",
                                     config.get((String) item.getKey()));
      dumpGenerator.writeBooleanField("isFinal",
                                      config.finalParameters.contains(item.getKey()));
      String[] resources = config.updatingResource.get(item.getKey());
      String resource = UNKNOWN_RESOURCE;
      if(resources != null && resources.length > 0) {
        resource = resources[0];
      }
      dumpGenerator.writeStringField("resource", resource);
      dumpGenerator.writeEndObject();
    }
  }
  dumpGenerator.writeEndArray();
  dumpGenerator.writeEndObject();
  dumpGenerator.flush();
}
 
Example 3
Source File: Configuration.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 *  Writes out all the parameters and their properties (final and resource) to
 *  the given {@link Writer}
 *  The format of the output would be
 *  { "properties" : [ {key1,value1,key1.isFinal,key1.resource}, {key2,value2,
 *  key2.isFinal,key2.resource}... ] }
 *  It does not output the parameters of the configuration object which is
 *  loaded from an input stream.
 * @param out the Writer to write to
 * @throws IOException
 */
public static void dumpConfiguration(Configuration config,
    Writer out) throws IOException {
  JsonFactory dumpFactory = new JsonFactory();
  JsonGenerator dumpGenerator = dumpFactory.createJsonGenerator(out);
  dumpGenerator.writeStartObject();
  dumpGenerator.writeFieldName("properties");
  dumpGenerator.writeStartArray();
  dumpGenerator.flush();
  synchronized (config) {
    for (Entry<Object,Object> item: config.getProps().entrySet()) {
      dumpGenerator.writeStartObject();
      dumpGenerator.writeStringField("key", (String) item.getKey());
      dumpGenerator.writeStringField("value",
                                     config.get((String) item.getKey()));
      dumpGenerator.writeBooleanField("isFinal",
                                      config.finalParameters.contains(item.getKey()));
      String[] resources = config.updatingResource.get(item.getKey());
      String resource = UNKNOWN_RESOURCE;
      if(resources != null && resources.length > 0) {
        resource = resources[0];
      }
      dumpGenerator.writeStringField("resource", resource);
      dumpGenerator.writeEndObject();
    }
  }
  dumpGenerator.writeEndArray();
  dumpGenerator.writeEndObject();
  dumpGenerator.flush();
}
 
Example 4
Source File: Configuration.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 *  Writes out all the parameters and their properties (final and resource) to
 *  the given {@link Writer}
 *  The format of the output would be 
 *  { "properties" : [ {key1,value1,key1.isFinal,key1.resource}, {key2,value2,
 *  key2.isFinal,key2.resource}... ] } 
 *  It does not output the parameters of the configuration object which is 
 *  loaded from an input stream.
 * @param out the Writer to write to
 * @throws IOException
 */
public static void dumpConfiguration(Configuration config,
    Writer out) throws IOException {
  JsonFactory dumpFactory = new JsonFactory();
  JsonGenerator dumpGenerator = dumpFactory.createJsonGenerator(out);
  dumpGenerator.writeStartObject();
  dumpGenerator.writeFieldName("properties");
  dumpGenerator.writeStartArray();
  dumpGenerator.flush();
  synchronized (config) {
    for (Map.Entry<Object,Object> item: config.getProps().entrySet()) {
      dumpGenerator.writeStartObject();
      dumpGenerator.writeStringField("key", (String) item.getKey());
      dumpGenerator.writeStringField("value", 
                                     config.get((String) item.getKey()));
      dumpGenerator.writeBooleanField("isFinal",
                                      config.finalParameters.contains(item.getKey()));
      String[] resources = config.updatingResource.get(item.getKey());
      String resource = UNKNOWN_RESOURCE;
      if(resources != null && resources.length > 0) {
        resource = resources[0];
      }
      dumpGenerator.writeStringField("resource", resource);
      dumpGenerator.writeEndObject();
    }
  }
  dumpGenerator.writeEndArray();
  dumpGenerator.writeEndObject();
  dumpGenerator.flush();
}
 
Example 5
Source File: Configuration.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 *  Writes out all the parameters and their properties (final and resource) to
 *  the given {@link Writer}
 *  The format of the output would be 
 *  { "properties" : [ {key1,value1,key1.isFinal,key1.resource}, {key2,value2,
 *  key2.isFinal,key2.resource}... ] } 
 *  It does not output the parameters of the configuration object which is 
 *  loaded from an input stream.
 * @param out the Writer to write to
 * @throws IOException
 */
public static void dumpConfiguration(Configuration config,
    Writer out) throws IOException {
  JsonFactory dumpFactory = new JsonFactory();
  JsonGenerator dumpGenerator = dumpFactory.createJsonGenerator(out);
  dumpGenerator.writeStartObject();
  dumpGenerator.writeFieldName("properties");
  dumpGenerator.writeStartArray();
  dumpGenerator.flush();
  synchronized (config) {
    for (Map.Entry<Object,Object> item: config.getProps().entrySet()) {
      dumpGenerator.writeStartObject();
      dumpGenerator.writeStringField("key", (String) item.getKey());
      dumpGenerator.writeStringField("value", 
                                     config.get((String) item.getKey()));
      dumpGenerator.writeBooleanField("isFinal",
                                      config.finalParameters.contains(item.getKey()));
      String[] resources = config.updatingResource.get(item.getKey());
      String resource = UNKNOWN_RESOURCE;
      if(resources != null && resources.length > 0) {
        resource = resources[0];
      }
      dumpGenerator.writeStringField("resource", resource);
      dumpGenerator.writeEndObject();
    }
  }
  dumpGenerator.writeEndArray();
  dumpGenerator.writeEndObject();
  dumpGenerator.flush();
}
 
Example 6
Source File: Configuration.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 *  Writes out all the parameters and their properties (final and resource) to
 *  the given {@link Writer}
 *  The format of the output would be
 *  { "properties" : [ {key1,value1,key1.isFinal,key1.resource}, {key2,value2,
 *  key2.isFinal,key2.resource}... ] }
 *  It does not output the parameters of the configuration object which is
 *  loaded from an input stream.
 * @param out the Writer to write to
 * @throws IOException
 */
public static void dumpConfiguration(Configuration config,
    Writer out) throws IOException {
  JsonFactory dumpFactory = new JsonFactory();
  JsonGenerator dumpGenerator = dumpFactory.createJsonGenerator(out);
  dumpGenerator.writeStartObject();
  dumpGenerator.writeFieldName("properties");
  dumpGenerator.writeStartArray();
  dumpGenerator.flush();
  synchronized (config) {
    for (Entry<Object,Object> item: config.getProps().entrySet()) {
      dumpGenerator.writeStartObject();
      dumpGenerator.writeStringField("key", (String) item.getKey());
      dumpGenerator.writeStringField("value",
                                     config.get((String) item.getKey()));
      dumpGenerator.writeBooleanField("isFinal",
                                      config.finalParameters.contains(item.getKey()));
      String[] resources = config.updatingResource.get(item.getKey());
      String resource = UNKNOWN_RESOURCE;
      if(resources != null && resources.length > 0) {
        resource = resources[0];
      }
      dumpGenerator.writeStringField("resource", resource);
      dumpGenerator.writeEndObject();
    }
  }
  dumpGenerator.writeEndArray();
  dumpGenerator.writeEndObject();
  dumpGenerator.flush();
}
 
Example 7
Source File: JsonMapper.java    From ReactiveLab with Apache License 2.0 4 votes vote down vote up
static String toJson(Metrics commandMetrics) throws IOException {
    StringWriter jsonString = new StringWriter();
    JsonGenerator json = jsonFactory.createJsonGenerator(jsonString);

    json.writeStartObject();
    json.writeStringField("type", "HystrixCommand"); // act as this as we are hijacking Hystrix for the dashboard
    json.writeStringField("name", commandMetrics.getName());
    json.writeStringField("group", "");
    json.writeNumberField("currentTime", System.currentTimeMillis());

    json.writeBooleanField("isCircuitBreakerOpen", false);

    long errors = commandMetrics.getRollingNumber().getRollingSum(Metrics.EventType.FAILURE);
    long success = commandMetrics.getRollingNumber().getRollingSum(Metrics.EventType.SUCCESS);
    long requests = success + errors;
    int errorPercentage = (int) ((double) errors / requests * 100);

    json.writeNumberField("errorPercentage", errorPercentage);
    json.writeNumberField("errorCount", errors);
    json.writeNumberField("requestCount", requests);

    // rolling counters
    json.writeNumberField("rollingCountCollapsedRequests", 0);
    json.writeNumberField("rollingCountExceptionsThrown", commandMetrics.getRollingNumber().getRollingSum(Metrics.EventType.EXCEPTION_THROWN));
    json.writeNumberField("rollingCountFailure", errors);
    json.writeNumberField("rollingCountFallbackFailure", 0);
    json.writeNumberField("rollingCountFallbackRejection", 0);
    json.writeNumberField("rollingCountFallbackSuccess", 0);
    json.writeNumberField("rollingCountResponsesFromCache", 0);
    json.writeNumberField("rollingCountSemaphoreRejected", 0);
    json.writeNumberField("rollingCountShortCircuited", 0);
    json.writeNumberField("rollingCountSuccess", success);
    json.writeNumberField("rollingCountThreadPoolRejected", 0);
    json.writeNumberField("rollingCountTimeout", 0);

    json.writeNumberField("currentConcurrentExecutionCount", commandMetrics.getRollingNumber().getRollingMaxValue(Metrics.EventType.CONCURRENCY_MAX_ACTIVE));

    // latency percentiles
    json.writeNumberField("latencyExecute_mean", commandMetrics.getRollingPercentile().getMean());
    json.writeObjectFieldStart("latencyExecute");
    json.writeNumberField("0", commandMetrics.getRollingPercentile().getPercentile(0));
    json.writeNumberField("25", commandMetrics.getRollingPercentile().getPercentile(25));
    json.writeNumberField("50", commandMetrics.getRollingPercentile().getPercentile(50));
    json.writeNumberField("75", commandMetrics.getRollingPercentile().getPercentile(75));
    json.writeNumberField("90", commandMetrics.getRollingPercentile().getPercentile(90));
    json.writeNumberField("95", commandMetrics.getRollingPercentile().getPercentile(95));
    json.writeNumberField("99", commandMetrics.getRollingPercentile().getPercentile(99));
    json.writeNumberField("99.5", commandMetrics.getRollingPercentile().getPercentile(99.5));
    json.writeNumberField("100", commandMetrics.getRollingPercentile().getPercentile(100));
    json.writeEndObject();

    json.writeNumberField("latencyTotal_mean", commandMetrics.getRollingPercentile().getMean());
    json.writeObjectFieldStart("latencyTotal");
    json.writeNumberField("0", commandMetrics.getRollingPercentile().getPercentile(0));
    json.writeNumberField("25", commandMetrics.getRollingPercentile().getPercentile(25));
    json.writeNumberField("50", commandMetrics.getRollingPercentile().getPercentile(50));
    json.writeNumberField("75", commandMetrics.getRollingPercentile().getPercentile(75));
    json.writeNumberField("90", commandMetrics.getRollingPercentile().getPercentile(90));
    json.writeNumberField("95", commandMetrics.getRollingPercentile().getPercentile(95));
    json.writeNumberField("99", commandMetrics.getRollingPercentile().getPercentile(99));
    json.writeNumberField("99.5", commandMetrics.getRollingPercentile().getPercentile(99.5));
    json.writeNumberField("100", commandMetrics.getRollingPercentile().getPercentile(100));
    json.writeEndObject();
    
    json.writeNumberField("propertyValue_circuitBreakerRequestVolumeThreshold", 0);
    json.writeNumberField("propertyValue_circuitBreakerSleepWindowInMilliseconds", 0);
    json.writeNumberField("propertyValue_circuitBreakerErrorThresholdPercentage", 0);
    json.writeBooleanField("propertyValue_circuitBreakerForceOpen", false);
    json.writeBooleanField("propertyValue_circuitBreakerForceClosed", false);
    json.writeBooleanField("propertyValue_circuitBreakerEnabled", false);

    json.writeStringField("propertyValue_executionIsolationStrategy", "");
    json.writeNumberField("propertyValue_executionIsolationThreadTimeoutInMilliseconds", 0);
    json.writeBooleanField("propertyValue_executionIsolationThreadInterruptOnTimeout", false);
    json.writeStringField("propertyValue_executionIsolationThreadPoolKeyOverride", "");
    json.writeNumberField("propertyValue_executionIsolationSemaphoreMaxConcurrentRequests", 0);
    json.writeNumberField("propertyValue_fallbackIsolationSemaphoreMaxConcurrentRequests", 0);

    json.writeNumberField("propertyValue_metricsRollingStatisticalWindowInMilliseconds", 10000);

    json.writeBooleanField("propertyValue_requestCacheEnabled", false);
    json.writeBooleanField("propertyValue_requestLogEnabled", false);

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

    json.writeEndObject();
    json.close();

    return jsonString.getBuffer().toString();
}