All Downloads are FREE. Search and download functionalities are using the official Maven repository.

co.arcs.groove.basking.task.DeleteFilesTask Maven / Gradle / Ivy

There is a newer version: 1.7.2
Show newest version
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;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy