Author: toad
Date: 2008-06-17 15:21:31 +0000 (Tue, 17 Jun 2008)
New Revision: 20400

Modified:
   branches/db4o/freenet/src/freenet/clients/http/QueueToadlet.java
   branches/db4o/freenet/src/freenet/node/fcp/FCPClient.java
   branches/db4o/freenet/src/freenet/node/fcp/FCPServer.java
Log:
Blocking remove for web interface

Modified: branches/db4o/freenet/src/freenet/clients/http/QueueToadlet.java
===================================================================
--- branches/db4o/freenet/src/freenet/clients/http/QueueToadlet.java    
2008-06-17 15:14:17 UTC (rev 20399)
+++ branches/db4o/freenet/src/freenet/clients/http/QueueToadlet.java    
2008-06-17 15:21:31 UTC (rev 20400)
@@ -139,7 +139,7 @@
                                String identifier = 
request.getPartAsString("identifier", MAX_IDENTIFIER_LENGTH);
                                if(logMINOR) Logger.minor(this, "Removing 
"+identifier);
                                try {
-                                       fcp.removeGlobalRequest(identifier);
+                                       
fcp.removeGlobalRequestBlocking(identifier);
                                } catch (MessageInvalidException e) {
                                        this.sendErrorPage(ctx, 200, 
                                                        
L10n.getString("QueueToadlet.failedToRemoveRequest"),

Modified: branches/db4o/freenet/src/freenet/node/fcp/FCPClient.java
===================================================================
--- branches/db4o/freenet/src/freenet/node/fcp/FCPClient.java   2008-06-17 
15:14:17 UTC (rev 20399)
+++ branches/db4o/freenet/src/freenet/node/fcp/FCPClient.java   2008-06-17 
15:21:31 UTC (rev 20400)
@@ -153,7 +153,7 @@
                }
        }

-       public void removeByIdentifier(String identifier, boolean kill, 
FCPServer server, ObjectContainer container) throws MessageInvalidException {
+       public boolean removeByIdentifier(String identifier, boolean kill, 
FCPServer server, ObjectContainer container) {
                assert((persistenceType == ClientRequest.PERSIST_FOREVER) == 
(container != null));
                ClientRequest req;
                boolean logMINOR = Logger.shouldLog(Logger.MINOR, this);
@@ -161,9 +161,11 @@
                synchronized(this) {
                        req = (ClientRequest) 
clientRequestsByIdentifier.get(identifier);
                        if(req == null)
-                               throw new 
MessageInvalidException(ProtocolErrorMessage.NO_SUCH_IDENTIFIER, "Not in hash", 
identifier, isGlobalQueue);
-                       else if(!(runningPersistentRequests.remove(req) || 
completedUnackedRequests.remove(req)))
-                               throw new 
MessageInvalidException(ProtocolErrorMessage.NO_SUCH_IDENTIFIER, "Not found", 
identifier, isGlobalQueue);
+                               return false;
+                       else if(!(runningPersistentRequests.remove(req) || 
completedUnackedRequests.remove(req))) {
+                               Logger.error(this, "Removing "+identifier+": in 
clientRequestsByIdentifier but not in running/completed maps!");
+                               return false;
+                       }
                        clientRequestsByIdentifier.remove(identifier);
                }
         req.requestWasRemoved(container);
@@ -173,6 +175,7 @@
                }
                if(completionCallback != null)
                        completionCallback.onRemove(req);
+               return true;
        }

        public boolean hasPersistentRequests(ObjectContainer container) {

Modified: branches/db4o/freenet/src/freenet/node/fcp/FCPServer.java
===================================================================
--- branches/db4o/freenet/src/freenet/node/fcp/FCPServer.java   2008-06-17 
15:14:17 UTC (rev 20399)
+++ branches/db4o/freenet/src/freenet/node/fcp/FCPServer.java   2008-06-17 
15:21:31 UTC (rev 20400)
@@ -45,6 +45,7 @@
 import freenet.node.RequestStarter;
 import freenet.support.Base64;
 import freenet.support.Logger;
+import freenet.support.MutableBoolean;
 import freenet.support.OOMHandler;
 import freenet.support.api.BooleanCallback;
 import freenet.support.api.Bucket;
@@ -565,8 +566,36 @@
                return (ClientRequest[]) v.toArray(new ClientRequest[v.size()]);
        }

-       public void removeGlobalRequest(String identifier) throws 
MessageInvalidException {
-               globalClient.removeByIdentifier(identifier, true);
+       public void removeGlobalRequestBlocking(final String identifier) throws 
MessageInvalidException {
+               if(!globalRebootClient.removeByIdentifier(identifier, true, 
this, null)) {
+                       final Object sync = new Object();
+                       final MutableBoolean done = new MutableBoolean();
+                       done.value = false;
+                       core.clientContext.jobRunner.queue(new DBJob() {
+
+                               public void run(ObjectContainer container, 
ClientContext context) {
+                                       try {
+                                               
globalForeverClient.removeByIdentifier(identifier, true, FCPServer.this, 
container);
+                                       } catch (Throwable t) {
+                                               Logger.error(this, "Caught 
removing identifier "+identifier+": "+t, t);
+                                       } finally {
+                                               synchronized(sync) {
+                                                       sync.notifyAll();
+                                               }
+                                       }
+                               }
+                               
+                       }, NativeThread.HIGH_PRIORITY, false);
+                       synchronized(sync) {
+                               while(!done.value) {
+                                       try {
+                                               sync.wait();
+                                       } catch (InterruptedException e) {
+                                               // Ignore
+                                       }
+                               }
+                       }
+               }
        }

        /**


Reply via email to