Search in sources :

Example 1 with Task

use of edu.iu.dsc.tws.executor.model.Task in project twister2 by DSC-SPIDAL.

the class BlockQueueMain method main.

public static void main(String[] args) throws InterruptedException {
    BlockingQueue q1 = new PriorityBlockingQueue();
    BlockingQueue q = new ArrayBlockingQueue(5);
    Task task1 = new Task(1001, "Task 1", new Date(), "scripts/task_scripts/run-task1.sh", "Thread 1");
    Task task2 = new Task(1002, "Task 2", new Date(), "scripts/task_scripts/run-task2.sh", "Thread 1");
    Task task3 = new Task(1003, "Task 3", new Date(), "scripts/task_scripts/run-task3.sh", "Thread 1");
    Task task4 = new Task(1004, "Task 4", new Date(), "scripts/task_scripts/run-task4.sh", "Thread 1");
    Task task5 = new Task(1005, "Task 5", new Date(), "scripts/task_scripts/run-task5.sh", "Thread 1");
    ArrayList<Task> taskArrayList = new ArrayList<>();
    taskArrayList.add(task1);
    taskArrayList.add(task2);
    taskArrayList.add(task3);
    taskArrayList.add(task4);
    taskArrayList.add(task5);
    // Demo Pub/Sup BlockingQueue
    /*Producer p = new Producer(q);
    Consumer c1 = new Consumer(q);
    Consumer c2 = new Consumer(q);
    Thread t = new Thread(p);
    t.start();

    Thread t1 = new Thread(c1);
    t1.start();


    System.out.println("Consumer : "+t1.getState());
    System.out.println("Producer : "+t.getState());
*/
    // Producing and Consuming real resources
    /*Producer p = new Producer(q, task1);
    Consumer c1 = new Consumer(q);
    Consumer c2 = new Consumer(q);
    Thread t = new Thread(p);
    t.start();

    Thread t1 = new Thread(c1);
    t1.start();


    System.out.println("Consumer : "+t1.getState());
    System.out.println("Producer : "+t.getState());
*/
    // consuming list of tasks
    StaticProducer p = new StaticProducer(q, taskArrayList, TaskOps.LIST);
    p.create();
    q = p.getQueue();
    System.out.println("Generated Queue : " + q.size());
    Consumer c1 = new Consumer(q, TaskOps.LIST);
    // Consumer c2 = new Consumer(q, TaskOps.LIST);
    Thread t1 = new Thread(c1);
    t1.start();
    System.out.println("Consumer : " + t1.getState());
}
Also used : ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) BlockingQueue(java.util.concurrent.BlockingQueue) PriorityBlockingQueue(java.util.concurrent.PriorityBlockingQueue) Task(edu.iu.dsc.tws.executor.model.Task) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) ArrayList(java.util.ArrayList) PriorityBlockingQueue(java.util.concurrent.PriorityBlockingQueue) Date(java.util.Date)

Example 2 with Task

use of edu.iu.dsc.tws.executor.model.Task in project twister2 by DSC-SPIDAL.

the class Producer method run.

public void run() {
    try {
        if (executableType == TaskOps.SINGLE) {
            // queue.put(produce("Process : "+i+" - "+"Task Descriptor : "+i));
            queue.put(produceTask(this.task));
        }
        if (executableType == TaskOps.LIST) {
            int i = 0;
            for (Task task : taskList) {
                System.out.println("Task " + i + " executing");
                queue.put(produceTask(task));
                i++;
            }
        }
        if (executableType == TaskOps.CONTINUES) {
        }
    } catch (InterruptedException ex) {
        System.err.println(ex.getMessage());
    }
}
Also used : Task(edu.iu.dsc.tws.executor.model.Task)

Example 3 with Task

use of edu.iu.dsc.tws.executor.model.Task in project twister2 by DSC-SPIDAL.

the class StaticProducer method create.

public void create() throws InterruptedException {
    if (executableType == TaskOps.SINGLE) {
        // queue.put(produce("Process : "+i+" - "+"Task Descriptor : "+i));
        queue.put(produceTask(this.task));
    }
    if (executableType == TaskOps.LIST) {
        int i = 0;
        for (Task task : taskList) {
            System.out.println("Task " + i + " executing");
            queue.put(produceTask(task));
            i++;
        }
    }
    if (executableType == TaskOps.CONTINUES) {
    }
}
Also used : Task(edu.iu.dsc.tws.executor.model.Task)

Example 4 with Task

use of edu.iu.dsc.tws.executor.model.Task in project twister2 by DSC-SPIDAL.

the class TaskManager method run.

@Override
public void run() {
    System.out.println("Running Task Manager : Thread Id = " + this.threadId);
    taskHandler.addTask(new Task(1000, "Task 1", new Date(), "Demo Task 1 to handle the queue", threadId));
// taskHandler.addTask(new Task(1002,"Task 2", new Date(), "Demo Task 2 to handle the queue",threadId));
// taskHandler.addTask(new Task(1003,"Task 3", new Date(), "Demo Task 3 to handle the queue",threadId));
}
Also used : Task(edu.iu.dsc.tws.executor.model.Task) Date(java.util.Date)

Aggregations

Task (edu.iu.dsc.tws.executor.model.Task)4 Date (java.util.Date)2 ArrayList (java.util.ArrayList)1 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)1 BlockingQueue (java.util.concurrent.BlockingQueue)1 PriorityBlockingQueue (java.util.concurrent.PriorityBlockingQueue)1