use of javax.realtime.ScopedMemory in project jop by jop-devel.
the class TestMemory501 method getSequencer.
public MissionSequencer getSequencer() {
return new GeneralSingleMissionSequencer(new GeneralMission() {
private int _depth;
@Override
public void initialize() {
final MemoryArea missionMem = RealtimeThread.getCurrentMemoryArea();
if (!(missionMem instanceof ScopedMemory)) {
fail("Mission memory is not instance of ScopedMemory");
}
new GeneralPeriodicEventHandler() {
@Override
public void handleAsyncEvent() {
MemoryArea privateMem = RealtimeThread.getCurrentMemoryArea();
if (!(privateMem instanceof PrivateMemory))
fail("Schedulable objects not run in private memory");
if (!(privateMem instanceof ScopedMemory))
fail("Private memory is not instance of ScopedMemory");
if (!(privateMem instanceof LTMemory))
fail("Private memory is not instance of LTMemory");
_depth = 0;
new PrivateMemory(5000).enter(new Runnable() {
public void run() {
final MissionManager mngrL1 = ((PrivateMemory) RealtimeThread.getCurrentMemoryArea()).getManager();
new PrivateMemory(5000).enter(new Runnable() {
public void run() {
MissionManager mngrL2 = ((PrivateMemory) RealtimeThread.getCurrentMemoryArea()).getManager();
if (!mngrL1.equals(mngrL2))
fail("Error occured in PrivateMemory.getManager()");
_depth++;
}
});
_depth++;
if (_depth != 2)
fail("Unable to enter nested private memory");
}
});
}
};
/*
* Object creation in mission scoped memory or immortal memory
* during the mission phase is allowed
*/
new GeneralPeriodicEventHandler() {
@Override
public void handleAsyncEvent() {
try {
missionMem.newInstance(Object.class);
} catch (Throwable e) {
fail("Error occured during object creation in mission memory during mission phase");
}
try {
ImmortalMemory.instance().newInstance(Object.class);
} catch (Throwable e) {
fail("Error occured during object creation in immortal memory during mission phase");
}
}
};
/*
* A scope may only be entered from the memory area in which it
* is created
*/
final PrivateMemory scopeL1 = new PrivateMemory(5000);
final PrivateMemory scopeL2 = new PrivateMemory(5000);
new GeneralPeriodicEventHandler() {
@Override
public void handleAsyncEvent() {
scopeL1.enter(new Runnable() {
public void run() {
try {
scopeL2.enter(new Runnable() {
public void run() {
fail("Private memory not entered from its parent scope");
}
});
} catch (Throwable t) {
/*
* scopeL2 is not allowed to be entered in
* scopeL1; there should be some exceptions
* thrown here
*/
}
}
});
}
};
/*
* A mission global object, which should be able to be touched
* by PEHs
*/
final int nValueReaders = 3;
final int value = 42;
final Integer missionGlobalNum = new Integer(value);
for (int i = 0; i < nValueReaders; i++) new GeneralPeriodicEventHandler() {
@Override
public void handleAsyncEvent() {
if (missionGlobalNum.intValue() != value) {
fail("Mission global object inaccessible or incorrect");
}
}
};
new Terminator();
}
});
}
use of javax.realtime.ScopedMemory in project jop by jop-devel.
the class SimpleScope method main.
/**
* @param args
*/
public static void main(String[] args) {
final ScopedMemory scope = new LTMemory(20000L);
final ScopedMemory inner = new LTMemory(10000L);
final Runnable run = new Runnable() {
public void run() {
MyRunner r = new MyRunner();
for (int i = 0; i < 10; ++i) {
Abc abc = new Abc();
r.setAbc(abc);
r.setOuter(scope);
for (int j = 0; j < 10; ++j) {
inner.enter(r);
}
}
}
};
System.out.println("some new");
new RtThread(10, 500000) {
public void run() {
for (; ; ) {
for (int i = 0; i < 20; ++i) {
System.out.print("*");
scope.enter(run);
// this is a dangling reference
// sa.ref.toString();
}
waitForNextPeriod();
}
}
};
System.out.println("start mission");
RtThread.startMission();
System.out.println("mission started");
}
Aggregations