create requests on progress if they have not been added before
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 14 May 2008 20:06:49 +0000 (20:06 +0000)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 14 May 2008 20:06:49 +0000 (20:06 +0000)
git-svn-id: http://trooper/svn/projects/jSite/trunk@882 c3eda9e8-030b-0410-8277-bc7414b0a119

src/net/pterodactylus/jsite/core/RequestManager.java

index a90207b..3b98dc2 100644 (file)
@@ -158,7 +158,7 @@ public class RequestManager implements NodeListener, HighLevelProgressListener {
                        logger.log(Level.WARNING, "no client for node: " + node);
                        return;
                }
-               final Map<String, Request> identifierRequests = new HashMap<String, Request>();
+               final Map<String, Request> identifierRequests = Collections.synchronizedMap(new HashMap<String, Request>());
                nodeRequests.put(node, identifierRequests);
                HighLevelCallback<RequestListResult> requestListCallback = highLevelClient.getRequests();
                requestListCallback.addHighLevelCallbackListener(new HighLevelCallbackListener<RequestListResult>() {
@@ -173,14 +173,15 @@ public class RequestManager implements NodeListener, HighLevelProgressListener {
                                        return;
                                }
                                for (RequestResult requestResult: requestListResult) {
-                                       String identifier = requestResult.getIdentifier();
-                                       if (identifierRequests.containsKey(identifier)) {
-                                               continue;
-                                       }
-                                       Request request = new Request(node, identifier);
-                                       identifierRequests.put(requestResult.getIdentifier(), request);
-                                       /* TODO - fill request */
-                                       fireRequestAdded(request);
+                                               String identifier = requestResult.getIdentifier();
+                                               logger.log(Level.FINER, "got identifier: " + identifier);
+                                               if (identifierRequests.containsKey(identifier)) {
+                                                       continue;
+                                               }
+                                               Request request = new Request(node, identifier);
+                                               identifierRequests.put(requestResult.getIdentifier(), request);
+                                               /* TODO - fill request */
+                                               fireRequestAdded(request);
                                }
                        }
                });
@@ -270,13 +271,16 @@ public class RequestManager implements NodeListener, HighLevelProgressListener {
                Map<String, Request> identifierRequests = nodeRequests.get(node);
                if (identifierRequests == null) {
                        logger.warning("got node without request map: " + node);
-                       return;
+                       identifierRequests = Collections.synchronizedMap(new HashMap<String, Request>());
+                       nodeRequests.put(node, identifierRequests);
                }
                Request request = identifierRequests.get(identifier);
-               if (request == null) {
-                       logger.warning("got progress for unknown request: " + identifier);
-                       return;
-               }
+                       if (request == null) {
+                               logger.warning("got progress for unknown request: " + identifier);
+                               request = new Request(node, identifier);
+                               identifierRequests.put(identifier, request);
+                               fireRequestAdded(request);
+                       }
                request.setTotalBlocks(highLevelProgress.getTotalBlocks());
                request.setRequiredBlocks(highLevelProgress.getRequiredBlocks());
                request.setSuccessfulBlocks(highLevelProgress.getSuccessfulBlocks());