00001
00004 package cast.tests;
00005
00006 import cast.AlreadyExistsOnWMException;
00007 import cast.architecture.ManagedComponent;
00008 import cast.cdl.TestStructInt;
00009
00017 public class DirectAccessWriter extends ManagedComponent {
00018
00019 private enum WriterBehaviour {
00020 CHECK, ALTER
00021 };
00022
00023 private WriterBehaviour m_behaviour = WriterBehaviour.ALTER;
00024
00025 @Override
00026 protected void runComponent() {
00027
00028 try {
00029
00030 int startingValue = 0;
00031 TestStructInt tsi = new TestStructInt(startingValue);
00032
00033
00034 addToWorkingMemory(newDataID(), tsi);
00035
00036 while (isRunning()) {
00037
00038 if (m_behaviour == WriterBehaviour.CHECK) {
00039
00040 if (tsi.dummy != startingValue) {
00041 throw new RuntimeException("Value has changed");
00042 } else {
00043 println("fine");
00044 }
00045 } else if (m_behaviour == WriterBehaviour.ALTER) {
00046
00047 tsi.dummy++;
00048 println("altered: " + tsi.dummy);
00049 }
00050
00051 sleepComponent(1000);
00052 }
00053
00054 } catch (AlreadyExistsOnWMException e) {
00055 logException(e);
00056 }
00057
00058 }
00059
00060 }