Class BProgramJsProxy
java.lang.Object
il.ac.bgu.cs.bp.bpjs.execution.jsproxy.SyncStatementBuilder
il.ac.bgu.cs.bp.bpjs.execution.jsproxy.BProgramJsProxy
- All Implemented Interfaces:
Serializable
An object representing the
BProgram
context for JavaScript code.
Methods in this object allow JavaScript code to register new BThreads,
create events,write messages to the log etc.
Methods in the class are available to JavaScript code via the bp
object, like so:
bp.log.info("I'm a log message!");
var myEvent = bp.Event("My Event");
bp.registerBThread(...);
- Author:
- michael
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
State of a b-thread, captures during a bp.sync. -
Field Summary
FieldsModifier and TypeFieldDescriptionfinal EventSet
Deprecated, for removal: This API element is subject to removal in a future version.final EventSetsJsProxy
final BpLog
final EventSet
Deprecated, for removal: This API element is subject to removal in a future version.Facility for creating random numbers. -
Constructor Summary
ConstructorsConstructorDescriptionBProgramJsProxy
(BProgram aBProgram) BProgramJsProxy
(BProgram aBProgram, BpLog log) -
Method Summary
Modifier and TypeMethodDescriptionvoid
Ifvalue
isfalse
, puts the entire program in an invalid state.static void
protected EventSet
convertToEventSet
(Object jsObject) Push a new event to the external event queue.boolean
Proxies contain no state of their own, and provide a gateway to the Java environment the BProgram runs in.Event constructor, called from JavaScript, hence the funny capitalization.Event constructor, called from JavaScript, hence the funny capitalization.void
fork()
static MapProxy
Gets the name of the Java thread executing this b-thread at the moment.getStore()
long
getTime()
int
hashCode()
hot
(boolean isHot) boolean
void
registerBThread
(String name, Object data, org.mozilla.javascript.Function func) Called from JS to add BThreads with data.void
registerBThread
(String name, org.mozilla.javascript.Function func) Called from JS to add BThreads running function as their runnable code.void
registerBThread
(org.mozilla.javascript.Function func) Registers a BThread and gives it a unique name.static void
setCurrentBThread
(BProgramSyncSnapshot bpss, BThreadSyncSnapshot btss) void
setInterruptHandler
(Object aPossibleHandler) void
setWaitForExternalEvents
(boolean newDaemonMode) Sets whether the BProgram will wait for external events when there's no internal event to choose.void
protected void
synchronizationPoint
(org.mozilla.javascript.NativeObject jsRWB, Boolean hot, Object data) Where the actual Behavioral Programming synchronization point is done.Methods inherited from class il.ac.bgu.cs.bp.bpjs.execution.jsproxy.SyncStatementBuilder
sync
-
Field Details
-
log
-
all
Deprecated, for removal: This API element is subject to removal in a future version.Deprecated - use eventSets.all -
none
Deprecated, for removal: This API element is subject to removal in a future version.Deprecated - use eventSets.none -
eventSets
-
random
Facility for creating random numbers. BPjs code should not use JavaScript's random facility, as it won't play well with model checking.
-
-
Constructor Details
-
BProgramJsProxy
-
BProgramJsProxy
-
-
Method Details
-
setCurrentBThread
-
clearCurrentBThread
public static void clearCurrentBThread() -
getCurrentChanges
-
Event
Event constructor, called from JavaScript, hence the funny capitalization.- Parameters:
name
- name of the event- Returns:
- an event with the passed name.
-
Event
Event constructor, called from JavaScript, hence the funny capitalization.- Parameters:
name
- name of the eventjsData
- Additional data for the object.- Returns:
- an event with the passed name.
-
EventSet
-
allExcept
-
registerBThread
Called from JS to add BThreads with data.- Parameters:
name
- Name of the registered BThread (useful for debugging).data
- Data object for the b-thread.func
- Script entry point of the BThread.- See Also:
-
registerBThread
Called from JS to add BThreads running function as their runnable code.- Parameters:
name
- Name of the registered BThread (useful for debugging).func
- Script entry point of the BThread.- See Also:
-
registerBThread
public void registerBThread(org.mozilla.javascript.Function func) Registers a BThread and gives it a unique name. Use when you don't care about the added BThread's name.- Parameters:
func
- the BThread to add.- See Also:
-
ASSERT
Ifvalue
isfalse
, puts the entire program in an invalid state. This, in turn, would terminate it when it's being run, or discover a specification violation when it's being verified.note: I'd rather call it
assert
too, but that's a Java keyword, which complicates stuff.- Parameters:
value
- The value of the assertion. Whenfalse
, the program is declared in invalid state.message
- Textual information about what caused the violation.- Throws:
FailedAssertionException
- ifvalue
is false.
-
fork
public void fork() throws org.mozilla.javascript.ContinuationPending- Throws:
org.mozilla.javascript.ContinuationPending
-
setInterruptHandler
-
sync
- Specified by:
sync
in classSyncStatementBuilder
-
hot
- Specified by:
hot
in classSyncStatementBuilder
-
synchronizationPoint
protected void synchronizationPoint(org.mozilla.javascript.NativeObject jsRWB, Boolean hot, Object data) Where the actual Behavioral Programming synchronization point is done.- Parameters:
jsRWB
- The JavaScript object{request:... waitFor:...}
hot
-True
if this should be a "hot" synchronization point.data
- Optional extra data the synchronizing b-thread may want to add.
-
convertToEventSet
-
enqueueExternalEvent
Push a new event to the external event queue.- Parameters:
evt
- The event to be pushed.- Returns:
- the event being pushed.
-
setWaitForExternalEvents
public void setWaitForExternalEvents(boolean newDaemonMode) Sets whether the BProgram will wait for external events when there's no internal event to choose.- Parameters:
newDaemonMode
-true
for makingthis
a daemon;false
otherwise.
-
isWaitForExternalEvents
public boolean isWaitForExternalEvents() -
getTime
public long getTime()- Returns:
- Returns the current time in milliseconds since 1/1/1970.
-
getThread
-
getStore
-
getJavaThreadName
Gets the name of the Java thread executing this b-thread at the moment. Useful for debugging Java runtime issues.- Returns:
- the name of the Java thread executing this b-thread at the moment.
-
hashCode
public int hashCode() -
equals
Proxies contain no state of their own, and provide a gateway to the Java environment the BProgram runs in. When comparing sync snapshots, we can encounter JS proxies when traversing the JS heap and stack. To prevent leaking the equality evaluation outside of the JavaScript, we do not check the equality of theBProgram
this
is a proxy of. Rather, we just check that the other object is a proxy too.
-