<commit_before>package org.wildfly.swarm.examples.multi.events;

import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectReader;
import com.netflix.ribbon.ClientOptions;
import com.netflix.ribbon.Ribbon;
import com.netflix.ribbon.http.HttpResourceGroup;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufInputStream;
import rx.Observable;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.container.AsyncResponse;
import javax.ws.rs.container.Suspended;
import javax.ws.rs.ext.MessageBodyReader;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author <NAME>
 */
@Path("/")
public class EventsResource {

    private final TimeService time;

    public EventsResource() {
        ClientOptions options = ClientOptions.create();
        options.withConfigurationBasedServerList("localhost:8181");
        HttpResourceGroup resourceGroup = Ribbon.createHttpResourceGroup( "time", options );
        this.time = Ribbon.from( TimeService.class, resourceGroup );
    }

    @GET
    @Produces("application/json")
    public void get(@Suspended final AsyncResponse asyncResponse) {
        Observable<ByteBuf> obs = this.time.currentTime().observe();

        obs.subscribe(
                (result) -> {
                    try {
                        ObjectMapper mapper = new ObjectMapper();
                        ObjectReader reader = mapper.reader();
                        JsonFactory factory = new JsonFactory();
                        JsonParser parser = factory.createParser(new ByteBufInputStream(result));
                        Map map = reader.readValue(parser, Map.class);
                        int hour = (int) map.get( "h" );
                        List<String> events = new ArrayList<>();
                        for ( int i = 1 ; i <= 10 ; ++i ) {
                            events.add( "Event #" + i + " at " + hour + ":00" );
                        }
                        asyncResponse.resume(events);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                },
                (err) -> {
                    asyncResponse.resume(err);
                });
    }
}<commit_msg>Better-handled error.<commit_after>package org.wildfly.swarm.examples.multi.events;

import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectReader;
import com.netflix.ribbon.ClientOptions;
import com.netflix.ribbon.Ribbon;
import com.netflix.ribbon.http.HttpResourceGroup;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufInputStream;
import rx.Observable;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.container.AsyncResponse;
import javax.ws.rs.container.Suspended;
import javax.ws.rs.ext.MessageBodyReader;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author <NAME>
 */
@Path("/")
public class EventsResource {

    private final TimeService time;

    public EventsResource() {
        ClientOptions options = ClientOptions.create();
        options.withConfigurationBasedServerList("localhost:8181");
        HttpResourceGroup resourceGroup = Ribbon.createHttpResourceGroup( "time", options );
        this.time = Ribbon.from( TimeService.class, resourceGroup );
    }

    @GET
    @Produces("application/json")
    public void get(@Suspended final AsyncResponse asyncResponse) {
        Observable<ByteBuf> obs = this.time.currentTime().observe();

        obs.subscribe(
                (result) -> {
                    try {
                        ObjectMapper mapper = new ObjectMapper();
                        ObjectReader reader = mapper.reader();
                        JsonFactory factory = new JsonFactory();
                        JsonParser parser = factory.createParser(new ByteBufInputStream(result));
                        Map map = reader.readValue(parser, Map.class);
                        int hour = (int) map.get( "h" );
                        List<String> events = new ArrayList<>();
                        for ( int i = 1 ; i <= 10 ; ++i ) {
                            events.add( "Event #" + i + " at " + hour + ":00" );
                        }
                        asyncResponse.resume(events);
                    } catch (IOException e) {
                        asyncResponse.resume(e);
                    }
                },
                (err) -> {
                    asyncResponse.resume(err);
                });
    }
}
{'fraction_non_alphanumeric': 0.11124354390147001, 'fraction_numerical': 0.003575685339690107, 'mean_word_length': 2.135118306351183, 'pattern_counts': {'":': 2, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 10}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5400447', 'n_tokens_mistral': 1407, 'n_tokens_neox': 1299, 'n_words': 267}