/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package simizer.processor.tasks;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import simizer.VM;
import simizer.processor.ProcessingUnit;

/**
 * This class is used for figuring a process. 
 * It is a composition of tasks, that is passed to the processing unit for execution.
 * Tasks in the TaskSession are executed in order by the processing unit,
 * by by successive calls to getNextTask();
 * @see VM
 * @see ProcessingUnit
 * 
 * @author Sylvain Lefebvre
 */
public class TaskSession {
    private int sessionId;
    private final Queue<Task> taskList = new LinkedList<Task>();
    private final List<Integer> resList = new ArrayList<>();
    private Task currentTask;
    private boolean complete=false;
    
    public TaskSession(int sesId) {
        this.sessionId = sesId;
    
    } 
    public void addResource(Integer rId) {
        resList.add(rId);
    }
    public List<Integer> getResourceList() {
        return this.resList;
    }
    public int getNbTasks() {
        return taskList.size();
    }
    
    public Task getCurrentTask() {
        return  this.currentTask;
    }
    public void addTask(Task t) {
        
        t.setTaskSession(this);
        taskList.add(t);
    }
    public Task getNextTask() {
        currentTask = taskList.poll();
        return currentTask;
    }
    /**
     * 
     * @return true if the task session is complete
     */
    public boolean isComplete() {
        return (taskList.size() == 0);
        
    }
    public int getSessionId() {
        return this.sessionId;
    }
    /**
     * Prints out the task list, for debugging purpose
     */ 
//    public void printTaskSession() {
//        for(Task t: this.taskList) {
//            System.out.println(t.getClass().toString());
//        }
//    }
}

@@ -1,104 +1,4 @@
-/*%0A * To change this template, choose Tools %7C Templates%0A * and open the template in the editor.%0A */%0A
 pack
@@ -242,20 +242,16 @@
 rocess. 
-%0A * 
 It is a 
@@ -276,16 +276,19 @@
 ks, that
+%0A *
  is pass
@@ -327,19 +327,16 @@
 ecution.
-%0A *
  Tasks i
@@ -356,16 +356,19 @@
 sion are
+%0A *
  execute
@@ -401,19 +401,16 @@
 ng unit,
-%0A *
  by by s
@@ -427,16 +427,19 @@
 calls to
+%0A *
  getNext
@@ -446,16 +446,19 @@
 Task();%0A
+ *%0A
  * @see 
@@ -485,17 +485,16 @@
 gUnit%0A *
- 
 %0A * @aut
@@ -545,18 +545,17 @@
 ssion %7B%0A
-  
+%0A
   privat
@@ -571,18 +571,16 @@
 sionId;%0A
-  
   privat
@@ -629,19 +629,13 @@
 ist%3C
-Task
 %3E();%0A
-  
   pr
@@ -689,18 +689,16 @@
 st%3C%3E();%0A
-  
   privat
@@ -721,51 +721,9 @@
 sk;%0A
-    private boolean complete=false;%0A    %0A  
+%0A
   pu
@@ -748,28 +748,24 @@
 nt sesId) %7B%0A
-    
     this.ses
@@ -786,20 +786,11 @@
 ;%0A  
-  %0A    %7D %0A  
+%7D%0A%0A
   pu
@@ -822,28 +822,24 @@
 eger rId) %7B%0A
-    
     resList.
@@ -846,30 +846,27 @@
 add(rId);%0A  
-  
 %7D
+%0A
 %0A
-  
   public Lis
@@ -892,28 +892,24 @@
 rceList() %7B%0A
-    
     return t
@@ -919,30 +919,27 @@
 .resList;%0A  
- 
- 
 %7D%0A
-  
+%0A
   public int
@@ -950,36 +950,32 @@
 NbTasks() %7B%0A    
-  
-  
 return taskList.
@@ -988,19 +988,11 @@
 ;%0A  
-  %7D%0A    %0A  
+%7D%0A%0A
   pu
@@ -1028,20 +1028,15 @@
     
-  
-  
 return 
- 
 this
@@ -1049,26 +1049,23 @@
 ntTask;%0A
-  
   %7D%0A
- 
+%0A
   
- 
 public v
@@ -1086,29 +1086,16 @@
 sk t) %7B%0A
-        %0A    
     t.se
@@ -1114,20 +1114,16 @@
 (this);%0A
-    
     task
@@ -1137,22 +1137,19 @@
 d(t);%0A  
- 
- 
 %7D%0A
-  
+%0A
   public
@@ -1174,20 +1174,16 @@
 ) %7B%0A    
-   
- 
 currentT
@@ -1205,20 +1205,16 @@
 poll();%0A
-    
     retu
@@ -1227,30 +1227,27 @@
 rentTask;%0A  
- 
- 
 %7D%0A
-  
+%0A
   /**%0A     *
@@ -1247,15 +1247,10 @@
 %0A   
- 
- * %0A  
+*%0A
    *
@@ -1302,17 +1302,13 @@
 %0A   
-  
 */%0A  
- 
- 
 publ
@@ -1333,28 +1333,24 @@
 ete() %7B%0A    
-   
- 
 return (task
@@ -1374,23 +1374,11 @@
 ;%0A  
-      %0A    %7D%0A  
+%7D%0A%0A
   pu
@@ -1407,20 +1407,16 @@
 ) %7B%0A    
- 
-   
 return t
@@ -1434,239 +1434,8 @@
 Id;%0A
-    %7D%0A    /**%0A     * Prints out the task list, for debugging purpose%0A     */ %0A//    public void printTaskSession() %7B%0A//        for(Task t: this.taskList) %7B%0A//            System.out.println(t.getClass().toString());%0A//        %7D%0A//  
   %7D%0A

Update the TaskSession class to use the GSG.