Search in sources :

Example 1 with TaskSequence

use of org.apache.pivot.util.concurrent.TaskSequence in project pivot by apache.

the class TaskTest method testTaskSequence.

@Test
public void testTaskSequence() {
    TaskListener<Void> taskListener = new TaskListener<Void>() {

        @Override
        public synchronized void taskExecuted(Task<Void> task) {
            System.out.println("EXECUTED");
            notify();
        }

        @Override
        public synchronized void executeFailed(Task<Void> task) {
            System.out.println("FAILED: " + task.getFault());
            notify();
        }
    };
    TaskSequence taskSequence = new TaskSequence();
    SleepTask task1 = new SleepTask(500);
    taskSequence.add(task1);
    SleepTask task2 = new SleepTask(1000);
    taskSequence.add(task2);
    SleepTask task3 = new SleepTask(2000);
    taskSequence.add(task3);
    synchronized (taskListener) {
        taskSequence.execute(taskListener);
        try {
            taskListener.wait();
        } catch (InterruptedException exception) {
        // empty block
        }
    }
}
Also used : Task(org.apache.pivot.util.concurrent.Task) TaskSequence(org.apache.pivot.util.concurrent.TaskSequence) TaskListener(org.apache.pivot.util.concurrent.TaskListener) Test(org.junit.Test)

Aggregations

Task (org.apache.pivot.util.concurrent.Task)1 TaskListener (org.apache.pivot.util.concurrent.TaskListener)1 TaskSequence (org.apache.pivot.util.concurrent.TaskSequence)1 Test (org.junit.Test)1