Search in sources :

Example 1 with CounterConfigurationSerializer

use of org.infinispan.counter.configuration.CounterConfigurationSerializer in project infinispan by infinispan.

the class CounterResource method getConfig.

private CompletionStage<RestResponse> getConfig(RestRequest request) {
    NettyRestResponse.Builder responseBuilder = new NettyRestResponse.Builder();
    String counterName = request.variables().get("counterName");
    return invocationHelper.getCounterManager().getConfigurationAsync(counterName).thenApply(cfg -> {
        if (cfg == null)
            return responseBuilder.status(NOT_FOUND).build();
        AbstractCounterConfiguration parsedConfig = ConvertUtil.configToParsedConfig(counterName, cfg);
        CounterConfigurationSerializer ccs = new CounterConfigurationSerializer();
        StringBuilderWriter sw = new StringBuilderWriter();
        try (ConfigurationWriter w = ConfigurationWriter.to(sw).withType(APPLICATION_JSON).build()) {
            ccs.serializeConfiguration(w, parsedConfig);
        }
        return responseBuilder.entity(sw.toString()).contentType(APPLICATION_JSON).build();
    });
}
Also used : CounterConfigurationSerializer(org.infinispan.counter.configuration.CounterConfigurationSerializer) StringBuilderWriter(org.infinispan.commons.io.StringBuilderWriter) ConfigurationWriter(org.infinispan.commons.configuration.io.ConfigurationWriter) CounterManagerConfigurationBuilder(org.infinispan.counter.configuration.CounterManagerConfigurationBuilder) AbstractCounterConfiguration(org.infinispan.counter.configuration.AbstractCounterConfiguration) NettyRestResponse(org.infinispan.rest.NettyRestResponse)

Aggregations

ConfigurationWriter (org.infinispan.commons.configuration.io.ConfigurationWriter)1 StringBuilderWriter (org.infinispan.commons.io.StringBuilderWriter)1 AbstractCounterConfiguration (org.infinispan.counter.configuration.AbstractCounterConfiguration)1 CounterConfigurationSerializer (org.infinispan.counter.configuration.CounterConfigurationSerializer)1 CounterManagerConfigurationBuilder (org.infinispan.counter.configuration.CounterManagerConfigurationBuilder)1 NettyRestResponse (org.infinispan.rest.NettyRestResponse)1