From 5c30d4efe4d50eee3538b9f93276fb40eb28438e Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 14 May 2008 20:06:49 +0000 Subject: [PATCH] create requests on progress if they have not been added before git-svn-id: http://trooper/svn/projects/jSite/trunk@882 c3eda9e8-030b-0410-8277-bc7414b0a119 --- .../pterodactylus/jsite/core/RequestManager.java | 32 ++++++++++++---------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/net/pterodactylus/jsite/core/RequestManager.java b/src/net/pterodactylus/jsite/core/RequestManager.java index a90207b..3b98dc2 100644 --- a/src/net/pterodactylus/jsite/core/RequestManager.java +++ b/src/net/pterodactylus/jsite/core/RequestManager.java @@ -158,7 +158,7 @@ public class RequestManager implements NodeListener, HighLevelProgressListener { logger.log(Level.WARNING, "no client for node: " + node); return; } - final Map identifierRequests = new HashMap(); + final Map identifierRequests = Collections.synchronizedMap(new HashMap()); nodeRequests.put(node, identifierRequests); HighLevelCallback requestListCallback = highLevelClient.getRequests(); requestListCallback.addHighLevelCallbackListener(new HighLevelCallbackListener() { @@ -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 identifierRequests = nodeRequests.get(node); if (identifierRequests == null) { logger.warning("got node without request map: " + node); - return; + identifierRequests = Collections.synchronizedMap(new HashMap()); + 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()); -- 2.7.4