Skip to content
This repository has been archived by the owner on Jan 14, 2018. It is now read-only.

Sync fixes #405

Open
wants to merge 1 commit into
base: release
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,23 +77,25 @@ public void addRequest(final CachedSpiceRequest<?> request, final Set<RequestLis
boolean aggregated = false;
Set<RequestListener<?>> 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<RequestListener<?>>());
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<RequestListener<?>>());
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public <T> void notifyListenersOfRequestSuccessButDontCompleteRequest(final Cach
requestListenerNotifier.notifyListenersOfRequestSuccess(request, result, listeners);
}

public <T> void notifyListenersOfRequestSuccess(final CachedSpiceRequest<T> request, final T result) {
public synchronized <T> void notifyListenersOfRequestSuccess(final CachedSpiceRequest<T> request, final T result) {
final Set<RequestListener<?>> listeners = mapRequestToRequestListener.get(request);
notifyListenersOfRequestProgress(request, listeners, RequestStatus.COMPLETE);

Expand All @@ -109,7 +109,7 @@ public <T> void notifyListenersOfRequestSuccess(final CachedSpiceRequest<T> requ
notifyOfRequestProcessed(request, listeners);
}

public <T> void notifyListenersOfRequestFailure(final CachedSpiceRequest<T> request, final SpiceException e) {
public synchronized <T> void notifyListenersOfRequestFailure(final CachedSpiceRequest<T> request, final SpiceException e) {
final Set<RequestListener<?>> listeners = mapRequestToRequestListener.get(request);
notifyListenersOfRequestProgress(request, listeners, RequestStatus.COMPLETE);

Expand All @@ -118,7 +118,7 @@ public <T> void notifyListenersOfRequestFailure(final CachedSpiceRequest<T> 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<RequestListener<?>> listeners = mapRequestToRequestListener.get(request);
notifyListenersOfRequestProgress(request, listeners, RequestStatus.COMPLETE);
Expand Down