Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.druid.server;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.io.CountingOutputStream;
import org.apache.druid.client.DirectDruidClient;
import org.apache.druid.error.DruidException;
import org.apache.druid.error.ErrorResponse;
import org.apache.druid.error.QueryExceptionCompat;
import org.apache.druid.java.util.common.ISE;
import org.apache.druid.java.util.common.RE;
import org.apache.druid.java.util.common.StringUtils;
import org.apache.druid.java.util.common.guava.Accumulator;
import org.apache.druid.java.util.common.guava.Sequence;
import org.apache.druid.java.util.common.logger.Logger;
import org.apache.druid.query.QueryException;
import org.apache.druid.query.QueryInterruptedException;
import org.apache.druid.query.TruncatedResponseContextException;
import org.apache.druid.query.context.ResponseContext;
import org.apache.druid.server.security.AuthConfig;
import org.apache.druid.server.security.ForbiddenException;
import javax.annotation.Nullable;
import javax.servlet.AsyncContext;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.io.Closeable;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Map;
public abstract class QueryResultPusher
{
private static final Logger log = new Logger(QueryResultPusher.class);
private final HttpServletRequest request;
private final String queryId;
private final ObjectMapper jsonMapper;
private final ResponseContextConfig responseContextConfig;
private final DruidNode selfNode;
private final QueryResource.QueryMetricCounter counter;
private final MediaType contentType;
private final Map extraHeaders;
private StreamingHttpResponseAccumulator accumulator;
private AsyncContext asyncContext;
private HttpServletResponse response;
public QueryResultPusher(
HttpServletRequest request,
ObjectMapper jsonMapper,
ResponseContextConfig responseContextConfig,
DruidNode selfNode,
QueryResource.QueryMetricCounter counter,
String queryId,
MediaType contentType,
Map extraHeaders
)
{
this.request = request;
this.queryId = queryId;
this.jsonMapper = jsonMapper;
this.responseContextConfig = responseContextConfig;
this.selfNode = selfNode;
this.counter = counter;
this.contentType = contentType;
this.extraHeaders = extraHeaders;
}
/**
* Builds a ResultsWriter to start the lifecycle of the QueryResultPusher. The ResultsWriter encapsulates the logic
* to run the query, serialize it and also report success/failure.
*
* This response must not be null. The job of this ResultsWriter is largely to provide lifecycle management to
* the query running and reporting, so this object must never be null.
*
* This start() method should do as little work as possible, it should really just make the ResultsWriter and return.
*
* @return a new ResultsWriter
*/
public abstract ResultsWriter start();
public abstract void writeException(Exception e, OutputStream out) throws IOException;
/**
* Pushes results out. Can sometimes return a JAXRS Response object instead of actually pushing to the output
* stream, primarily for error handling that occurs before switching the servlet to asynchronous mode.
*
* @return null if the response has already been handled and pushed out, or a non-null Response object if it expects
* the container to put the bytes on the wire.
*/
@Nullable
public Response push()
{
ResultsWriter resultsWriter = null;
try {
resultsWriter = start();
final Response.ResponseBuilder startResponse = resultsWriter.start();
if (startResponse != null) {
startResponse.header(QueryResource.QUERY_ID_RESPONSE_HEADER, queryId);
for (Map.Entry entry : extraHeaders.entrySet()) {
startResponse.header(entry.getKey(), entry.getValue());
}
return startResponse.build();
}
final QueryResponse