diff --git a/robospice-core-parent/robospice/src/main/java/com/octo/android/robospice/request/RequestProcessor.java b/robospice-core-parent/robospice/src/main/java/com/octo/android/robospice/request/RequestProcessor.java index e85fa6964..5259f5bcd 100644 --- a/robospice-core-parent/robospice/src/main/java/com/octo/android/robospice/request/RequestProcessor.java +++ b/robospice-core-parent/robospice/src/main/java/com/octo/android/robospice/request/RequestProcessor.java @@ -77,23 +77,25 @@ public void addRequest(final CachedSpiceRequest request, final Set> listRequestListenerForThisRequest; - synchronized (mapRequestToRequestListener) { - listRequestListenerForThisRequest = mapRequestToRequestListener.get(request); + synchronized (requestProgressManager) { + synchronized (mapRequestToRequestListener) { + listRequestListenerForThisRequest = mapRequestToRequestListener.get(request); - if (listRequestListenerForThisRequest == null) { - if (request.isProcessable()) { - Ln.d("Adding entry for type %s and cacheKey %s.", request.getResultType(), request.getRequestCacheKey()); - listRequestListenerForThisRequest = Collections.synchronizedSet(new HashSet>()); - this.mapRequestToRequestListener.put(request, listRequestListenerForThisRequest); + if (listRequestListenerForThisRequest == null) { + if (request.isProcessable()) { + Ln.d("Adding entry for type %s and cacheKey %s.", request.getResultType(), request.getRequestCacheKey()); + listRequestListenerForThisRequest = Collections.synchronizedSet(new HashSet>()); + this.mapRequestToRequestListener.put(request, listRequestListenerForThisRequest); + } + } else { + Ln.d("Request for type %s and cacheKey %s already exists.", request.getResultType(), request.getRequestCacheKey()); + aggregated = true; } - } else { - Ln.d("Request for type %s and cacheKey %s already exists.", request.getResultType(), request.getRequestCacheKey()); - aggregated = true; } - } - if (listRequestListener != null && listRequestListenerForThisRequest != null) { - listRequestListenerForThisRequest.addAll(listRequestListener); + if (listRequestListener != null && listRequestListenerForThisRequest != null) { + listRequestListenerForThisRequest.addAll(listRequestListener); + } } if (aggregated) { diff --git a/robospice-core-parent/robospice/src/main/java/com/octo/android/robospice/request/RequestProgressManager.java b/robospice-core-parent/robospice/src/main/java/com/octo/android/robospice/request/RequestProgressManager.java index 708a07d31..a2bdcf1ee 100644 --- a/robospice-core-parent/robospice/src/main/java/com/octo/android/robospice/request/RequestProgressManager.java +++ b/robospice-core-parent/robospice/src/main/java/com/octo/android/robospice/request/RequestProgressManager.java @@ -100,7 +100,7 @@ public void notifyListenersOfRequestSuccessButDontCompleteRequest(final Cach requestListenerNotifier.notifyListenersOfRequestSuccess(request, result, listeners); } - public void notifyListenersOfRequestSuccess(final CachedSpiceRequest request, final T result) { + public synchronized void notifyListenersOfRequestSuccess(final CachedSpiceRequest request, final T result) { final Set> listeners = mapRequestToRequestListener.get(request); notifyListenersOfRequestProgress(request, listeners, RequestStatus.COMPLETE); @@ -109,7 +109,7 @@ public void notifyListenersOfRequestSuccess(final CachedSpiceRequest requ notifyOfRequestProcessed(request, listeners); } - public void notifyListenersOfRequestFailure(final CachedSpiceRequest request, final SpiceException e) { + public synchronized void notifyListenersOfRequestFailure(final CachedSpiceRequest request, final SpiceException e) { final Set> listeners = mapRequestToRequestListener.get(request); notifyListenersOfRequestProgress(request, listeners, RequestStatus.COMPLETE); @@ -118,7 +118,7 @@ public void notifyListenersOfRequestFailure(final CachedSpiceRequest requ notifyOfRequestProcessed(request, listeners); } - public void notifyListenersOfRequestCancellation(final CachedSpiceRequest request) { + public synchronized void notifyListenersOfRequestCancellation(final CachedSpiceRequest request) { Ln.d("Not calling network request : " + request + " as it is cancelled. "); final Set> listeners = mapRequestToRequestListener.get(request); notifyListenersOfRequestProgress(request, listeners, RequestStatus.COMPLETE);