co.arcs.groove.basking.task.DeleteFilesTask Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of basking Show documentation
Show all versions of basking Show documentation
Java + command-line tool for synchronising Grooveshark libraries.
package co.arcs.groove.basking.task;
import com.beust.jcommander.internal.Lists;
import com.google.common.eventbus.EventBus;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
import java.io.File;
import java.util.List;
import co.arcs.groove.basking.event.Events.DeleteFilesFinishedEvent;
import co.arcs.groove.basking.event.Events.DeleteFilesStartedEvent;
import co.arcs.groove.basking.task.BuildSyncPlanTask.SyncPlan;
import co.arcs.groove.basking.task.BuildSyncPlanTask.SyncPlan.Item;
public class DeleteFilesTask implements Task> {
private final EventBus bus;
private final List items;
private final ListeningExecutorService executor;
public DeleteFilesTask(EventBus bus, ListeningExecutorService executor, List- items) {
this.bus = bus;
this.items = items;
this.executor = executor;
}
@Override
public List
call() throws Exception {
bus.post(new DeleteFilesStartedEvent(this));
List> deleteFutures = Lists.newArrayList();
for (Item item : items) {
deleteFutures.add(executor.submit(new DeleteFileTask(bus, item.getFile())));
}
List result = Futures.allAsList(deleteFutures).get();
bus.post(new DeleteFilesFinishedEvent(this));
return result;
}
}