You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by rv...@apache.org on 2013/01/14 13:53:12 UTC
svn commit: r1432905 - in
/jena/Experimental/cancellable-updates/src/main/java/com/hp/hpl/jena:
sparql/modify/UpdateProcessRemote.java
sparql/modify/UpdateProcessRemoteForm.java
sparql/modify/UpdateProcessorBase.java update/UpdateProcessor.java
Author: rvesse
Date: Mon Jan 14 12:53:12 2013
New Revision: 1432905
URL: http://svn.apache.org/viewvc?rev=1432905&view=rev
Log:
Initial update cancellation API stubs (JENA-382)
Modified:
jena/Experimental/cancellable-updates/src/main/java/com/hp/hpl/jena/sparql/modify/UpdateProcessRemote.java
jena/Experimental/cancellable-updates/src/main/java/com/hp/hpl/jena/sparql/modify/UpdateProcessRemoteForm.java
jena/Experimental/cancellable-updates/src/main/java/com/hp/hpl/jena/sparql/modify/UpdateProcessorBase.java
jena/Experimental/cancellable-updates/src/main/java/com/hp/hpl/jena/update/UpdateProcessor.java
Modified: jena/Experimental/cancellable-updates/src/main/java/com/hp/hpl/jena/sparql/modify/UpdateProcessRemote.java
URL: http://svn.apache.org/viewvc/jena/Experimental/cancellable-updates/src/main/java/com/hp/hpl/jena/sparql/modify/UpdateProcessRemote.java?rev=1432905&r1=1432904&r2=1432905&view=diff
==============================================================================
--- jena/Experimental/cancellable-updates/src/main/java/com/hp/hpl/jena/sparql/modify/UpdateProcessRemote.java (original)
+++ jena/Experimental/cancellable-updates/src/main/java/com/hp/hpl/jena/sparql/modify/UpdateProcessRemote.java Mon Jan 14 12:53:12 2013
@@ -35,6 +35,7 @@ public class UpdateProcessRemote impleme
{
private final UpdateRequest request ;
private final String endpoint ;
+ private Boolean inProgress = false, cancelled = false;
public UpdateProcessRemote(UpdateRequest request , String endpoint )
{
@@ -57,10 +58,38 @@ public class UpdateProcessRemote impleme
@Override
public void execute()
{
+ synchronized (cancelled) {
+ if (cancelled) throw new ARQException("This update has been cancelled, if you wish to re-attempt please create a fresh UpdateProcessor instance");
+ }
+
if ( endpoint == null )
throw new ARQException("Null endpoint for remote update") ;
String reqStr = request.toString() ;
- HttpOp.execHttpPost(endpoint, WebContent.contentTypeSPARQLUpdate, reqStr) ;
+
+ //Flag whether updates are in progress, required to know whether we can safely cancel or not
+ synchronized (inProgress) {
+ if (inProgress) throw new ARQException("The remote update is already executing, please wait for it to complete before calling execute() again");
+ inProgress = true;
+ }
+ HttpOp.execHttpPost(endpoint, WebContent.contentTypeSPARQLUpdate, reqStr) ;
+ //Flag whether updates are in progress, required to know whether we can safely cancel or not
+ synchronized (inProgress) {
+ inProgress = false;
+ }
+ }
+
+ @Override
+ public void cancel()
+ {
+ //Mark updates as cancelled
+ synchronized (cancelled) {
+ cancelled = true;
+ }
+ //We can't cancel in-progress remote updates, if it is in-progress then
+ //throw an UnsupportedOperationException
+ synchronized (inProgress) {
+ if (inProgress) throw new UnsupportedOperationException("Cannot cancel an in-progress remote update");
+ }
}
@Override
Modified: jena/Experimental/cancellable-updates/src/main/java/com/hp/hpl/jena/sparql/modify/UpdateProcessRemoteForm.java
URL: http://svn.apache.org/viewvc/jena/Experimental/cancellable-updates/src/main/java/com/hp/hpl/jena/sparql/modify/UpdateProcessRemoteForm.java?rev=1432905&r1=1432904&r2=1432905&view=diff
==============================================================================
--- jena/Experimental/cancellable-updates/src/main/java/com/hp/hpl/jena/sparql/modify/UpdateProcessRemoteForm.java (original)
+++ jena/Experimental/cancellable-updates/src/main/java/com/hp/hpl/jena/sparql/modify/UpdateProcessRemoteForm.java Mon Jan 14 12:53:12 2013
@@ -43,6 +43,7 @@ public class UpdateProcessRemoteForm imp
{
private final UpdateRequest request ;
private final String endpoint ;
+ private Boolean inProgress = false, cancelled = false;
public UpdateProcessRemoteForm(UpdateRequest request , String endpoint )
{
@@ -64,7 +65,7 @@ public class UpdateProcessRemoteForm imp
@Override
public void execute()
- {
+ {
if ( endpoint == null )
throw new ARQException("Null endpoint for remote update by form") ;
String reqStr = request.toString() ;
@@ -73,7 +74,36 @@ public class UpdateProcessRemoteForm imp
Map<String, HttpResponseHandler> handlers = new HashMap<String, HttpResponseHandler>() ;
//handlers.put("text/html", HttpResponseLib.nullResponse) ;
handlers.put("*", HttpResponseLib.nullResponse) ;
+
+ //Check for cancellation
+ synchronized (cancelled) {
+ if (cancelled) throw new ARQException("This update has been cancelled, if you wish to re-attempt please create a fresh UpdateProcessor instance");
+ }
+
+ //Flag whether updates are in progress, required to know whether we can safely cancel or not
+ synchronized (inProgress) {
+ if (inProgress) throw new ARQException("The remote update is already executing, please wait for it to complete before calling execute() again");
+ inProgress = true;
+ }
HttpOp.execHttpPostForm(endpoint, params, handlers) ;
+ //Flag whether updates are in progress, required to know whether we can safely cancel or not
+ synchronized (inProgress) {
+ inProgress = false;
+ }
+ }
+
+ @Override
+ public void cancel()
+ {
+ //Mark updates as cancelled
+ synchronized (cancelled) {
+ cancelled = true;
+ }
+ //We can't cancel in-progress remote updates, if it is in-progress then
+ //throw an UnsupportedOperationException
+ synchronized (inProgress) {
+ if (inProgress) throw new UnsupportedOperationException("Cannot cancel an in-progress remote update");
+ }
}
@Override
Modified: jena/Experimental/cancellable-updates/src/main/java/com/hp/hpl/jena/sparql/modify/UpdateProcessorBase.java
URL: http://svn.apache.org/viewvc/jena/Experimental/cancellable-updates/src/main/java/com/hp/hpl/jena/sparql/modify/UpdateProcessorBase.java?rev=1432905&r1=1432904&r2=1432905&view=diff
==============================================================================
--- jena/Experimental/cancellable-updates/src/main/java/com/hp/hpl/jena/sparql/modify/UpdateProcessorBase.java (original)
+++ jena/Experimental/cancellable-updates/src/main/java/com/hp/hpl/jena/sparql/modify/UpdateProcessorBase.java Mon Jan 14 12:53:12 2013
@@ -55,6 +55,12 @@ public class UpdateProcessorBase impleme
UpdateEngine proc = factory.create(request, graphStore, initialBinding, context) ;
proc.execute() ;
}
+
+ @Override
+ public void cancel()
+ {
+ throw new UnsupportedOperationException("Cancellation is not yet supported");
+ }
@Override
public GraphStore getGraphStore()
Modified: jena/Experimental/cancellable-updates/src/main/java/com/hp/hpl/jena/update/UpdateProcessor.java
URL: http://svn.apache.org/viewvc/jena/Experimental/cancellable-updates/src/main/java/com/hp/hpl/jena/update/UpdateProcessor.java?rev=1432905&r1=1432904&r2=1432905&view=diff
==============================================================================
--- jena/Experimental/cancellable-updates/src/main/java/com/hp/hpl/jena/update/UpdateProcessor.java (original)
+++ jena/Experimental/cancellable-updates/src/main/java/com/hp/hpl/jena/update/UpdateProcessor.java Mon Jan 14 12:53:12 2013
@@ -46,4 +46,20 @@ public interface UpdateProcessor
/** Execute */
public void execute() ;
+
+ /**
+ * Cancels execution if cancellation is supported
+ * <p>
+ * If the update processor has yet to start execution this should have no immediate effect
+ * but should cause the processor to throw an error if and when {@link #execute()} is called.
+ * </p>
+ * <p>
+ * If the processor is carrying out the execution then it should halt and abort the update as soon
+ * as it is able. The side effects of cancellation with regards to things like transactions
+ * should be the same as if an error occurred in update processing i.e. transactions should be rolled
+ * back or marked as un-commitable and an error should be thrown for the user to handle as desired.
+ * </p>
+ * @exception UnsupportedOperationException Thrown if cancellation is not supported
+ */
+ public void cancel() ;
}