Search in sources :

Example 1 with DocprocMessageProcessor

use of com.yahoo.feedapi.DocprocMessageProcessor in project vespa by vespa-engine.

the class VespaFeedHandler method handle.

public HttpResponse handle(HttpRequest request, RouteMetricSet.ProgressCallback callback) {
    if (request.getProperty("status") != null) {
        return new MetricResponse(context.getMetrics().getMetricSet());
    }
    try {
        int busy = busyThreads.incrementAndGet();
        if (busy > maxBusyThreads)
            return new EmptyResponse(com.yahoo.jdisc.http.HttpResponse.Status.SERVICE_UNAVAILABLE);
        boolean asynchronous = request.getBooleanProperty("asynchronous");
        MessagePropertyProcessor.PropertySetter properties = getPropertyProcessor().buildPropertySetter(request);
        String route = properties.getRoute().toString();
        FeedResponse response = new FeedResponse(new RouteMetricSet(route, callback));
        SingleSender sender = new SingleSender(response, getSharedSender(route), !asynchronous);
        sender.addMessageProcessor(properties);
        sender.addMessageProcessor(new DocprocMessageProcessor(getDocprocChain(request), getDocprocServiceRegistry(request)));
        Feeder feeder = createFeeder(sender, request);
        feeder.setAbortOnDocumentError(properties.getAbortOnDocumentError());
        feeder.setCreateIfNonExistent(properties.getCreateIfNonExistent());
        response.setAbortOnFeedError(properties.getAbortOnFeedError());
        List<String> errors = feeder.parse();
        for (String s : errors) {
            response.addXMLParseError(s);
        }
        if (errors.size() > 0 && feeder instanceof XMLFeeder) {
            response.addXMLParseError("If you are trying to feed JSON, set the Content-Type header to application/json.");
        }
        sender.done();
        if (asynchronous) {
            return response;
        }
        long millis = getTimeoutMillis(request);
        boolean completed = sender.waitForPending(millis);
        if (!completed) {
            response.addError(Error.TIMEOUT, "Timed out after " + millis + " ms waiting for responses");
        }
        response.done();
        return response;
    } finally {
        busyThreads.decrementAndGet();
    }
}
Also used : DocprocMessageProcessor(com.yahoo.feedapi.DocprocMessageProcessor) RouteMetricSet(com.yahoo.clientmetrics.RouteMetricSet) SingleSender(com.yahoo.feedapi.SingleSender) XMLFeeder(com.yahoo.feedapi.XMLFeeder) Feeder(com.yahoo.feedapi.Feeder) JsonFeeder(com.yahoo.feedapi.JsonFeeder) XMLFeeder(com.yahoo.feedapi.XMLFeeder) EmptyResponse(com.yahoo.container.jdisc.EmptyResponse) MessagePropertyProcessor(com.yahoo.feedapi.MessagePropertyProcessor)

Aggregations

RouteMetricSet (com.yahoo.clientmetrics.RouteMetricSet)1 EmptyResponse (com.yahoo.container.jdisc.EmptyResponse)1 DocprocMessageProcessor (com.yahoo.feedapi.DocprocMessageProcessor)1 Feeder (com.yahoo.feedapi.Feeder)1 JsonFeeder (com.yahoo.feedapi.JsonFeeder)1 MessagePropertyProcessor (com.yahoo.feedapi.MessagePropertyProcessor)1 SingleSender (com.yahoo.feedapi.SingleSender)1 XMLFeeder (com.yahoo.feedapi.XMLFeeder)1