Skip to content

Add type arguments in StorageTaskManager #517

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 13, 2019
Merged
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 @@ -32,7 +32,7 @@
/*package*/ class StorageTaskManager {
private static final StorageTaskManager _instance = new StorageTaskManager();

private final Map<String, WeakReference<StorageTask>> inProgressTasks = new HashMap<>();
private final Map<String, WeakReference<StorageTask<?>>> inProgressTasks = new HashMap<>();

private final Object syncObject = new Object();

Expand All @@ -44,7 +44,7 @@ public List<UploadTask> getUploadTasksUnder(@NonNull StorageReference parent) {
synchronized (syncObject) {
ArrayList<UploadTask> inProgressList = new ArrayList<>();
String parentPath = parent.toString();
for (Map.Entry<String, WeakReference<StorageTask>> entry : inProgressTasks.entrySet()) {
for (Map.Entry<String, WeakReference<StorageTask<?>>> entry : inProgressTasks.entrySet()) {
if (entry.getKey().startsWith(parentPath)) {
StorageTask task = entry.getValue().get();
if (task instanceof UploadTask) {
Expand All @@ -60,9 +60,9 @@ public List<FileDownloadTask> getDownloadTasksUnder(@NonNull StorageReference pa
synchronized (syncObject) {
ArrayList<FileDownloadTask> inProgressList = new ArrayList<>();
String parentPath = parent.toString();
for (Map.Entry<String, WeakReference<StorageTask>> entry : inProgressTasks.entrySet()) {
for (Map.Entry<String, WeakReference<StorageTask<?>>> entry : inProgressTasks.entrySet()) {
if (entry.getKey().startsWith(parentPath)) {
StorageTask task = entry.getValue().get();
StorageTask<?> task = entry.getValue().get();
if (task instanceof FileDownloadTask) {
inProgressList.add((FileDownloadTask) task);
}
Expand All @@ -72,19 +72,19 @@ public List<FileDownloadTask> getDownloadTasksUnder(@NonNull StorageReference pa
}
}

public void ensureRegistered(StorageTask targetTask) {
public void ensureRegistered(StorageTask<?> targetTask) {
synchronized (syncObject) {
// ensure *this* is added to the in progress list
inProgressTasks.put(targetTask.getStorage().toString(), new WeakReference<>(targetTask));
}
}

public void unRegister(StorageTask targetTask) {
public void unRegister(StorageTask<?> targetTask) {
synchronized (syncObject) {
// ensure *this* is added to the in progress list
String key = targetTask.getStorage().toString();
WeakReference<StorageTask> weakReference = inProgressTasks.get(key);
StorageTask task = weakReference != null ? weakReference.get() : null;
WeakReference<StorageTask<?>> weakReference = inProgressTasks.get(key);
StorageTask<?> task = weakReference != null ? weakReference.get() : null;
if (task == null || task == targetTask) {
inProgressTasks.remove(key);
}
Expand Down