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.HashMap;
00029
00030 import Ice.Current;
00031 import cast.cdl.TaskManagementDecision;
00032 import cast.cdl.TaskOutcome;
00033 import cast.interfaces.ManagedComponentPrx;
00034 import cast.interfaces._TaskManagerOperations;
00035
00042 public abstract class SubarchitectureTaskManager extends
00043 WorkingMemoryReaderComponent implements _TaskManagerOperations {
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00153 protected Object m_proposalLock;
00154
00155 protected Object m_completionLock;
00156
00157 protected final HashMap<String, ManagedComponentPrx> m_components;
00158
00163 public SubarchitectureTaskManager() {
00164 m_proposalLock = new Object();
00165 m_completionLock = new Object();
00166 m_components = new HashMap<String, ManagedComponentPrx>();
00167 }
00168
00169 @Override
00170 public void stopInternal() {
00171 super.stopInternal();
00172
00173 synchronized (m_proposalLock) {
00174 m_proposalLock.notifyAll();
00175 }
00176
00177 synchronized (m_completionLock) {
00178 m_completionLock.notifyAll();
00179 }
00180 }
00181
00182
00191 protected void sendTaskDecision(String _component, String _taskID,
00192 TaskManagementDecision _decision) {
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220 ManagedComponentPrx prx = m_components.get(_component);
00221 assert(prx != null);
00222
00223 prx.taskDecision(_taskID, _decision);
00224
00225 debug("sent decision: " + _taskID);
00226 }
00227
00236 protected abstract void taskCompleted(String _component, String _taskID, TaskOutcome _data);
00237
00246 protected abstract void taskProposed(String _component,
00247 String _taskID, String _taskName);
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00267 protected abstract void taskRetracted(String _component, String _taskID);
00268
00269
00275 protected void waitForProposals() {
00276 synchronized (m_proposalLock) {
00277 try {
00278 m_proposalLock.wait();
00279 } catch (InterruptedException e) {
00280 e.printStackTrace();
00281 System.exit(1);
00282 }
00283 }
00284 }
00285
00290 protected void waitForCompletions() {
00291 synchronized (m_completionLock) {
00292 try {
00293 m_completionLock.wait();
00294 } catch (InterruptedException e) {
00295 e.printStackTrace();
00296 System.exit(1);
00297 }
00298 }
00299 }
00300
00301 public void proposeTask(String _component, String _taskID,
00302 String _taskName, Current __current) {
00303 lockComponent();
00304
00305 taskProposed(_component, _taskID, _taskName);
00306 unlockComponent();
00307
00308 synchronized (m_proposalLock) {
00309 m_proposalLock.notifyAll();
00310 }
00311 }
00312
00313 public void retractTask(String _component, String _taskID, Current __current) {
00314 lockComponent();
00315 taskRetracted(_component,_taskID);
00316 unlockComponent();
00317
00318 synchronized (m_proposalLock) {
00319 m_proposalLock.notifyAll();
00320 }
00321 }
00322
00323 public void taskComplete(String _component, String _taskID, TaskOutcome _outcome,
00324 Current __current) {
00325 lockComponent();
00326
00327 taskCompleted(_component, _taskID, _outcome);
00328 unlockComponent();
00329
00330
00331
00332 synchronized (m_completionLock) {
00333 m_completionLock.notifyAll();
00334 }
00335 }
00336
00337 public void addManagedComponent(ManagedComponentPrx _comp, Current __current) {
00338 m_components.put(_comp.getID(), _comp);
00339 }
00340
00341
00342 }