00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00026 package cast.architecture;
00027
00028 import java.util.Queue;
00029 import java.util.concurrent.ConcurrentLinkedQueue;
00030
00031 import cast.cdl.TaskManagementDecision;
00032 import cast.cdl.TaskOutcome;
00033 import cast.core.Pair;
00034
00038 public class AlwaysPositiveTaskManager extends SubarchitectureTaskManager {
00039
00040 @Override
00041 protected void taskCompleted(String _component, String _taskID,
00042 TaskOutcome _data) {
00043
00044 }
00045
00046 @Override
00047 protected void taskProposed(String _component, String _taskID,
00048 String _taskName) {
00049 if (m_goalQueue == null) {
00050 m_goalQueue = new ConcurrentLinkedQueue<Pair<String, String>>();
00051 }
00052 m_goalQueue.add(new Pair<String, String>(_component, _taskID));
00053 }
00054
00055 @Override
00056 protected void taskRetracted(String _component, String _taskID) {
00057 for (Pair<String, String> task : m_goalQueue) {
00058 if (task.m_second.equals(_taskID)) {
00059 m_goalQueue.remove(task);
00060 return;
00061 }
00062 }
00063 }
00064
00065 private Queue<Pair<String, String>> m_goalQueue;
00066
00070 public AlwaysPositiveTaskManager() {
00071 receiveNoChanges();
00072 }
00073
00074 protected void processTaskQueue() {
00075 while (!m_goalQueue.isEmpty()) {
00076 Pair<String, String> task = m_goalQueue.poll();
00077 sendTaskDecision(task.m_first, task.m_second,
00078 TaskManagementDecision.TaskAdopted);
00079 }
00080 }
00081
00082 @Override
00083 protected void stop() {
00084 if(m_goalQueue != null) {
00085 m_goalQueue.clear();
00086 }
00087
00088 synchronized (m_proposalLock) {
00089 m_proposalLock.notifyAll();
00090 }
00091 }
00092
00093 @Override
00094 public void runComponent() {
00095
00096 while (isRunning()) {
00097
00098
00099 if (m_goalQueue != null) {
00100 lockComponent();
00101 processTaskQueue();
00102 unlockComponent();
00103 }
00104
00105 waitForProposals();
00106 }
00107
00108 }
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127 }