From: <tho...@us...> - 2011-04-13 20:33:19
|
Revision: 4397 http://bigdata.svn.sourceforge.net/bigdata/?rev=4397&view=rev Author: thompsonbry Date: 2011-04-13 20:33:10 +0000 (Wed, 13 Apr 2011) Log Message: ----------- This commit includes incremental progress toward support for full read/write tx for the RWStore and a further refactoring of the NanoSparqlServer. The read/write tx support is not yet finished. Martyn is looking into a bug with the free bits logic. I've refactored the NanoSparqlServer initialization a bit. You can now initialize the server either using NanoSparqlServer or a web.xml file. A sample web.xml file is included in the same package as the NanoSparqlServer and you can run that web.xml file using the WebAppUnassembled class in that package. The key bit to making this work was to isolate the life cycle logic within a ServletContextListener. When using the web.xml file, everything is explicitly configured in that web.xml file. When using the NanoSparqlServer, the same initialization parameters are explicitly set and the various listeners and servlets are initialized by hand (in the code). I had to add several more of the jetty dependencies in order to make this work, including: - jetty-servlet - jetty-security - jetty-webapp (only when using web.xml) - jetty-xml (only when using web.xml) build.xml has been updated so CI will find those dependencies. So has .classpath. I've also refactored the performance counters stuff so that it can be served up by jetty and it is now available at /counters when using NanoSparqlServer. There is more work to be done in layering in the performance counters properly, but this is a nice start. The "DELETE with BODY using POST" method of the REST API was not being invoked properly by the test suite and was not being delegated properly by the RESTServlet. Both of those issues have been fixed. Modified Paths: -------------- branches/QUADS_QUERY_BRANCH/.classpath branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/counters/httpd/CounterSetHTTPD.java branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/counters/query/CounterSetQuery.java branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/counters/query/URLQueryModel.java branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/counters/render/RendererFactory.java branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/journal/AbstractJournal.java branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/journal/AbstractTask.java branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/journal/RWStrategy.java branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/rawstore/AbstractRawStore.java branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/util/httpd/NanoHTTPD.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/bench/NanoSparqlServer.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/BigdataServlet.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/DeleteServlet.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/NanoSparqlServer.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/QueryServlet.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/RESTServlet.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/StatusServlet.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/UpdateServlet.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/XMLBuilder.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/bench/TestNanoSparqlServer.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/bench/TestNanoSparqlServer_StartStop.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/webapp/TestAll.java branches/QUADS_QUERY_BRANCH/build.xml Added Paths: ----------- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/BigdataBaseContext.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/BigdataRDFContext.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/BigdataRDFServlet.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/BigdataRDFServletContextListener.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/ConfigParams.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/CountersServlet.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/SparqlEndpointConfig.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/WebAppUnassembled.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/web.xml branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/webapp/TestNanoSparqlServer.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/webapp/TestXMLBuilder.java Removed Paths: ------------- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/BigdataContext.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/JettySparqlServer.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/webapp/TestJettySparqlServer_StartStop.java Modified: branches/QUADS_QUERY_BRANCH/.classpath =================================================================== --- branches/QUADS_QUERY_BRANCH/.classpath 2011-04-13 20:21:27 UTC (rev 4396) +++ branches/QUADS_QUERY_BRANCH/.classpath 2011-04-13 20:33:10 UTC (rev 4397) @@ -1,71 +1,75 @@ -<?xml version="1.0" encoding="UTF-8"?> -<classpath> - <classpathentry kind="src" path="bigdata-rdf/src/java"/> - <classpathentry kind="src" path="bigdata-rdf/src/samples"/> - <classpathentry kind="src" path="dsi-utils/src/java"/> - <classpathentry kind="src" path="bigdata/src/resources/logging"/> - <classpathentry kind="src" path="bigdata-sails/src/samples"/> - <classpathentry kind="src" path="bigdata-jini/src/test"/> - <classpathentry kind="src" path="bigdata-sails/src/java"/> - <classpathentry kind="src" path="bigdata/src/java"/> - <classpathentry kind="src" path="bigdata-rdf/src/test"/> - <classpathentry kind="src" path="bigdata/src/test"/> - <classpathentry kind="src" path="bigdata-sails/src/test"/> - <classpathentry kind="src" path="bigdata-jini/src/java"/> - <classpathentry kind="src" path="contrib/src/problems"/> - <classpathentry kind="src" path="bigdata/src/samples"/> - <classpathentry kind="src" path="dsi-utils/src/test"/> - <classpathentry kind="src" path="ctc-striterators/src/java"/> - <classpathentry kind="src" path="ctc-striterators/src/test"/> - <classpathentry kind="src" path="bigdata-perf/bsbm/src/test"/> - <classpathentry kind="lib" path="bigdata-jini/lib/apache/zookeeper-3.2.1.jar"/> - <classpathentry exported="true" kind="lib" path="bigdata/lib/dsi-utils-1.0.6-020610.jar"/> - <classpathentry exported="true" kind="lib" path="bigdata/lib/lgpl-utils-1.0.6-020610.jar"/> - <classpathentry exported="true" kind="lib" path="bigdata-rdf/lib/nxparser-6-22-2010.jar"/> - <classpathentry kind="lib" path="bigdata/lib/tuprolog/tuprolog-v2.1.1.jar"/> - <classpathentry exported="true" kind="lib" path="bigdata/lib/jetty/jetty-continuation-7.2.2.v20101205.jar"/> - <classpathentry exported="true" kind="lib" path="bigdata/lib/jetty/jetty-http-7.2.2.v20101205.jar"/> - <classpathentry exported="true" kind="lib" path="bigdata/lib/jetty/jetty-io-7.2.2.v20101205.jar"/> - <classpathentry exported="true" kind="lib" path="bigdata/lib/jetty/jetty-server-7.2.2.v20101205.jar"/> - <classpathentry exported="true" kind="lib" path="bigdata/lib/jetty/jetty-util-7.2.2.v20101205.jar"/> - <classpathentry exported="true" kind="lib" path="bigdata/lib/jetty/servlet-api-2.5.jar"/> - <classpathentry kind="src" path="lgpl-utils/src/java"/> - <classpathentry kind="src" path="lgpl-utils/src/test"/> - <classpathentry exported="true" kind="lib" path="bigdata/lib/icu/icu4j-3_6.jar"/> - <classpathentry exported="true" kind="lib" path="bigdata/lib/unimi/colt-1.2.0.jar"/> - <classpathentry exported="true" kind="lib" path="bigdata/lib/cweb-commons-1.1-b2-dev.jar"/> - <classpathentry exported="true" kind="lib" path="bigdata/lib/cweb-extser-0.1-b2-dev.jar"/> - <classpathentry exported="true" kind="lib" path="bigdata/lib/cweb-junit-ext-1.1-b3-dev.jar" sourcepath="/junit-ext/src"/> - <classpathentry exported="true" kind="lib" path="bigdata/lib/junit-3.8.1.jar"/> - <classpathentry exported="true" kind="lib" path="bigdata/lib/apache/log4j-1.2.15.jar"/> - <classpathentry exported="true" kind="lib" path="bigdata/lib/icu/icu4jni.jar"/> - <classpathentry exported="true" kind="lib" path="bigdata-rdf/lib/slf4j-api-1.4.3.jar"/> - <classpathentry exported="true" kind="lib" path="bigdata-rdf/lib/slf4j-log4j12-1.4.3.jar"/> - <classpathentry exported="true" kind="lib" path="bigdata-rdf/lib/iris-0.58.jar"/> - <classpathentry exported="true" kind="lib" path="bigdata-rdf/lib/jgrapht-jdk1.5-0.7.1.jar"/> - <classpathentry exported="true" kind="lib" path="bigdata-jini/lib/jini/lib/browser.jar"/> - <classpathentry exported="true" kind="lib" path="bigdata-jini/lib/jini/lib/classserver.jar"/> - <classpathentry exported="true" kind="lib" path="bigdata-jini/lib/jini/lib/fiddler.jar"/> - <classpathentry exported="true" kind="lib" path="bigdata-jini/lib/jini/lib/jini-core.jar"/> - <classpathentry exported="true" kind="lib" path="bigdata-jini/lib/jini/lib/jini-ext.jar"/> - <classpathentry exported="true" kind="lib" path="bigdata-jini/lib/jini/lib/jsk-lib.jar"/> - <classpathentry exported="true" kind="lib" path="bigdata-jini/lib/jini/lib/jsk-platform.jar"/> - <classpathentry exported="true" kind="lib" path="bigdata-jini/lib/jini/lib/jsk-resources.jar"/> - <classpathentry exported="true" kind="lib" path="bigdata-jini/lib/jini/lib/mahalo.jar"/> - <classpathentry exported="true" kind="lib" path="bigdata-jini/lib/jini/lib/mercury.jar"/> - <classpathentry exported="true" kind="lib" path="bigdata-jini/lib/jini/lib/norm.jar"/> - <classpathentry exported="true" kind="lib" path="bigdata-jini/lib/jini/lib/outrigger.jar"/> - <classpathentry exported="true" kind="lib" path="bigdata-jini/lib/jini/lib/reggie.jar"/> - <classpathentry exported="true" kind="lib" path="bigdata-jini/lib/jini/lib/start.jar"/> - <classpathentry exported="true" kind="lib" path="bigdata-jini/lib/jini/lib/sun-util.jar"/> - <classpathentry exported="true" kind="lib" path="bigdata-jini/lib/jini/lib/tools.jar"/> - <classpathentry exported="true" kind="lib" path="bigdata/lib/unimi/fastutil-5.1.5.jar"/> - <classpathentry exported="true" kind="lib" path="bigdata/lib/lucene/lucene-analyzers-3.0.0.jar"/> - <classpathentry exported="true" kind="lib" path="bigdata/lib/lucene/lucene-core-3.0.0.jar"/> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> - <classpathentry exported="true" kind="lib" path="bigdata-rdf/lib/openrdf-sesame-2.3.0-onejar.jar"/> - <classpathentry kind="lib" path="bigdata-sails/lib/sesame-sparql-testsuite-2.3.0.jar"/> - <classpathentry kind="lib" path="bigdata-sails/lib/sesame-store-testsuite-2.3.0.jar"/> - <classpathentry exported="true" kind="lib" path="bigdata/lib/high-scale-lib-v1.1.2.jar"/> - <classpathentry kind="output" path="bin"/> -</classpath> +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="src" path="bigdata-rdf/src/java"/> + <classpathentry kind="src" path="bigdata-rdf/src/samples"/> + <classpathentry kind="src" path="dsi-utils/src/java"/> + <classpathentry kind="src" path="bigdata/src/resources/logging"/> + <classpathentry kind="src" path="bigdata-sails/src/samples"/> + <classpathentry kind="src" path="bigdata-jini/src/test"/> + <classpathentry kind="src" path="bigdata-sails/src/java"/> + <classpathentry kind="src" path="bigdata/src/java"/> + <classpathentry kind="src" path="bigdata-rdf/src/test"/> + <classpathentry kind="src" path="bigdata/src/test"/> + <classpathentry kind="src" path="bigdata-sails/src/test"/> + <classpathentry kind="src" path="bigdata-jini/src/java"/> + <classpathentry kind="src" path="contrib/src/problems"/> + <classpathentry kind="src" path="bigdata/src/samples"/> + <classpathentry kind="src" path="dsi-utils/src/test"/> + <classpathentry kind="src" path="ctc-striterators/src/java"/> + <classpathentry kind="src" path="ctc-striterators/src/test"/> + <classpathentry kind="src" path="bigdata-perf/bsbm/src/test"/> + <classpathentry kind="lib" path="bigdata-jini/lib/apache/zookeeper-3.2.1.jar"/> + <classpathentry exported="true" kind="lib" path="bigdata/lib/dsi-utils-1.0.6-020610.jar"/> + <classpathentry exported="true" kind="lib" path="bigdata/lib/lgpl-utils-1.0.6-020610.jar"/> + <classpathentry exported="true" kind="lib" path="bigdata-rdf/lib/nxparser-6-22-2010.jar"/> + <classpathentry kind="lib" path="bigdata/lib/tuprolog/tuprolog-v2.1.1.jar"/> + <classpathentry exported="true" kind="lib" path="bigdata/lib/jetty/jetty-continuation-7.2.2.v20101205.jar"/> + <classpathentry exported="true" kind="lib" path="bigdata/lib/jetty/jetty-http-7.2.2.v20101205.jar"/> + <classpathentry exported="true" kind="lib" path="bigdata/lib/jetty/jetty-io-7.2.2.v20101205.jar"/> + <classpathentry exported="true" kind="lib" path="bigdata/lib/jetty/jetty-server-7.2.2.v20101205.jar"/> + <classpathentry exported="true" kind="lib" path="bigdata/lib/jetty/jetty-util-7.2.2.v20101205.jar"/> + <classpathentry exported="true" kind="lib" path="bigdata/lib/jetty/servlet-api-2.5.jar"/> + <classpathentry kind="lib" path="bigdata/lib/jetty/jetty-servlet-7.2.2.v20101205.jar"/> + <classpathentry kind="lib" path="bigdata/lib/jetty/jetty-security-7.2.2.v20101205.jar"/> + <classpathentry kind="lib" path="bigdata/lib/jetty/jetty-webapp-7.2.2.v20101205.jar"/> + <classpathentry kind="lib" path="bigdata/lib/jetty/jetty-xml-7.2.2.v20101205.jar"/> + <classpathentry kind="src" path="lgpl-utils/src/java"/> + <classpathentry kind="src" path="lgpl-utils/src/test"/> + <classpathentry exported="true" kind="lib" path="bigdata/lib/icu/icu4j-3_6.jar"/> + <classpathentry exported="true" kind="lib" path="bigdata/lib/unimi/colt-1.2.0.jar"/> + <classpathentry exported="true" kind="lib" path="bigdata/lib/cweb-commons-1.1-b2-dev.jar"/> + <classpathentry exported="true" kind="lib" path="bigdata/lib/cweb-extser-0.1-b2-dev.jar"/> + <classpathentry exported="true" kind="lib" path="bigdata/lib/cweb-junit-ext-1.1-b3-dev.jar" sourcepath="/junit-ext/src"/> + <classpathentry exported="true" kind="lib" path="bigdata/lib/junit-3.8.1.jar"/> + <classpathentry exported="true" kind="lib" path="bigdata/lib/apache/log4j-1.2.15.jar"/> + <classpathentry exported="true" kind="lib" path="bigdata/lib/icu/icu4jni.jar"/> + <classpathentry exported="true" kind="lib" path="bigdata-rdf/lib/slf4j-api-1.4.3.jar"/> + <classpathentry exported="true" kind="lib" path="bigdata-rdf/lib/slf4j-log4j12-1.4.3.jar"/> + <classpathentry exported="true" kind="lib" path="bigdata-rdf/lib/iris-0.58.jar"/> + <classpathentry exported="true" kind="lib" path="bigdata-rdf/lib/jgrapht-jdk1.5-0.7.1.jar"/> + <classpathentry exported="true" kind="lib" path="bigdata-jini/lib/jini/lib/browser.jar"/> + <classpathentry exported="true" kind="lib" path="bigdata-jini/lib/jini/lib/classserver.jar"/> + <classpathentry exported="true" kind="lib" path="bigdata-jini/lib/jini/lib/fiddler.jar"/> + <classpathentry exported="true" kind="lib" path="bigdata-jini/lib/jini/lib/jini-core.jar"/> + <classpathentry exported="true" kind="lib" path="bigdata-jini/lib/jini/lib/jini-ext.jar"/> + <classpathentry exported="true" kind="lib" path="bigdata-jini/lib/jini/lib/jsk-lib.jar"/> + <classpathentry exported="true" kind="lib" path="bigdata-jini/lib/jini/lib/jsk-platform.jar"/> + <classpathentry exported="true" kind="lib" path="bigdata-jini/lib/jini/lib/jsk-resources.jar"/> + <classpathentry exported="true" kind="lib" path="bigdata-jini/lib/jini/lib/mahalo.jar"/> + <classpathentry exported="true" kind="lib" path="bigdata-jini/lib/jini/lib/mercury.jar"/> + <classpathentry exported="true" kind="lib" path="bigdata-jini/lib/jini/lib/norm.jar"/> + <classpathentry exported="true" kind="lib" path="bigdata-jini/lib/jini/lib/outrigger.jar"/> + <classpathentry exported="true" kind="lib" path="bigdata-jini/lib/jini/lib/reggie.jar"/> + <classpathentry exported="true" kind="lib" path="bigdata-jini/lib/jini/lib/start.jar"/> + <classpathentry exported="true" kind="lib" path="bigdata-jini/lib/jini/lib/sun-util.jar"/> + <classpathentry exported="true" kind="lib" path="bigdata-jini/lib/jini/lib/tools.jar"/> + <classpathentry exported="true" kind="lib" path="bigdata/lib/unimi/fastutil-5.1.5.jar"/> + <classpathentry exported="true" kind="lib" path="bigdata/lib/lucene/lucene-analyzers-3.0.0.jar"/> + <classpathentry exported="true" kind="lib" path="bigdata/lib/lucene/lucene-core-3.0.0.jar"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> + <classpathentry exported="true" kind="lib" path="bigdata-rdf/lib/openrdf-sesame-2.3.0-onejar.jar"/> + <classpathentry kind="lib" path="bigdata-sails/lib/sesame-sparql-testsuite-2.3.0.jar"/> + <classpathentry kind="lib" path="bigdata-sails/lib/sesame-store-testsuite-2.3.0.jar"/> + <classpathentry exported="true" kind="lib" path="bigdata/lib/high-scale-lib-v1.1.2.jar"/> + <classpathentry kind="output" path="bin"/> +</classpath> Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/counters/httpd/CounterSetHTTPD.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/counters/httpd/CounterSetHTTPD.java 2011-04-13 20:21:27 UTC (rev 4396) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/counters/httpd/CounterSetHTTPD.java 2011-04-13 20:33:10 UTC (rev 4397) @@ -1,3 +1,26 @@ +/** + +Copyright (C) SYSTAP, LLC 2006-2011. 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.counters.httpd; import java.io.ByteArrayInputStream; @@ -241,7 +264,7 @@ { // build model of the controller state. - final URLQueryModel model = new URLQueryModel(getService(), + final URLQueryModel model = URLQueryModel.getInstance(getService(), req.uri, req.params, req.headers); renderer = RendererFactory.get(model, counterSelector, mimeType); Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/counters/query/CounterSetQuery.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/counters/query/CounterSetQuery.java 2011-04-13 20:21:27 UTC (rev 4396) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/counters/query/CounterSetQuery.java 2011-04-13 20:33:10 UTC (rev 4397) @@ -114,38 +114,9 @@ */ public class CounterSetQuery { - static protected final Logger log = Logger.getLogger(CounterSetQuery.class); + static private final Logger log = Logger.getLogger(CounterSetQuery.class); /** - * Create a {@link URLQueryModel} from a URL. - * - * @param url - * The URL. - * - * @return The {@link URLQueryModel} - * - * @throws UnsupportedEncodingException - */ - static private URLQueryModel newQueryModel(final URL url) - throws UnsupportedEncodingException { - - // Extract the URL query parameters. - final LinkedHashMap<String, Vector<String>> params = NanoHTTPD - .decodeParams(url.getQuery(), - new LinkedHashMap<String, Vector<String>>()); - - // add any relevant headers - final Map<String, String> headers = new TreeMap<String, String>( - new CaseInsensitiveStringComparator()); - - headers.put("host", url.getHost() + ":" + url.getPort()); - - return new URLQueryModel(null/* service */, url.toString(), params, - headers); - - } - - /** * Reads a list of {@link URL}s from a file. Blank lines and comment lines * are ignored. * @@ -477,7 +448,7 @@ for (URL url : urls) { - queries.add(newQueryModel(url)); + queries.add(URLQueryModel.getInstance(url)); } Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/counters/query/URLQueryModel.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/counters/query/URLQueryModel.java 2011-04-13 20:21:27 UTC (rev 4396) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/counters/query/URLQueryModel.java 2011-04-13 20:33:10 UTC (rev 4397) @@ -31,6 +31,8 @@ import java.io.File; import java.io.UnsupportedEncodingException; import java.lang.reflect.Field; +import java.net.URL; +import java.net.URLDecoder; import java.net.URLEncoder; import java.text.DateFormat; import java.text.DecimalFormat; @@ -38,13 +40,19 @@ import java.text.NumberFormat; import java.util.Arrays; import java.util.Collection; +import java.util.Enumeration; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.Map; +import java.util.TreeMap; import java.util.Vector; import java.util.regex.Pattern; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.CognitiveWeb.util.CaseInsensitiveStringComparator; import org.apache.log4j.Logger; import com.bigdata.counters.History; @@ -54,6 +62,7 @@ import com.bigdata.service.Event; import com.bigdata.service.IEventReportingService; import com.bigdata.service.IService; +import com.bigdata.util.httpd.NanoHTTPD; /** * The model for a URL used to query an {@link ICounterSelector}. @@ -63,7 +72,7 @@ */ public class URLQueryModel { - protected static transient final Logger log = Logger.getLogger(URLQueryModel.class); + private static transient final Logger log = Logger.getLogger(URLQueryModel.class); /** * Name of the URL query parameter specifying the starting path for the page @@ -207,10 +216,15 @@ */ final public LinkedHashMap<String,Vector<String>> params; +// /** +// * The request headers. +// */ +// final public Map<String,String> headers; + /** - * The request headers. + * The reconstructed request URL. */ - final public Map<String,String> headers; + private final String requestURL; /** * The value of the {@link #PATH} query parameter. @@ -329,7 +343,9 @@ final public File file; /** - * @param fed + * Factory for {@link NanoHTTPD} integration. + * + * @param service * The service object IFF one was specified when * {@link CounterSetHTTPD} was started. * @param uri @@ -345,16 +361,134 @@ * @param header * Header entries, percent decoded */ - public URLQueryModel(final IService service, final String uri, + public static URLQueryModel getInstance(// + final IService service,// + final String uri,// + final LinkedHashMap<String, Vector<String>> params,// + final Map<String, String> headers// + ) { + + /* + * Re-create the request URL, including the protocol, host, port, and + * path but not any query parameters. + */ + + final StringBuilder sb = new StringBuilder(); + + // protocol (known from the container). + sb.append("http://"); + + // host and port + sb.append(headers.get("host")); + + // path (including the leading '/') + sb.append(uri); + + final String requestURL = sb.toString(); + + return new URLQueryModel(service, uri, params, requestURL); + + } + + /** + * Factory for Servlet API integration. + * + * @param service + * The service object IFF one was specified when + * {@link CounterSetHTTPD} was started. + * @param req + * The request. + * @param resp + * The response. + */ + public static URLQueryModel getInstance(// + final IService service, + final HttpServletRequest req, + final HttpServletResponse resp + ) throws UnsupportedEncodingException { + + final String uri = URLDecoder.decode(req.getRequestURI(), "UTF-8"); + + final LinkedHashMap<String, Vector<String>> params = new LinkedHashMap<String, Vector<String>>(); + + @SuppressWarnings("unchecked") + final Enumeration<String> enames = req.getParameterNames(); + + while (enames.hasMoreElements()) { + + final String name = enames.nextElement(); + + final String[] values = req.getParameterValues(name); + + final Vector<String> value = new Vector<String>(); + + for (String v : values) { + + value.add(v); + + } + + params.put(name, value); + + } + + final String requestURL = req.getRequestURL().toString(); + + return new URLQueryModel(service, uri, params, requestURL); + + } + + /** + * Create a {@link URLQueryModel} from a URL. This is useful when serving + * historical performance counter data out of a file. + * + * @param url + * The URL. + * + * @return The {@link URLQueryModel} + * + * @throws UnsupportedEncodingException + */ + static public URLQueryModel getInstance(final URL url) + throws UnsupportedEncodingException { + + // Extract the URL query parameters. + final LinkedHashMap<String, Vector<String>> params = NanoHTTPD + .decodeParams(url.getQuery(), + new LinkedHashMap<String, Vector<String>>()); + + // add any relevant headers + final Map<String, String> headers = new TreeMap<String, String>( + new CaseInsensitiveStringComparator()); + + headers.put("host", url.getHost() + ":" + url.getPort()); + + return URLQueryModel.getInstance(null/* service */, url.toString(), + params, headers); + + } + + private URLQueryModel(final IService service, final String uri, final LinkedHashMap<String, Vector<String>> params, - final Map<String, String> headers) { + final String requestURL) { + if (uri == null) + throw new IllegalArgumentException(); + + if (params == null) + throw new IllegalArgumentException(); + + if (requestURL == null) + throw new IllegalArgumentException(); + this.uri = uri; this.params = params; - this.headers = headers; +// this.headers = headers; + this.requestURL = requestURL; + this.path = getProperty(params, PATH, ICounterSet.pathSeparator); if (log.isInfoEnabled()) @@ -691,19 +825,8 @@ */ public StringBuilder getRequestURL() { - final StringBuilder sb = new StringBuilder(); + return new StringBuilder(requestURL); - // protocol (known from the container). - sb.append("http://"); - - // host and port - sb.append(headers.get("host")); - - // path (including the leading '/') - sb.append(uri); - - return sb; - } /** Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/counters/render/RendererFactory.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/counters/render/RendererFactory.java 2011-04-13 20:21:27 UTC (rev 4396) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/counters/render/RendererFactory.java 2011-04-13 20:33:10 UTC (rev 4397) @@ -28,11 +28,6 @@ package com.bigdata.counters.render; -import java.io.IOException; -import java.io.Writer; - -import com.bigdata.counters.CounterSet; -import com.bigdata.counters.ICounter; import com.bigdata.counters.query.ICounterSelector; import com.bigdata.counters.query.ReportEnum; import com.bigdata.counters.query.URLQueryModel; Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/journal/AbstractJournal.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/journal/AbstractJournal.java 2011-04-13 20:21:27 UTC (rev 4396) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/journal/AbstractJournal.java 2011-04-13 20:33:10 UTC (rev 4397) @@ -2708,6 +2708,18 @@ } + public void abortContext(final IAllocationContext context) { + + assertCanWrite(); + + if(_bufferStrategy instanceof RWStrategy) { + + ((RWStrategy) _bufferStrategy).abortContext(context); + + } + + } + final public long getRootAddr(final int index) { final ReadLock lock = _fieldReadWriteLock.readLock(); Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/journal/AbstractTask.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/journal/AbstractTask.java 2011-04-13 20:21:27 UTC (rev 4396) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/journal/AbstractTask.java 2011-04-13 20:33:10 UTC (rev 4397) @@ -604,24 +604,50 @@ synchronized (name2Addr) { /* - * FIXME In order to use shadow allocations, the unisolated - * index MUST be loaded using the IsolatedActionJournal. There - * are two places immediate below where it tests the cache and - * where it loads using the AbstractJournal, both of which are - * not appropriate as they fail to impose the - * IsolatedActionJournal with the consequence that the - * allocation contexts are not isolated. + * RWStore: There are two reasons why we must use shadow + * allocations for unisolated operations against the RWStore. + * + * (1) A rollback of an unisolated operation which caused + * mutations to the structure of an index will cause operations + * which access the index the rollback to fail since the backing + * allocations would have been immediately recycled by the + * RWStore (if running with a zero retention policy). + * + * (2) Allocations made during the unisolated operation should + * be immediately recycled if the operation is rolled back. This + * will not occur unless the unisolated operation makes those + * allocations against a shadow allocation context. Given that + * it does so, the rollback logic must also discard the shadow + * allocator in order for the shadowed allocations to be + * reclaimed immediately. + * + * In order to use shadow allocations, the unisolated index MUST + * be loaded using the IsolatedActionJournal. There are two + * places immediate below where it tests the cache and where it + * loads using the AbstractJournal, both of which are not + * appropriate as they fail to impose the IsolatedActionJournal + * with the consequence that the allocation contexts are not + * isolated. [Also, we do not want N2A to cache references to a + * B+Tree backed by a different shadow journal.] */ - // recover from unisolated index cache. - btree = name2Addr.getIndexCache(name); -// btree = null; // do not use the name2Addr cache. + if ((resourceManager.getLiveJournal().getBufferStrategy() instanceof RWStrategy)) { + /* + * Note: Do NOT use the name2Addr cache for the RWStore. + * Each unisolated index view MUST be backed by a shadow + * journal! + */ + btree = null; + } else { + // recover from unisolated index cache. + btree = name2Addr.getIndexCache(name); + } if (btree == null) { final IJournal tmp; - tmp = resourceManager.getLiveJournal(); -// tmp = getJournal();// wrap with the IsolatedActionJournal. +// tmp = resourceManager.getLiveJournal(); + tmp = getJournal();// wrap with the IsolatedActionJournal. // re-load btree from the store. btree = BTree.load(// @@ -636,8 +662,8 @@ // add to the unisolated index cache (must not exist). name2Addr.putIndexCache(name, btree, false/* replace */); - btree.setBTreeCounters((resourceManager) - .getIndexCounters(name)); + btree.setBTreeCounters(resourceManager + .getIndexCounters(name)); } @@ -686,7 +712,7 @@ /** * Given the name of an index and a {@link BTree}, obtain the view for all * source(s) described by the {@link BTree}s index partition metadata (if - * any),insert that view into the {@link #indexCache}, and return the view. + * any), inserts that view into the {@link #indexCache}, and return the view. * <p> * Note: This method is used both when registering a new index ({@link #registerIndex(String, BTree)}) * and when reading an index view from the source ({@link #getIndex(String)}). @@ -954,8 +980,6 @@ l.btree.writeCheckpoint(); - ((IsolatedActionJournal) getJournal()).detachContext(); - } if(INFO) { @@ -1054,11 +1078,18 @@ } + /* + * Do clean up. + */ + // clear n2a. n2a.clear(); // clear the commit list. commitList.clear(); + + // Detach the allocation context used by the operation. + ((IsolatedActionJournal) getJournal()).detachContext(); final long elapsed = System.nanoTime() - begin; @@ -1073,6 +1104,17 @@ } + /** + * Discard any allocations for writes on unisolated indices touched by the + * task for an {@link ITx#UNISOLATED} which fails, but while the task still + * has its locks. + */ + private void abortTask() { + + ((IsolatedActionJournal) getJournal()).abortContext(); + + } + /* * End isolation support for name2addr. */ @@ -1747,7 +1789,7 @@ * * @throws Exception * - * FIXME update javadoc to reflect the change in how the locks are acquired. + * @todo update javadoc to reflect the change in how the locks are acquired. */ private T doUnisolatedReadWriteTask() throws Exception { @@ -2010,7 +2052,7 @@ * prevent tasks from progressing. If there is strong lock contention then * writers will be more or less serialized. * - * FIXME javadoc update to reflect the {@link NonBlockingLockManager} + * @todo javadoc update to reflect the {@link NonBlockingLockManager} * * @author <a href="mailto:tho...@us...">Bryan Thompson</a> * @version $Id$ @@ -2044,8 +2086,15 @@ // invoke doTask() on AbstractTask with locks. final T ret = delegate.doTask(); + // checkpoint while holding locks. + delegate.checkpointNanoTime = delegate.checkpointTask(); + + return ret; + + } catch(Throwable t) { + /* - * FIXME If there is an error in the task execution, then for + * RWStore: If there is an error in the task execution, then for * RWStore we need to explicitly undo the allocations for the * B+Tree(s) on which this task wrote. If we do not take this * step, then the records already written onto the store up to @@ -2053,12 +2102,11 @@ * succeeds. This is essentially a persistent memory leak on the * store. */ + delegate.abortTask(); - // checkpoint while holding locks. - delegate.checkpointNanoTime = delegate.checkpointTask(); - - return ret; - + // rethrow the exception. + throw new RuntimeException(t); + } finally { /* @@ -2248,7 +2296,7 @@ * declare a lock - such views will always be read-only and support * concurrent readers. */ - public IIndex getIndex(String name, long timestamp) { + public IIndex getIndex(final String name, final long timestamp) { if (timestamp == ITx.UNISOLATED) { @@ -2393,15 +2441,15 @@ // return delegate.getKeyBuilder(); // } - public void force(boolean metadata) { + public void force(final boolean metadata) { delegate.force(metadata); } - public int getByteCount(long addr) { + public int getByteCount(final long addr) { return delegate.getByteCount(addr); } - public ICommitRecord getCommitRecord(long timestamp) { + public ICommitRecord getCommitRecord(final long timestamp) { return delegate.getCommitRecord(timestamp); } @@ -2413,7 +2461,7 @@ return delegate.getFile(); } - public long getOffset(long addr) { + public long getOffset(final long addr) { return delegate.getOffset(addr); } @@ -2429,7 +2477,7 @@ return delegate.getResourceMetadata(); } - public long getRootAddr(int index) { + public long getRootAddr(final int index) { return delegate.getRootAddr(index); } @@ -2461,7 +2509,7 @@ // delegate.packAddr(out, addr); // } - public ByteBuffer read(long addr) { + public ByteBuffer read(final long addr) { return delegate.read(addr); } @@ -2469,19 +2517,19 @@ return delegate.size(); } - public long toAddr(int nbytes, long offset) { + public long toAddr(final int nbytes, final long offset) { return delegate.toAddr(nbytes, offset); } - public String toString(long addr) { + public String toString(final long addr) { return delegate.toString(addr); } - public IRootBlockView getRootBlock(long commitTime) { + public IRootBlockView getRootBlock(final long commitTime) { return delegate.getRootBlock(commitTime); } - public Iterator<IRootBlockView> getRootBlocks(long startTime) { + public Iterator<IRootBlockView> getRootBlocks(final long startTime) { return delegate.getRootBlocks(startTime); } @@ -2492,16 +2540,16 @@ * the IsolatedActionJournal as the IAllocationContext. This causes the * allocations to be scoped to the AbstractTask. */ - - public long write(ByteBuffer data) { + + public long write(final ByteBuffer data) { return delegate.write(data, this); } - public long write(ByteBuffer data, long oldAddr) { + public long write(final ByteBuffer data, final long oldAddr) { return delegate.write(data, oldAddr, this); } - public void delete(long addr) { + public void delete(final long addr) { delegate.delete(addr, this); } @@ -2517,12 +2565,16 @@ // return delegate.write(data, oldAddr, context); // } - public void detachContext() { - delegate.detachContext(this); - } + public void detachContext() { + delegate.detachContext(this); + } - public ScheduledFuture<?> addScheduledTask(Runnable task, - long initialDelay, long delay, TimeUnit unit) { + public void abortContext() { + delegate.abortContext(this); + } + + public ScheduledFuture<?> addScheduledTask(final Runnable task, + final long initialDelay, final long delay, final TimeUnit unit) { return delegate.addScheduledTask(task, initialDelay, delay, unit); } Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/journal/RWStrategy.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/journal/RWStrategy.java 2011-04-13 20:21:27 UTC (rev 4396) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/journal/RWStrategy.java 2011-04-13 20:33:10 UTC (rev 4397) @@ -265,12 +265,18 @@ } - public void detachContext(final IAllocationContext context) { - - m_store.detachContext(context); - - } + public void detachContext(final IAllocationContext context) { + + m_store.detachContext(context); + + } + public void abortContext(final IAllocationContext context) { + + m_store.abortContext(context); + + } + /** * Operation is not supported. * Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/rawstore/AbstractRawStore.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/rawstore/AbstractRawStore.java 2011-04-13 20:21:27 UTC (rev 4396) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/rawstore/AbstractRawStore.java 2011-04-13 20:33:10 UTC (rev 4397) @@ -96,4 +96,12 @@ public void detachContext(IAllocationContext context) { // NOP } + + /** + * The default implementation is a NOP. + */ + public void abortContext(final IAllocationContext context) { + // NOP + } + } Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/util/httpd/NanoHTTPD.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/util/httpd/NanoHTTPD.java 2011-04-13 20:21:27 UTC (rev 4396) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/util/httpd/NanoHTTPD.java 2011-04-13 20:33:10 UTC (rev 4397) @@ -112,6 +112,9 @@ * </pre> * * @version $Id$ + * + * @deprecated This is being replaced by the use of the Servlet API and embedded + * use of jetty as a light weight servlet container. */ public class NanoHTTPD implements IServiceShutdown { Modified: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/bench/NanoSparqlServer.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/bench/NanoSparqlServer.java 2011-04-13 20:21:27 UTC (rev 4396) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/bench/NanoSparqlServer.java 2011-04-13 20:33:10 UTC (rev 4397) @@ -167,6 +167,9 @@ * (2) I need to verify that the exclusive semaphore logic for the * unisolated sail connection works with cross thread access. Someone had * pointed out a bizarre hole in this.... + * + * @deprecated This has been replaced by the class of the same name in the + * <code>com.bigdata.sail.webapp</code> package. */ public class NanoSparqlServer extends AbstractHTTPD { Added: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/BigdataBaseContext.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/BigdataBaseContext.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/BigdataBaseContext.java 2011-04-13 20:33:10 UTC (rev 4397) @@ -0,0 +1,33 @@ +package com.bigdata.rdf.sail.webapp; + +import org.apache.log4j.Logger; + +import com.bigdata.journal.IIndexManager; + +/** + * Context object provides access to the {@link IIndexManager}. + * + * @author Martyn Cutcher + */ +public class BigdataBaseContext { + + static private final Logger log = Logger.getLogger(BigdataBaseContext.class); + + private final IIndexManager m_indexManager; + + public BigdataBaseContext(final IIndexManager indexManager) { + + if (indexManager == null) + throw new IllegalArgumentException(); + + m_indexManager = indexManager; + + } + + public IIndexManager getIndexManager() { + + return m_indexManager; + + } + +} Property changes on: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/BigdataBaseContext.java ___________________________________________________________________ Added: svn:keywords + Id Date Revision Author HeadURL Deleted: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/BigdataContext.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/BigdataContext.java 2011-04-13 20:21:27 UTC (rev 4396) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/BigdataContext.java 2011-04-13 20:33:10 UTC (rev 4397) @@ -1,616 +0,0 @@ -package com.bigdata.rdf.sail.webapp; - -import info.aduna.xml.XMLWriter; - -import java.io.IOException; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.io.StringWriter; -import java.util.Map; -import java.util.UUID; -import java.util.concurrent.Callable; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ScheduledFuture; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicLong; - -import javax.servlet.ServletContext; -import javax.servlet.http.HttpServletRequest; - -import org.apache.log4j.Logger; -import org.openrdf.query.MalformedQueryException; -import org.openrdf.query.QueryLanguage; -import org.openrdf.query.parser.ParsedQuery; -import org.openrdf.query.parser.QueryParser; -import org.openrdf.query.parser.sparql.SPARQLParserFactory; -import org.openrdf.query.resultio.sparqlxml.SPARQLResultsXMLWriter; -import org.openrdf.repository.RepositoryException; -import org.openrdf.rio.rdfxml.RDFXMLWriter; -import org.openrdf.sail.SailException; - -import com.bigdata.bop.engine.QueryEngine; -import com.bigdata.journal.IIndexManager; -import com.bigdata.journal.ITx; -import com.bigdata.journal.TimestampUtility; -import com.bigdata.rawstore.Bytes; -import com.bigdata.rdf.sail.BigdataSail; -import com.bigdata.rdf.sail.BigdataSailGraphQuery; -import com.bigdata.rdf.sail.BigdataSailRepository; -import com.bigdata.rdf.sail.BigdataSailRepositoryConnection; -import com.bigdata.rdf.sail.BigdataSailTupleQuery; -import com.bigdata.rdf.sail.bench.NanoSparqlServer; -import com.bigdata.rdf.sail.webapp.BigdataServlet.QueryType; -import com.bigdata.rdf.store.AbstractTripleStore; -import com.bigdata.util.concurrent.ThreadPoolExecutorBaseStatisticsTask; -import com.bigdata.util.httpd.NanoHTTPD; - -/** - * - * @author Martyn Cutcher - * - */ -public class BigdataContext { - /** - * The logger for the concrete {@link NanoSparqlServer} class. The {@link NanoHTTPD} - * class has its own logger. - */ - static private final Logger log = Logger.getLogger(BigdataServlet.class); - - static private BigdataContext s_context; - - private final Config m_config; - private final IIndexManager m_indexManager; - private final QueryParser m_engine; - - private final ScheduledFuture<?> m_queueStatsFuture; - private final ThreadPoolExecutorBaseStatisticsTask m_queueSampleTask; - - /** - * The currently executing queries (does not include queries where a client - * has established a connection but the query is not running because the - * {@link #queryService} is blocking). - */ - protected final ConcurrentHashMap<Long/* queryId */, RunningQuery> m_queries = new ConcurrentHashMap<Long, RunningQuery>(); - - public Map<Long, RunningQuery> getQueries() { - return m_queries; - } - - /** - * Factory for the query identifiers. - */ - protected final AtomicLong m_queryIdFactory = new AtomicLong(); - - public AtomicLong getQueryIdFactory() { - return m_queryIdFactory; - } - - /** - * This call establishes the context to run the servlets that - * use it in an embedded server. - * - * @param config - * @param indexManager - * @return the BigdataContext - */ - synchronized static public BigdataContext establishContext(final Config config, final IIndexManager indexManager) - throws SailException, RepositoryException, IOException { - if (s_context == null) { - s_context = new BigdataContext(config, indexManager); - } - - return s_context; - } - - /** - * When a servlet starts up in a web container it establishes the BigdataContext - * that will be defined by the context parameters in the web.xml file. - * - * @param context - * @return the BigdataContext - */ - synchronized static BigdataContext establishContext(ServletContext context) { - if (s_context == null) { - // TODO get config info from servlet context - } - - return s_context; - } - - static BigdataContext getContext() { - return s_context; - } - - public BigdataContext(final Config config, final IIndexManager indexManager) throws IOException, SailException, - RepositoryException { - - if (config.namespace == null) - throw new IllegalArgumentException(); - - if (indexManager == null) - throw new IllegalArgumentException(); - - m_config = config; - - m_indexManager = indexManager; - - // used to parse qeries. - m_engine = new SPARQLParserFactory().getParser(); - - if (indexManager.getCollectQueueStatistics()) { - - final long initialDelay = 0; // initial delay in ms. - final long delay = 1000; // delay in ms. - final TimeUnit unit = TimeUnit.MILLISECONDS; - - // FIXME add mechanism for stats sampling - // queueSampleTask = new ThreadPoolExecutorBaseStatisticsTask( - // (ThreadPoolExecutor) queryService); - // - // queueStatsFuture = indexManager.addScheduledTask(queueSampleTask, - // initialDelay, delay, unit); - - m_queueSampleTask = null; - - m_queueStatsFuture = null; - } else { - - m_queueSampleTask = null; - - m_queueStatsFuture = null; - - } - - } - - public void shutdownNow() { - if(log.isInfoEnabled()) - log.info("Normal shutdown."); - - // Stop collecting queue statistics. - if (m_queueStatsFuture != null) - m_queueStatsFuture.cancel(true/* mayInterruptIfRunning */); - - } - - public IIndexManager getIndexManager() { - return m_indexManager; - } - - /** - * Configuration object. - */ - public static class Config { - - /** - * When true, suppress various things otherwise written on stdout. - */ - public boolean quiet = false; - - /** - * The port on which the server will answer requests -or- ZERO to - * use any open port. - */ - public int port = 80; - - /** - * The default namespace. - */ - public String namespace; - - /** - * The default timestamp used to query the default namespace. The server - * will obtain a read only transaction which reads from the commit point - * associated with this timestamp. - */ - public long timestamp = ITx.UNISOLATED; - - /** - * The #of threads to use to handle SPARQL queries -or- ZERO (0) for an - * unbounded pool. - */ - public int queryThreadPoolSize = 8; - -// /** -// * The capacity of the buffers for the pipe connecting the running query -// * to the HTTP response. -// */ -// public int bufferCapacity = Bytes.kilobyte32 * 1; - - public String resourceBase = "."; - - public Config() { - } - - } - - public Config getConfig() { - return m_config; - } - - public ThreadPoolExecutorBaseStatisticsTask getSampleTask() { - return m_queueSampleTask; - } - - public static void clear() { - if (s_context != null) { - s_context.shutdownNow(); - s_context = null; - } - } - - /** - * Abstract base class for running queries handles the timing, pipe, - * reporting, obtains the connection, and provides the finally {} semantics - * for each type of query task. - * - * @author <a href="mailto:tho...@us...">Bryan - * Thompson</a> - * @version $Id$ - */ - public abstract class AbstractQueryTask implements Callable<Void> { - - /** The namespace against which the query will be run. */ - private final String namespace; - - /** - * The timestamp of the view for that namespace against which the query - * will be run. - */ - private final long timestamp; - - /** The SPARQL query string. */ - protected final String queryStr; - - /** - * A symbolic constant indicating the type of query. - */ - protected final QueryType queryType; - - /** - * The negotiated MIME type to be used for the query response. - */ - protected final String mimeType; - - /** A pipe used to incrementally deliver the results to the client. */ - private final OutputStream os; - - /** - * Sesame has an option for a base URI during query evaluation. This - * provides a symbolic place holder for that URI in case we ever provide - * a hook to set it. - */ - protected final String baseURI = null; - - /** - * The queryId used by the {@link NanoSparqlServer}. - */ - protected final Long queryId; - - /** - * The queryId used by the {@link QueryEngine}. - */ - protected final UUID queryId2; - - /** - * - * @param namespace - * The namespace against which the query will be run. - * @param timestamp - * The timestamp of the view for that namespace against which - * the query will be run. - * @param queryStr - * The SPARQL query string. - * @param os - * A pipe used to incrementally deliver the results to the - * client. - */ - protected AbstractQueryTask(final String namespace, - final long timestamp, final String queryStr, - final QueryType queryType, - final String mimeType, - final OutputStream os) { - - this.namespace = namespace; - this.timestamp = timestamp; - this.queryStr = queryStr; - this.queryType = queryType; - this.mimeType = mimeType; - this.os = os; - this.queryId = Long.valueOf(m_queryIdFactory.incrementAndGet()); - this.queryId2 = UUID.randomUUID(); - - } - - /** - * Execute the query. - * - * @param cxn - * The connection. - * @param os - * Where the write the query results. - * - * @throws Exception - */ - abstract protected void doQuery(BigdataSailRepositoryConnection cxn, - OutputStream os) throws Exception; - - final public Void call() throws Exception { - final long begin = System.nanoTime(); - BigdataSailRepositoryConnection cxn = null; - try { - cxn = getQueryConnection(namespace, timestamp); - m_queries.put(queryId, new RunningQuery(queryId.longValue(),queryId2, - queryStr, begin)); - if(log.isTraceEnabled()) - log.trace("Query running..."); -// try { - doQuery(cxn, os); -// } catch(Throwable t) { -// /* -// * Log the query and the exception together. -// */ -// log.error(t.getLocalizedMessage() + ":\n" + queryStr, t); -// } - if(log.isTraceEnabled()) - log.trace("Query done - flushing results."); - os.flush(); - os.close(); - if(log.isTraceEnabled()) - log.trace("Query done - output stream closed."); - return null; - } catch (Throwable t) { - // launder and rethrow the exception. - throw BigdataServlet.launderThrowable(t, os, queryStr); - } finally { - m_queries.remove(queryId); - try { - os.close(); - } catch (Throwable t) { - log.error(t, t); - } - try { - if (cxn != null) - cxn.close(); - } catch (Throwable t) { - log.error(t, t); - } - } - } - - } - - /** - * Executes a tuple query. - */ - private class TupleQueryTask extends AbstractQueryTask { - - public TupleQueryTask(final String namespace, final long timestamp, - final String queryStr, final QueryType queryType, - final String mimeType, final OutputStream os) { - - super(namespace, timestamp, queryStr, queryType, mimeType, os); - - } - - protected void doQuery(final BigdataSailRepositoryConnection cxn, - final OutputStream os) throws Exception { - - final BigdataSailTupleQuery query = cxn.prepareTupleQuery( - QueryLanguage.SPARQL, queryStr, baseURI); - - if (true) { - StringWriter strw = new StringWriter(); - - query.evaluate(new SPARQLResultsXMLWriter(new XMLWriter(strw))); - - OutputStreamWriter outstr = new OutputStreamWriter(os); - String res = strw.toString(); - outstr.write(res); - outstr.flush(); - outstr.close(); - } else { - query.evaluate(new SPARQLResultsXMLWriter(new XMLWriter(os))); - } - } - - } - - /** - * Executes a graph query. - */ - private class GraphQueryTask extends AbstractQueryTask { - - public GraphQueryTask(final String namespace, final long timestamp, - final String queryStr, final QueryType queryType, - final String mimeType, final OutputStream os) { - - super(namespace, timestamp, queryStr, queryType, mimeType, os); - - } - - @Override - protected void doQuery(final BigdataSailRepositoryConnection cxn, - final OutputStream os) throws Exception { - - final BigdataSailGraphQuery query = cxn.prepareGraphQuery( - QueryLanguage.SPARQL, queryStr, baseURI); - - query.evaluate(new RDFXMLWriter(os)); - - } - - } - ... [truncated message content] |