Source:
public void run() { LOG.info("Starting Query purger thread"); while (!stopped && !queryPurger.isInterrupted()) { FinishedQuery finished = null; try { finished = finishedQueries.take(); } catch (InterruptedException e) { LOG.info("QueryPurger has been interrupted, exiting"); return; } try { FinishedGrillQuery finishedQuery = new FinishedGrillQuery(finished.getCtx()); if (finished.ctx.getStatus().getStatus() == Status.SUCCESSFUL) { if (finished.ctx.getStatus().isResultSetAvailable()) { GrillResultSet set = getResultset(finished.getCtx().getQueryHandle()); if(set != null &&PersistentResultSet.class.isAssignableFrom(set.getClass())) { GrillResultSetMetadata metadata = set.getMetadata(); String outputPath = ((PersistentResultSet) set).getOutputPath(); int rows = set.size(); finishedQuery.setMetadataClass(metadata.getClass().getName()); finishedQuery.setResult(outputPath); finishedQuery.setMetadata(mapper.writeValueAsString(metadata)); finishedQuery.setRows(rows); } } } try { LOG.warn("XXXXX " + finishedQuery); grillServerDao.insertFinishedQuery(finishedQuery); } catch (Exception e) { LOG.warn("Exception while purging query ",e); finishedQueries.add(finished); continue; } synchronized (finished.ctx) { finished.ctx.setFinishedQueryPersisted(true); try { if (finished.getCtx().getSelectedDriver() != null) { finished.getCtx().getSelectedDriver().closeQuery( finished.getCtx().getQueryHandle()); } } catch (Exception e) { LOG.warn("Exception while closing query with selected driver.", e); } allQueries.remove(finished.getCtx().getQueryHandle()); resultSets.remove(finished.getCtx().getQueryHandle()); } fireStatusChangeEvent(finished.getCtx(), new QueryStatus(1f, Status.CLOSED, "Query purged", false, null, null), finished.getCtx().getStatus()); LOG.info("Query purged: " + finished.getCtx().getQueryHandle()); } catch (GrillException e) { LOG.error("Error closing query ", e); } catch (Exception e) { LOG.error("Error in query purger", e); } } LOG.info("QueryPurger exited"); }

Target:
public void run() { LOG.info("Starting Query purger thread"); while (!stopped && !queryPurger.isInterrupted()) { FinishedQuery finished = null; try { finished = finishedQueries.take(); } catch (InterruptedException e) { LOG.info("QueryPurger has been interrupted, exiting"); return; } try { FinishedGrillQuery finishedQuery = new FinishedGrillQuery(finished.getCtx()); if (finished.ctx.getStatus().getStatus() == Status.SUCCESSFUL) { if (finished.ctx.getStatus().isResultSetAvailable()) { GrillResultSet set = getResultset(finished.getCtx().getQueryHandle()); if(set != null &&PersistentResultSet.class.isAssignableFrom(set.getClass())) { GrillResultSetMetadata metadata = set.getMetadata(); String outputPath = ((PersistentResultSet) set).getOutputPath(); int rows = set.size(); finishedQuery.setMetadataClass(metadata.getClass().getName()); finishedQuery.setResult(outputPath); finishedQuery.setMetadata(mapper.writeValueAsString(metadata)); finishedQuery.setRows(rows); } } } try { grillServerDao.insertFinishedQuery(finishedQuery); } catch (Exception e) { LOG.warn("Exception while purging query ",e); finishedQueries.add(finished); continue; } synchronized (finished.ctx) { finished.ctx.setFinishedQueryPersisted(true); try { if (finished.getCtx().getSelectedDriver() != null) { finished.getCtx().getSelectedDriver().closeQuery( finished.getCtx().getQueryHandle()); } } catch (Exception e) { LOG.warn("Exception while closing query with selected driver.", e); } allQueries.remove(finished.getCtx().getQueryHandle()); resultSets.remove(finished.getCtx().getQueryHandle()); } fireStatusChangeEvent(finished.getCtx(), new QueryStatus(1f, Status.CLOSED, "Query purged", false, null, null), finished.getCtx().getStatus()); LOG.info("Query purged: " + finished.getCtx().getQueryHandle()); } catch (GrillException e) { LOG.error("Error closing query ", e); } catch (Exception e) { LOG.error("Error in query purger", e); } } LOG.info("QueryPurger exited"); }