Search in sources :

Example 1 with MemoryArea

use of javax.realtime.MemoryArea 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();
        }
    });
}
Also used : LTMemory(javax.realtime.LTMemory) PrivateMemory(javax.safetycritical.PrivateMemory) ScopedMemory(javax.realtime.ScopedMemory) MemoryArea(javax.realtime.MemoryArea)

Aggregations

LTMemory (javax.realtime.LTMemory)1 MemoryArea (javax.realtime.MemoryArea)1 ScopedMemory (javax.realtime.ScopedMemory)1 PrivateMemory (javax.safetycritical.PrivateMemory)1