Search in sources :

Example 11 with BSyncStatement

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

the class BProgramSyncSnapshotIO method readBThreadSnapshot.

private BThreadSyncSnapshot readBThreadSnapshot(ScriptableInputStream sis, ScriptableObject scope) throws IOException, ClassNotFoundException {
    String name = (String) sis.readObject();
    byte[] contBytes = (byte[]) sis.readObject();
    final BThreadJsProxy btProxy = new BThreadJsProxy();
    final BProgramJsProxy bpProxy = new BProgramJsProxy(bprogram);
    StubProvider stubPrv = (StreamObjectStub stub) -> {
        if (stub == StreamObjectStub.BP_PROXY) {
            return bpProxy;
        }
        if (stub == StreamObjectStub.BT_PROXY) {
            return btProxy;
        }
        throw new IllegalArgumentException("Unknown stub " + stub);
    };
    try (ByteArrayInputStream inBytes = new ByteArrayInputStream(contBytes);
        BThreadSyncSnapshotInputStream bssis = new BThreadSyncSnapshotInputStream(inBytes, scope, stubPrv)) {
        Scriptable btScope = (Scriptable) bssis.readObject();
        Function entryPoint = (Function) bssis.readObject();
        Function interruptHandler = (Function) bssis.readObject();
        BSyncStatement stmt = (BSyncStatement) bssis.readObject();
        Object cont = bssis.readObject();
        final BThreadSyncSnapshot bThreadSyncSnapshot = new BThreadSyncSnapshot(name, entryPoint, interruptHandler, btScope, cont, stmt);
        btProxy.setBThread(bThreadSyncSnapshot);
        return bThreadSyncSnapshot;
    }
}
Also used : BSyncStatement(il.ac.bgu.cs.bp.bpjs.model.BSyncStatement) BThreadJsProxy(il.ac.bgu.cs.bp.bpjs.execution.jsproxy.BThreadJsProxy) Scriptable(org.mozilla.javascript.Scriptable) BProgramJsProxy(il.ac.bgu.cs.bp.bpjs.execution.jsproxy.BProgramJsProxy) Function(org.mozilla.javascript.Function) ByteArrayInputStream(java.io.ByteArrayInputStream) ScriptableObject(org.mozilla.javascript.ScriptableObject) BThreadSyncSnapshot(il.ac.bgu.cs.bp.bpjs.model.BThreadSyncSnapshot)

Aggregations

BSyncStatement (il.ac.bgu.cs.bp.bpjs.model.BSyncStatement)11 BEvent (il.ac.bgu.cs.bp.bpjs.model.BEvent)9 ComposableEventSet (il.ac.bgu.cs.bp.bpjs.model.eventsets.ComposableEventSet)4 EventSet (il.ac.bgu.cs.bp.bpjs.model.eventsets.EventSet)4 EventSets (il.ac.bgu.cs.bp.bpjs.model.eventsets.EventSets)4 Collections.emptySet (java.util.Collections.emptySet)4 Collections.singleton (java.util.Collections.singleton)4 List (java.util.List)4 Set (java.util.Set)4 Collectors.toSet (java.util.stream.Collectors.toSet)4 HashSet (java.util.HashSet)3 Map (java.util.Map)3 Test (org.junit.Test)3 Context (org.mozilla.javascript.Context)3 Collectors (java.util.stream.Collectors)2 NativeArray (org.mozilla.javascript.NativeArray)2 NativeObject (org.mozilla.javascript.NativeObject)2 BProgramJsProxy (il.ac.bgu.cs.bp.bpjs.execution.jsproxy.BProgramJsProxy)1 BThreadJsProxy (il.ac.bgu.cs.bp.bpjs.execution.jsproxy.BThreadJsProxy)1 BThreadSyncSnapshot (il.ac.bgu.cs.bp.bpjs.model.BThreadSyncSnapshot)1