Example usage for com.badlogic.gdx.utils DelayedRemovalArray DelayedRemovalArray

List of usage examples for com.badlogic.gdx.utils DelayedRemovalArray DelayedRemovalArray

Introduction

In this page you can find the example usage for com.badlogic.gdx.utils DelayedRemovalArray DelayedRemovalArray.

Prototype

public DelayedRemovalArray(T[] array) 

Source Link

Usage

From source file:es.eucm.ead.editor.control.workers.WorkerExecutor.java

License:Open Source License

/**
 * Starts a worker and cancels any other worker of the same class
 *///from   ww  w  . j a  v  a 2s.  c o m
public <T extends Worker> void execute(Class<T> workerClass, WorkerListener workerListener,
        boolean cancelOthers, Object... args) {
    try {
        DelayedRemovalArray<Worker> workers = workersMap.get(workerClass);
        if (workers == null) {
            workers = new DelayedRemovalArray<Worker>(1);
            workersMap.put(workerClass, workers);
        }
        if (cancelOthers) {
            for (Worker worker : workers) {
                if (!worker.isDone()) {
                    worker.cancel();
                }
            }
        }
        Worker worker = workerClass.newInstance();
        worker.setController(controller);
        worker.setListener(workerListener);
        worker.setArguments(args);

        workers.add(worker);

        executorService.submit(worker);
        for (WorkerExecutorListener listener : listeners) {
            listener.executed(workerClass, worker.getListener());
        }
    } catch (Exception e) {
        Gdx.app.error("WorkerExecutor", "Error submitting worker", e);
    }
}