From: <mrp...@us...> - 2014-09-26 14:26:10
|
Revision: 8665 http://sourceforge.net/p/bigdata/code/8665 Author: mrpersonick Date: 2014-09-26 14:26:04 +0000 (Fri, 26 Sep 2014) Log Message: ----------- Ticket #1018: cancelAll() functionality on remote sail connection Modified Paths: -------------- branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/java/com/bigdata/rdf/sparql/ast/service/RemoteServiceCallImpl.java branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/remote/BigdataSailRemoteRepositoryConnection.java branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/client/IPreparedBooleanQuery.java branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/client/IPreparedGraphQuery.java branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/client/IPreparedSparqlUpdate.java branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/client/IPreparedTupleQuery.java branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/client/RemoteRepository.java branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/client/RemoteRepositoryManager.java Added Paths: ----------- branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/client/IPreparedQueryListener.java Modified: branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/java/com/bigdata/rdf/sparql/ast/service/RemoteServiceCallImpl.java =================================================================== --- branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/java/com/bigdata/rdf/sparql/ast/service/RemoteServiceCallImpl.java 2014-09-26 13:03:10 UTC (rev 8664) +++ branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/java/com/bigdata/rdf/sparql/ast/service/RemoteServiceCallImpl.java 2014-09-26 14:26:04 UTC (rev 8665) @@ -172,7 +172,7 @@ // //// queryResult = parseResults(checkResponseCode(doSparqlQuery(opts))); - queryResult = repo.tupleResults(o, queryId); + queryResult = repo.tupleResults(o, queryId, null); } finally { Modified: branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/remote/BigdataSailRemoteRepositoryConnection.java =================================================================== --- branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/remote/BigdataSailRemoteRepositoryConnection.java 2014-09-26 13:03:10 UTC (rev 8664) +++ branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/remote/BigdataSailRemoteRepositoryConnection.java 2014-09-26 14:26:04 UTC (rev 8665) @@ -32,8 +32,16 @@ import java.io.InputStream; import java.io.Reader; import java.net.URL; +import java.util.Arrays; +import java.util.Collections; import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; +import java.util.concurrent.locks.ReentrantReadWriteLock; import org.apache.log4j.Logger; import org.openrdf.model.Graph; @@ -71,6 +79,7 @@ import com.bigdata.rdf.sail.webapp.client.IPreparedBooleanQuery; import com.bigdata.rdf.sail.webapp.client.IPreparedGraphQuery; +import com.bigdata.rdf.sail.webapp.client.IPreparedQueryListener; import com.bigdata.rdf.sail.webapp.client.IPreparedSparqlUpdate; import com.bigdata.rdf.sail.webapp.client.IPreparedTupleQuery; import com.bigdata.rdf.sail.webapp.client.RemoteRepository; @@ -94,7 +103,8 @@ * setting a binding. * TODO Support baseURIs */ -public class BigdataSailRemoteRepositoryConnection implements RepositoryConnection { +public class BigdataSailRemoteRepositoryConnection + implements RepositoryConnection, IPreparedQueryListener { private static final transient Logger log = Logger .getLogger(BigdataSailRemoteRepositoryConnection.class); @@ -107,7 +117,140 @@ this.repo = repo; } + + /** + * A concurrency-managed list of running query ids. + */ + private final Map<UUID, UUID> queryIds = new ConcurrentHashMap<UUID, UUID>(); + + /** + * Manage access to the query ids. + */ + private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); + /** + * Cancel the specified query. + * + * @param queryId + * The query id. + * @throws Exception + */ + public void cancel(final UUID queryId) throws Exception { + + lock.readLock().lock(); + + try { + + repo.getRemoteRepository().cancel(queryId); + queryIds.remove(queryId); + + if (log.isDebugEnabled()) { + log.debug("Query cancelled: " + queryId); + log.debug("Queries running: " + Arrays.toString(queryIds.keySet().toArray())); + } + + } finally { + lock.readLock().unlock(); + } + + } + + /** + * Cancel all queries started by this connection that have not completed + * yet at the time of this request. + * + * @param queryId + * The query id. + * @throws Exception + */ + public void cancelAll() throws Exception { + + lock.writeLock().lock(); + + try { + + final RemoteRepository repo = this.repo.getRemoteRepository(); + + for (UUID queryId : queryIds.keySet()) { + repo.cancel(queryId); + } + queryIds.clear(); + + if (log.isDebugEnabled()) { + log.debug("All queries cancelled."); + log.debug("Queries running: " + Arrays.toString(queryIds.keySet().toArray())); + } + + } finally { + lock.writeLock().unlock(); + } + } + + /** + * Return a list of all queries initiated by this connection that have + * not completed. + * @return + */ + public Set<UUID> getQueryIds() { + + lock.readLock().lock(); + + try { + return Collections.unmodifiableSet(queryIds.keySet()); + } finally { + lock.readLock().unlock(); + } + } + + /** + * Callback from the query evaluation object that the query result has been + * closed (the query either completed or was already cancelled). + * + * @param queryId + * The query id. + */ + public void closed(final UUID queryId) { + + lock.readLock().lock(); + + try { + + queryIds.remove(queryId); + + if (log.isDebugEnabled()) { + log.debug("Query completed normally: " + queryId); + log.debug("Queries running: " + Arrays.toString(queryIds.keySet().toArray())); + } + + } finally { + lock.readLock().unlock(); + } + } + + /** + * Add a newly launched query id. + * + * @param queryId + * The query id. + */ + public void addQueryId(final UUID queryId) { + + lock.readLock().lock(); + + try { + + queryIds.put(queryId, queryId); + + if (log.isDebugEnabled()) { + log.debug("Query started: " + queryId); Thread.dumpStack(); + log.debug("Queries running: " + Arrays.toString(queryIds.keySet().toArray())); + } + + } finally { + lock.readLock().unlock(); + } + } + public long count(final Resource s, final URI p, final Value o, final Resource... c) throws RepositoryException { @@ -135,9 +278,17 @@ final RemoteRepository remote = repo.getRemoteRepository(); - final GraphQueryResult src = - remote.getStatements(s, p, o, includeInferred, c); + final IPreparedGraphQuery query = + remote.getStatements2(s, p, o, includeInferred, c); + + /* + * Add to the list of running queries. Will be later removed + * via the IPreparedQueryListener callback. + */ + addQueryId(query.getQueryId()); + final GraphQueryResult src = query.evaluate(this); + /* * Well this was certainly annoying. is there a better way? */ @@ -209,7 +360,7 @@ } @Override - public BooleanQuery prepareBooleanQuery(final QueryLanguage ql, + public RemoteBooleanQuery prepareBooleanQuery(final QueryLanguage ql, final String query) throws RepositoryException, MalformedQueryException { @@ -225,90 +376,14 @@ final IPreparedBooleanQuery q = remote.prepareBooleanQuery(query); - /* - * Only supports evaluate() right now. - */ - return new BooleanQuery() { - - @Override - public boolean evaluate() throws QueryEvaluationException { - try { - return q.evaluate(); - } catch (Exception ex) { - throw new QueryEvaluationException(ex); - } - } - - /** - * @see http://trac.bigdata.com/ticket/914 (Set timeout on remote query) - */ - @Override - public int getMaxQueryTime() { - - final long millis = q.getMaxQueryMillis(); - - if (millis == -1) { - // Note: -1L is returned if the http header is not specified. - return -1; - - } - - return (int) TimeUnit.MILLISECONDS.toSeconds(millis); - - } - - /** - * @see http://trac.bigdata.com/ticket/914 (Set timeout on remote query) - */ - @Override - public void setMaxQueryTime(final int seconds) { - - q.setMaxQueryMillis(TimeUnit.SECONDS.toMillis(seconds)); - - } - - @Override - public void clearBindings() { - throw new UnsupportedOperationException(); - } - - @Override - public BindingSet getBindings() { - throw new UnsupportedOperationException(); - } - - @Override - public Dataset getDataset() { - throw new UnsupportedOperationException(); - } - - @Override - public boolean getIncludeInferred() { - throw new UnsupportedOperationException(); - } - - @Override - public void removeBinding(String arg0) { - throw new UnsupportedOperationException(); - } - - @Override - public void setBinding(String arg0, Value arg1) { - throw new UnsupportedOperationException(); - } - - @Override - public void setDataset(Dataset arg0) { - throw new UnsupportedOperationException(); - } - - @Override - public void setIncludeInferred(boolean arg0) { - throw new UnsupportedOperationException(); - } - - }; - + /* + * Add to the list of running queries. Will be later removed + * via the IPreparedQueryListener callback. + */ + addQueryId(q.getQueryId()); + + return new RemoteBooleanQuery(q); + } catch (Exception ex) { throw new RepositoryException(ex); @@ -345,98 +420,14 @@ final RemoteRepository remote = repo.getRemoteRepository(); final IPreparedGraphQuery q = remote.prepareGraphQuery(query); - - /* - * Only supports evaluate() right now. - */ - return new GraphQuery() { - - @Override - public GraphQueryResult evaluate() throws QueryEvaluationException { - try { - return q.evaluate(); - } catch (Exception ex) { - throw new QueryEvaluationException(ex); - } - } - - /** - * @see http://trac.bigdata.com/ticket/914 (Set timeout on - * remote query) - */ - @Override - public int getMaxQueryTime() { - final long millis = q.getMaxQueryMillis(); - - if (millis == -1) { - // Note: -1L is returned if the http header is not specified. - return -1; - - } - - return (int) TimeUnit.MILLISECONDS.toSeconds(millis); - - } - - /** - * @see http://trac.bigdata.com/ticket/914 (Set timeout on - * remote query) - */ - @Override - public void setMaxQueryTime(final int seconds) { - - q.setMaxQueryMillis(TimeUnit.SECONDS.toMillis(seconds)); - - } - - @Override - public void clearBindings() { - throw new UnsupportedOperationException(); - } - - @Override - public BindingSet getBindings() { - throw new UnsupportedOperationException(); - } - - @Override - public Dataset getDataset() { - throw new UnsupportedOperationException(); - } - - @Override - public boolean getIncludeInferred() { - throw new UnsupportedOperationException(); - } - - @Override - public void removeBinding(String arg0) { - throw new UnsupportedOperationException(); - } - - @Override - public void setBinding(String arg0, Value arg1) { - throw new UnsupportedOperationException(); - } - - @Override - public void setDataset(Dataset arg0) { - throw new UnsupportedOperationException(); - } - - @Override - public void setIncludeInferred(boolean arg0) { - throw new UnsupportedOperationException(); - } - - @Override - public void evaluate(RDFHandler arg0) - throws QueryEvaluationException, RDFHandlerException { - throw new UnsupportedOperationException(); - } - - }; + /* + * Add to the list of running queries. Will be later removed + * via the IPreparedQueryListener callback. + */ + addQueryId(q.getQueryId()); + + return new RemoteGraphQuery(q); } catch (Exception ex) { @@ -494,98 +485,14 @@ final RemoteRepository remote = repo.getRemoteRepository(); final IPreparedTupleQuery q = remote.prepareTupleQuery(query); - - /* - * Only supports evaluate() right now. - */ - return new TupleQuery() { - - @Override - public TupleQueryResult evaluate() throws QueryEvaluationException { - try { - return q.evaluate(); - } catch (Exception ex) { - throw new QueryEvaluationException(ex); - } - } - /** - * @see http://trac.bigdata.com/ticket/914 (Set timeout on - * remote query) - */ - @Override - public int getMaxQueryTime() { - - final long millis = q.getMaxQueryMillis(); - - if (millis == -1) { - // Note: -1L is returned if the http header is not specified. - return -1; - - } - - return (int) TimeUnit.MILLISECONDS.toSeconds(millis); - - } - - /** - * @see http://trac.bigdata.com/ticket/914 (Set timeout on - * remote query) - */ - @Override - public void setMaxQueryTime(final int seconds) { - - q.setMaxQueryMillis(TimeUnit.SECONDS.toMillis(seconds)); - - } - - @Override - public void clearBindings() { - throw new UnsupportedOperationException(); - } - - @Override - public BindingSet getBindings() { - throw new UnsupportedOperationException(); - } - - @Override - public Dataset getDataset() { - throw new UnsupportedOperationException(); - } - - @Override - public boolean getIncludeInferred() { - throw new UnsupportedOperationException(); - } - - @Override - public void removeBinding(String arg0) { - throw new UnsupportedOperationException(); - } - - @Override - public void setBinding(String arg0, Value arg1) { - throw new UnsupportedOperationException(); - } - - @Override - public void setDataset(Dataset arg0) { - throw new UnsupportedOperationException(); - } - - @Override - public void setIncludeInferred(boolean arg0) { - throw new UnsupportedOperationException(); - } - - @Override - public void evaluate(TupleQueryResultHandler arg0) - throws QueryEvaluationException { - throw new UnsupportedOperationException(); - } - - }; + /* + * Add to the list of running queries. Will be later removed + * via the IPreparedQueryListener callback. + */ + addQueryId(q.getQueryId()); + + return new RemoteTupleQuery(q); } catch (Exception ex) { @@ -982,58 +889,7 @@ /* * Only execute() is currently supported. */ - return new Update() { - - @Override - public void execute() throws UpdateExecutionException { - try { - update.evaluate(); - } catch (Exception ex) { - throw new UpdateExecutionException(ex); - } - } - - @Override - public void clearBindings() { - throw new UnsupportedOperationException(); - } - - @Override - public BindingSet getBindings() { - throw new UnsupportedOperationException(); - } - - @Override - public Dataset getDataset() { - throw new UnsupportedOperationException(); - } - - @Override - public boolean getIncludeInferred() { - throw new UnsupportedOperationException(); - } - - @Override - public void removeBinding(String arg0) { - throw new UnsupportedOperationException(); - } - - @Override - public void setBinding(String arg0, Value arg1) { - throw new UnsupportedOperationException(); - } - - @Override - public void setDataset(Dataset arg0) { - throw new UnsupportedOperationException(); - } - - @Override - public void setIncludeInferred(boolean arg0) { - throw new UnsupportedOperationException(); - } - - }; + return new RemoteUpdate(update); } catch (Exception ex) { @@ -1096,5 +952,351 @@ public ValueFactory getValueFactory() { throw new UnsupportedOperationException(); } + + public class RemoteTupleQuery implements TupleQuery { + + private final IPreparedTupleQuery q; + + public RemoteTupleQuery(final IPreparedTupleQuery q) { + this.q = q; + } + + public UUID getQueryId() { + return q.getQueryId(); + } + + @Override + public TupleQueryResult evaluate() throws QueryEvaluationException { + try { + return q.evaluate(BigdataSailRemoteRepositoryConnection.this); + } catch (Exception ex) { + throw new QueryEvaluationException(ex); + } + } + /** + * @see http://trac.bigdata.com/ticket/914 (Set timeout on + * remote query) + */ + @Override + public int getMaxQueryTime() { + + final long millis = q.getMaxQueryMillis(); + + if (millis == -1) { + // Note: -1L is returned if the http header is not specified. + return -1; + + } + + return (int) TimeUnit.MILLISECONDS.toSeconds(millis); + + } + + /** + * @see http://trac.bigdata.com/ticket/914 (Set timeout on + * remote query) + */ + @Override + public void setMaxQueryTime(final int seconds) { + q.setMaxQueryMillis(TimeUnit.SECONDS.toMillis(seconds)); + } + + @Override + public void clearBindings() { + throw new UnsupportedOperationException(); + } + + @Override + public BindingSet getBindings() { + throw new UnsupportedOperationException(); + } + + @Override + public Dataset getDataset() { + throw new UnsupportedOperationException(); + } + + @Override + public boolean getIncludeInferred() { + throw new UnsupportedOperationException(); + } + + @Override + public void removeBinding(String arg0) { + throw new UnsupportedOperationException(); + } + + @Override + public void setBinding(String arg0, Value arg1) { + throw new UnsupportedOperationException(); + } + + @Override + public void setDataset(Dataset arg0) { + throw new UnsupportedOperationException(); + } + + @Override + public void setIncludeInferred(boolean arg0) { + throw new UnsupportedOperationException(); + } + + @Override + public void evaluate(TupleQueryResultHandler arg0) + throws QueryEvaluationException { + throw new UnsupportedOperationException(); + } + + } + + public class RemoteGraphQuery implements GraphQuery { + + private final IPreparedGraphQuery q; + + public RemoteGraphQuery(final IPreparedGraphQuery q) { + this.q = q; + } + + public UUID getQueryId() { + return q.getQueryId(); + } + + @Override + public GraphQueryResult evaluate() throws QueryEvaluationException { + try { + return q.evaluate(BigdataSailRemoteRepositoryConnection.this); + } catch (Exception ex) { + throw new QueryEvaluationException(ex); + } + } + + /** + * @see http://trac.bigdata.com/ticket/914 (Set timeout on + * remote query) + */ + @Override + public int getMaxQueryTime() { + + final long millis = q.getMaxQueryMillis(); + + if (millis == -1) { + // Note: -1L is returned if the http header is not specified. + return -1; + + } + + return (int) TimeUnit.MILLISECONDS.toSeconds(millis); + + } + + /** + * @see http://trac.bigdata.com/ticket/914 (Set timeout on + * remote query) + */ + @Override + public void setMaxQueryTime(final int seconds) { + q.setMaxQueryMillis(TimeUnit.SECONDS.toMillis(seconds)); + } + + @Override + public void clearBindings() { + throw new UnsupportedOperationException(); + } + + @Override + public BindingSet getBindings() { + throw new UnsupportedOperationException(); + } + + @Override + public Dataset getDataset() { + throw new UnsupportedOperationException(); + } + + @Override + public boolean getIncludeInferred() { + throw new UnsupportedOperationException(); + } + + @Override + public void removeBinding(String arg0) { + throw new UnsupportedOperationException(); + } + + @Override + public void setBinding(String arg0, Value arg1) { + throw new UnsupportedOperationException(); + } + + @Override + public void setDataset(Dataset arg0) { + throw new UnsupportedOperationException(); + } + + @Override + public void setIncludeInferred(boolean arg0) { + throw new UnsupportedOperationException(); + } + + @Override + public void evaluate(RDFHandler arg0) + throws QueryEvaluationException, RDFHandlerException { + throw new UnsupportedOperationException(); + } + + } + + public class RemoteBooleanQuery implements BooleanQuery { + + private final IPreparedBooleanQuery q; + + public RemoteBooleanQuery(final IPreparedBooleanQuery q) { + this.q = q; + } + + public UUID getQueryId() { + return q.getQueryId(); + } + + @Override + public boolean evaluate() throws QueryEvaluationException { + try { + return q.evaluate(BigdataSailRemoteRepositoryConnection.this); + } catch (Exception ex) { + throw new QueryEvaluationException(ex); + } + } + + /** + * @see http://trac.bigdata.com/ticket/914 (Set timeout on remote query) + */ + @Override + public int getMaxQueryTime() { + + final long millis = q.getMaxQueryMillis(); + + if (millis == -1) { + // Note: -1L is returned if the http header is not specified. + return -1; + + } + + return (int) TimeUnit.MILLISECONDS.toSeconds(millis); + + } + + /** + * @see http://trac.bigdata.com/ticket/914 (Set timeout on remote query) + */ + @Override + public void setMaxQueryTime(final int seconds) { + q.setMaxQueryMillis(TimeUnit.SECONDS.toMillis(seconds)); + } + + @Override + public void clearBindings() { + throw new UnsupportedOperationException(); + } + + @Override + public BindingSet getBindings() { + throw new UnsupportedOperationException(); + } + + @Override + public Dataset getDataset() { + throw new UnsupportedOperationException(); + } + + @Override + public boolean getIncludeInferred() { + throw new UnsupportedOperationException(); + } + + @Override + public void removeBinding(String arg0) { + throw new UnsupportedOperationException(); + } + + @Override + public void setBinding(String arg0, Value arg1) { + throw new UnsupportedOperationException(); + } + + @Override + public void setDataset(Dataset arg0) { + throw new UnsupportedOperationException(); + } + + @Override + public void setIncludeInferred(boolean arg0) { + throw new UnsupportedOperationException(); + } + + } + + public class RemoteUpdate implements Update { + + private final IPreparedSparqlUpdate q; + + public RemoteUpdate(final IPreparedSparqlUpdate q) { + this.q = q; + } + + public UUID getQueryId() { + return q.getQueryId(); + } + + @Override + public void execute() throws UpdateExecutionException { + try { + q.evaluate(BigdataSailRemoteRepositoryConnection.this); + } catch (Exception ex) { + throw new UpdateExecutionException(ex); + } + } + + @Override + public void clearBindings() { + throw new UnsupportedOperationException(); + } + + @Override + public BindingSet getBindings() { + throw new UnsupportedOperationException(); + } + + @Override + public Dataset getDataset() { + throw new UnsupportedOperationException(); + } + + @Override + public boolean getIncludeInferred() { + throw new UnsupportedOperationException(); + } + + @Override + public void removeBinding(String arg0) { + throw new UnsupportedOperationException(); + } + + @Override + public void setBinding(String arg0, Value arg1) { + throw new UnsupportedOperationException(); + } + + @Override + public void setDataset(Dataset arg0) { + throw new UnsupportedOperationException(); + } + + @Override + public void setIncludeInferred(boolean arg0) { + throw new UnsupportedOperationException(); + } + + } + } Modified: branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/client/IPreparedBooleanQuery.java =================================================================== --- branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/client/IPreparedBooleanQuery.java 2014-09-26 13:03:10 UTC (rev 8664) +++ branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/client/IPreparedBooleanQuery.java 2014-09-26 14:26:04 UTC (rev 8665) @@ -35,6 +35,25 @@ */ public interface IPreparedBooleanQuery extends IPreparedQuery { + /** + * Evaluate the boolean query. + * + * @param listener + * The query listener. + * @return The result. + * + * @throws Exception + */ boolean evaluate() throws Exception; + /** + * Evaluate the boolean query, notify the specified listener when complete. + * + * @param listener + * The query listener. + * @return The result. + * + * @throws Exception + */ + boolean evaluate(IPreparedQueryListener listener) throws Exception; } \ No newline at end of file Modified: branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/client/IPreparedGraphQuery.java =================================================================== --- branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/client/IPreparedGraphQuery.java 2014-09-26 13:03:10 UTC (rev 8664) +++ branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/client/IPreparedGraphQuery.java 2014-09-26 14:26:04 UTC (rev 8665) @@ -37,6 +37,24 @@ */ public interface IPreparedGraphQuery extends IPreparedQuery { + /** + * Evaluate the graph query. + * + * @return The result. + * + * @throws Exception + */ GraphQueryResult evaluate() throws Exception; + /** + * Evaluate the graph query, notify the specified listener when complete. + * + * @param listener + * The query listener. + * @return The result. + * + * @throws Exception + */ + GraphQueryResult evaluate(IPreparedQueryListener listener) + throws Exception; } \ No newline at end of file Added: branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/client/IPreparedQueryListener.java =================================================================== --- branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/client/IPreparedQueryListener.java (rev 0) +++ branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/client/IPreparedQueryListener.java 2014-09-26 14:26:04 UTC (rev 8665) @@ -0,0 +1,45 @@ +/** + +Copyright (C) SYSTAP, LLC 2006-Infinity. All rights reserved. + +Contact: + SYSTAP, LLC + 4501 Tower Road + Greensboro, NC 27410 + lic...@bi... + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; version 2 of the License. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +package com.bigdata.rdf.sail.webapp.client; + +import java.util.UUID; + +/** + * A listener for IPreparedQuery evaluate objects. + */ +public interface IPreparedQueryListener { + + /** + * Callback method from the query evaluation object (GraphQueryResult, + * TupleQueryResult, BooleanQueryResult) notifying that the result object + * has been closed and the query has either completed or been + * cancelled. + * + * @param uuid + * The query id. + */ + void closed(final UUID queryId); + +} Property changes on: branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/client/IPreparedQueryListener.java ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Modified: branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/client/IPreparedSparqlUpdate.java =================================================================== --- branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/client/IPreparedSparqlUpdate.java 2014-09-26 13:03:10 UTC (rev 8664) +++ branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/client/IPreparedSparqlUpdate.java 2014-09-26 14:26:04 UTC (rev 8665) @@ -37,6 +37,16 @@ void evaluate() throws Exception; + /** + * Evaluate and notify the specified listener when complete. + * + * @param listener + * The query listener. + * + * @throws Exception + */ + void evaluate(IPreparedQueryListener listener) throws Exception; + UUID getQueryId(); } \ No newline at end of file Modified: branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/client/IPreparedTupleQuery.java =================================================================== --- branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/client/IPreparedTupleQuery.java 2014-09-26 13:03:10 UTC (rev 8664) +++ branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/client/IPreparedTupleQuery.java 2014-09-26 14:26:04 UTC (rev 8665) @@ -46,4 +46,16 @@ */ public TupleQueryResult evaluate() throws Exception; + /** + * Evaluate the tuple query, notify the specified listener when complete. + * + * @param listener + * The query listener. + * @return The result. + * + * @throws Exception + */ + public TupleQueryResult evaluate(IPreparedQueryListener listener) + throws Exception; + } \ No newline at end of file Modified: branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/client/RemoteRepository.java =================================================================== --- branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/client/RemoteRepository.java 2014-09-26 13:03:10 UTC (rev 8664) +++ branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/client/RemoteRepository.java 2014-09-26 14:26:04 UTC (rev 8665) @@ -521,7 +521,7 @@ // checkResponseCode(response = doConnect(opts)); - return graphResults(opts, null); + return graphResults(opts, null, null); } @@ -600,7 +600,7 @@ * * TODO includeInferred is currently ignored. */ - public GraphQueryResult getStatements(final Resource subj, final URI pred, + public IPreparedGraphQuery getStatements2(final Resource subj, final URI pred, final Value obj, final boolean includeInferred, final Resource... contexts) throws Exception { @@ -673,7 +673,28 @@ final IPreparedGraphQuery query = prepareGraphQuery(queryStr); - return query.evaluate(); + return query; + + } + + /** + * Return all matching statements. + * + * @param subj + * @param pred + * @param obj + * @param includeInferred + * @param contexts + * @return + * @throws Exception + * + * TODO includeInferred is currently ignored. + */ + public GraphQueryResult getStatements(final Resource subj, final URI pred, + final Value obj, final boolean includeInferred, + final Resource... contexts) throws Exception { + + return getStatements2(subj, pred, obj, includeInferred, contexts).evaluate(); } @@ -1238,9 +1259,17 @@ @Override public TupleQueryResult evaluate() throws Exception { + return evaluate(null); + + } + + @Override + public TupleQueryResult evaluate(final IPreparedQueryListener listener) + throws Exception { + setupConnectOptions(); - return tupleResults(opts, getQueryId()); + return tupleResults(opts, getQueryId(), listener); } @@ -1268,9 +1297,17 @@ @Override public GraphQueryResult evaluate() throws Exception { + return evaluate(null); + + } + + @Override + public GraphQueryResult evaluate(final IPreparedQueryListener listener) + throws Exception { + setupConnectOptions(); - return graphResults(opts, getQueryId()); + return graphResults(opts, getQueryId(), listener); } @@ -1300,9 +1337,17 @@ @Override public boolean evaluate() throws Exception { + return evaluate(null); + + } + + @Override + public boolean evaluate(final IPreparedQueryListener listener) + throws Exception { + setupConnectOptions(); - return booleanResults(opts, getQueryId()); + return booleanResults(opts, getQueryId(), listener); // HttpResponse response = null; // try { @@ -1344,7 +1389,15 @@ @Override public void evaluate() throws Exception { + + evaluate(null); + + } + @Override + public void evaluate(final IPreparedQueryListener listener) + throws Exception { + HttpResponse response = null; try { @@ -1367,6 +1420,10 @@ } + if (listener != null) { + listener.closed(getQueryId()); + } + } } @@ -1797,14 +1854,18 @@ * * @param response * The connection from which to read the results. + * @param listener + * The listener to notify when the query result has been + * closed (optional). * * @return The results. * * @throws Exception * If anything goes wrong. */ - public TupleQueryResult tupleResults(final ConnectOptions opts, final UUID queryId) - throws Exception { + public TupleQueryResult tupleResults(final ConnectOptions opts, + final UUID queryId, final IPreparedQueryListener listener) + throws Exception { HttpResponse response = null; HttpEntity entity = null; @@ -1893,6 +1954,13 @@ } + /* + * Notify the listener. + */ + if (listener != null) { + listener.closed(queryId); + } + } }; @@ -1935,6 +2003,9 @@ * * @param response * The connection from which to read the results. + * @param listener + * The listener to notify when the query result has been + * closed (optional). * * @return The graph * @@ -1942,7 +2013,8 @@ * If anything goes wrong. */ public GraphQueryResult graphResults(final ConnectOptions opts, - final UUID queryId) throws Exception { + final UUID queryId, final IPreparedQueryListener listener) + throws Exception { HttpResponse response = null; HttpEntity entity = null; @@ -2047,6 +2119,10 @@ } + if (listener != null) { + listener.closed(queryId); + } + } }; @@ -2099,7 +2175,9 @@ * If anything goes wrong, including if the result set does not * encode a single boolean value. */ - protected boolean booleanResults(final ConnectOptions opts, final UUID queryId) throws Exception { + protected boolean booleanResults(final ConnectOptions opts, + final UUID queryId, final IPreparedQueryListener listener) + throws Exception { HttpResponse response = null; HttpEntity entity = null; @@ -2150,6 +2228,10 @@ cancel(queryId); } catch (Exception ex) {log.warn(ex); } } + + if (listener != null) { + listener.closed(queryId); + } } Modified: branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/client/RemoteRepositoryManager.java =================================================================== --- branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/client/RemoteRepositoryManager.java 2014-09-26 13:03:10 UTC (rev 8664) +++ branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/client/RemoteRepositoryManager.java 2014-09-26 14:26:04 UTC (rev 8665) @@ -214,7 +214,7 @@ opts.setAcceptHeader(ConnectOptions.DEFAULT_GRAPH_ACCEPT_HEADER); - return graphResults(opts, null/* queryId */); + return graphResults(opts, null/* queryId */, null); // try { // // check response in try. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |