Search in sources :

Example 36 with BEvent

use of il.ac.bgu.cs.bp.bpjs.model.BEvent in project BPjs by bThink-BGU.

the class BProgramSyncSnapshotIO method deserialize.

public BProgramSyncSnapshot deserialize(byte[] bytes) throws IOException, ClassNotFoundException {
    try {
        Context ctxt = ContextFactory.getGlobal().enterContext();
        // must use interpreter mode
        ctxt.setOptimizationLevel(-1);
        final ScriptableObject globalScope = ctxt.initStandardObjects();
        try (ScriptableInputStream sis = new ScriptableInputStream(new ByteArrayInputStream(bytes), globalScope)) {
            Header header = (Header) sis.readObject();
            Set<BThreadSyncSnapshot> bthreads = new HashSet<>(header.bthreadCount);
            for (int i = 0; i < header.bthreadCount; i++) {
                bthreads.add(readBThreadSnapshot(sis, globalScope));
            }
            List<BEvent> events = new ArrayList<>(header.externalEventCount);
            for (int i = 0; i < header.externalEventCount; i++) {
                events.add((BEvent) sis.readObject());
            }
            return new BProgramSyncSnapshot(bprogram, bthreads, events, header.fa);
        }
    } finally {
        Context.exit();
    }
}
Also used : Context(org.mozilla.javascript.Context) ScriptableObject(org.mozilla.javascript.ScriptableObject) ScriptableInputStream(org.mozilla.javascript.serialize.ScriptableInputStream) ArrayList(java.util.ArrayList) ByteArrayInputStream(java.io.ByteArrayInputStream) BEvent(il.ac.bgu.cs.bp.bpjs.model.BEvent) BProgramSyncSnapshot(il.ac.bgu.cs.bp.bpjs.model.BProgramSyncSnapshot) BThreadSyncSnapshot(il.ac.bgu.cs.bp.bpjs.model.BThreadSyncSnapshot) HashSet(java.util.HashSet)

Example 37 with BEvent

use of il.ac.bgu.cs.bp.bpjs.model.BEvent in project BPjs by bThink-BGU.

the class BProgramSyncSnapshotIO method serialize.

public byte[] serialize(BProgramSyncSnapshot bpss) throws IOException {
    try {
        // need Javascript environment for
        Context ctxt = Context.enter();
        // this, even though we're not
        // executing code per se.
        final ScriptableObject globalScope = ctxt.initStandardObjects();
        try (ByteArrayOutputStream bytes = new ByteArrayOutputStream();
            ObjectOutputStream outs = new ObjectOutputStream(bytes)) {
            outs.writeObject(new Header(bpss.getBThreadSnapshots().size(), bpss.getExternalEvents().size(), bpss.getFailedAssertion()));
            for (BThreadSyncSnapshot bss : bpss.getBThreadSnapshots()) {
                writeBThreadSnapshot(bss, outs, globalScope);
            }
            for (BEvent ee : bpss.getExternalEvents()) {
                outs.writeObject(ee);
            }
            outs.flush();
            return bytes.toByteArray();
        }
    } finally {
        Context.exit();
    }
}
Also used : Context(org.mozilla.javascript.Context) ScriptableObject(org.mozilla.javascript.ScriptableObject) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BEvent(il.ac.bgu.cs.bp.bpjs.model.BEvent) ObjectOutputStream(java.io.ObjectOutputStream) BThreadSyncSnapshot(il.ac.bgu.cs.bp.bpjs.model.BThreadSyncSnapshot)

Aggregations

BEvent (il.ac.bgu.cs.bp.bpjs.model.BEvent)37 Test (org.junit.Test)25 SingleResourceBProgram (il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram)16 BProgramRunner (il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner)13 InMemoryEventLoggingListener (il.ac.bgu.cs.bp.bpjs.execution.listeners.InMemoryEventLoggingListener)13 PrintBProgramRunnerListener (il.ac.bgu.cs.bp.bpjs.execution.listeners.PrintBProgramRunnerListener)13 BSyncStatement (il.ac.bgu.cs.bp.bpjs.model.BSyncStatement)9 EventPattern (il.ac.bgu.cs.bp.bpjs.analysis.eventpattern.EventPattern)8 BProgram (il.ac.bgu.cs.bp.bpjs.model.BProgram)8 BThreadSyncSnapshot (il.ac.bgu.cs.bp.bpjs.model.BThreadSyncSnapshot)7 StringBProgram (il.ac.bgu.cs.bp.bpjs.model.StringBProgram)6 Context (org.mozilla.javascript.Context)6 BProgramSyncSnapshot (il.ac.bgu.cs.bp.bpjs.model.BProgramSyncSnapshot)5 EventSet (il.ac.bgu.cs.bp.bpjs.model.eventsets.EventSet)5 HashSet (java.util.HashSet)5 List (java.util.List)5 Set (java.util.Set)5 ComposableEventSet (il.ac.bgu.cs.bp.bpjs.model.eventsets.ComposableEventSet)4 EventSets (il.ac.bgu.cs.bp.bpjs.model.eventsets.EventSets)4 Collections.emptySet (java.util.Collections.emptySet)4