/* * 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.drill.test; import java.util.concurrent.BlockingQueue; import org.apache.drill.common.exceptions.UserException; import org.apache.drill.exec.proto.UserBitShared.QueryId; import org.apache.drill.exec.proto.UserBitShared.QueryResult.QueryState; import org.apache.drill.exec.rpc.ConnectionThrottle; import org.apache.drill.exec.rpc.user.QueryDataBatch; import org.apache.drill.exec.rpc.user.UserResultsListener; import org.apache.drill.shaded.guava.com.google.common.collect.Queues; /** * Drill query event listener that buffers rows into a producer-consumer * queue. Allows rows to be received asynchronously, but processed by * a synchronous reader. *
* Query messages are transformed into events: query ID, batch,
* EOF or error.
*/
public class BufferingQueryEventListener implements UserResultsListener
{
private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(BufferingQueryEventListener.class);
public static class QueryEvent
{
public enum Type { QUERY_ID, BATCH, EOF, ERROR }
public final Type type;
public QueryId queryId;
public QueryDataBatch batch;
public Exception error;
public QueryState state;
public QueryEvent(QueryId queryId) {
this.queryId = queryId;
this.type = Type.QUERY_ID;
}
public QueryEvent(Exception ex) {
error = ex;
type = Type.ERROR;
}
public QueryEvent(QueryDataBatch batch) {
this.batch = batch;
type = Type.BATCH;
}
public QueryEvent(QueryState state) {
this.type = Type.EOF;
this.state = state;
}
}
private BlockingQueue