Skip to content

Commit

Permalink
default priorities can be changed (closes #115)
Browse files Browse the repository at this point in the history
  • Loading branch information
michbarsinai committed Feb 9, 2021
1 parent a08dbf6 commit 92738c5
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 19 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ a link to this page somewhere in the documentation/system about section.
* :sparkles: :sparkles: :tada: :sparkles: :tada: :sparkles: :rainbow: :sparkles: :sparkles: :sparkles: BPjs now uses Rhino's native continuation equality and hash code ([#116](https://github.com/bThink-BGU/BPjs/issues/116). Also, :tada: :rainbow: :sparkles:.
* :arrow_up: Scope and context creations across BPjs have been consolidated to utility methods in a new class called `BPjs`.
* :arrow_up: Event selection strategies that ignore the synchronization statement data field, issue a warning when b-threads put data there ([#151](https://github.com/bThink-BGU/BPjs/issues/151)).
* :arrow_up: Default priorities in `PrioritizedBSyncEventSelectionStrategy` and `PrioritizedBThreadsEventSelectionStrategy` can be changed ([#115](https://github.com/bThink-BGU/BPjs/issues/115) and [PR#147](https://github.com/bThink-BGU/BPjs/pull/147)).
* :arrow_up: Updated docs.
* :arrow_up: `BProgram` uses an override-able protected method to access its global scope, in case you want to intercept these calls.
* :bug: Fixed an issue that caused `toString` for JavaScript objects to crash at certain cases ([#145](https://github.com/bThink-BGU/BPjs/issues/145)).


### 2021-01

* :sparkles: `BProgramSyncSnapshot`s are serialized using a single stream, and with the b-program's original scope as a top-level scope (([#126](https://github.com/bThink-BGU/BPjs/issues/126)).
Expand All @@ -62,21 +62,21 @@ a link to this page somewhere in the documentation/system about section.
* :sparkles: Another easy event set composition/creation added: `bp.eventSets` gives access to `EventSets`, with methods such as `bp.eventSets.anyOf(...)` and `bp.eventSets.not(...)`
* :arrow_up: Logging now allows formatting, using Java's MessageFormat.
* :arrow_up: Expressive `toString` on JavaScript sets ([#135](https://github.com/bThink-BGU/BPjs/issues/135)).
* :arrow_up: Error messages when passing non-events to a synchronization statement are more informative (([#131](https://github.com/bThink-BGU/BPjs/issues/131)).
* :arrow_up: Error messages when passing non-events to a synchronization statement are more informative ([#131](https://github.com/bThink-BGU/BPjs/issues/131)).
* :arrow_up: Improved logging consistency ([#132](https://github.com/bThink-BGU/BPjs/issues/132)).
* :arrow_up: Error messages when JS event sets do not return a `Boolean` are more informative (([#138](https://github.com/bThink-BGU/BPjs/issues/138)).
* :arrow_up: BThread data documentation updated (([#134](https://github.com/bThink-BGU/BPjs/issues/134)).
* :arrow_up: BProgram storage can be updated by the b-program before b-threads run (([#129](https://github.com/bThink-BGU/BPjs/issues/129)).
* :arrow_up: Changes made to the b-program store after the last sync of a b-thread are now applied (([#130](https://github.com/bThink-BGU/BPjs/issues/130)).
* :arrow_up: Error messages when JS event sets do not return a `Boolean` are more informative ([#138](https://github.com/bThink-BGU/BPjs/issues/138)).
* :arrow_up: BThread data documentation updated ([#134](https://github.com/bThink-BGU/BPjs/issues/134)).
* :arrow_up: BProgram storage can be updated by the b-program before b-threads run ([#129](https://github.com/bThink-BGU/BPjs/issues/129)).
* :arrow_up: Changes made to the b-program store after the last sync of a b-thread are now applied ([#130](https://github.com/bThink-BGU/BPjs/issues/130)).
* :arrow_up: More tests (logger, JSProxy, ScriptableUtils, OrderedSet, JsEventSet, some event selection strategies).
* :bug: :tada: JS-semantics are applied for `equals` and `hashCode` for b-thread and b-program data (([#144](https://github.com/bThink-BGU/BPjs/issues/144)).
* :bug: :tada: JS-semantics are applied for `equals` and `hashCode` for b-thread and b-program data ([#144](https://github.com/bThink-BGU/BPjs/issues/144)).
* :bug: Fixed the note color issue in the documentation ([#137](https://github.com/bThink-BGU/BPjs/issues/137)).
* :bug: Fixed the bench marker.
* :bug: Fixes a crash when a JS event set predicate returns `null` instead of a boolean.
* :put_litter_in_its_place: Significant cleanup of the b-program I/O area.
* :put_litter_in_its_place: Significant cleanup of the event set area. Some methods moved from `ComposableEventSet` to `EventSets`.
* :put_litter_in_its_place: Some documentation updates and corrections.
* :put_litter_in_its_place: Removed extraneous dependencies from `pom.xml` (([#133](https://github.com/bThink-BGU/BPjs/issues/133)).
* :put_litter_in_its_place: Removed extraneous dependencies from `pom.xml` ([#133](https://github.com/bThink-BGU/BPjs/issues/133)).

[Earlier Changes](changelog-2020.md)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@
* @author michael
*/
public class PrioritizedBSyncEventSelectionStrategy extends AbstractEventSelectionStrategy {


private int defaultPriority = Integer.MIN_VALUE;

public PrioritizedBSyncEventSelectionStrategy(long seed) {
super(seed);
}
Expand Down Expand Up @@ -83,7 +85,7 @@ public Set<BEvent> selectableEvents(BProgramSyncSnapshot bpss) {
.collect( toSet() );
} else {
// Can't select any internal event, defer to the external, non-blocked ones.
return externalEvents.stream().filter( e->!blocked.contains(e) ) // No internal events requested, defer to externals.
return externalEvents.stream().filter( e->!blocked.contains(e) )
.findFirst().map( e->singleton(e) ).orElse(emptySet());
}
} finally {
Expand All @@ -94,8 +96,15 @@ public Set<BEvent> selectableEvents(BProgramSyncSnapshot bpss) {

private int getValue( SyncStatement stmt ) {
return (stmt.hasData() && (stmt.getData() instanceof Number))?
((Number)stmt.getData()).intValue() : Integer.MIN_VALUE;
((Number)stmt.getData()).intValue() : defaultPriority;
}

public int getDefaultPriority() {
return defaultPriority;
}

public void setDefaultPriority(int defaultPriority) {
this.defaultPriority = defaultPriority;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
*/
public class PrioritizedBThreadsEventSelectionStrategy extends AbstractEventSelectionStrategy {

public static final int DEFAULT_PRIORITY = -1;
private int defaultPriority = -1;

/** A mapping of b-thread names to their priorities. */
final private Map<String, Integer> priorities = new HashMap<>();
Expand Down Expand Up @@ -113,15 +113,23 @@ public void setPriority(String bThreadName, Integer priority) {
}

public int getPriority(String bThreadName) {
return priorities.getOrDefault(bThreadName, DEFAULT_PRIORITY);
return priorities.getOrDefault(bThreadName, defaultPriority);
}

public int getHighestPriority() {
return priorities.values().stream().mapToInt( Integer::intValue ).max().orElse(DEFAULT_PRIORITY);
return priorities.values().stream().mapToInt( Integer::intValue ).max().orElse(defaultPriority);
}

public int getLowestPriority() {
return priorities.values().stream().mapToInt( Integer::intValue ).min().orElse(DEFAULT_PRIORITY);
return priorities.values().stream().mapToInt( Integer::intValue ).min().orElse(defaultPriority);
}

public int getDefaultPriority() {
return defaultPriority;
}

public void setDefaultPriority(int defaultPriority) {
this.defaultPriority = defaultPriority;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

import org.junit.Test;

Expand All @@ -34,6 +33,21 @@ public void testSelectableEvents_noBlocking() throws InterruptedException {
);
assertEquals(new HashSet<>(Arrays.asList(EVT_2, EVT_3)), sut.selectableEvents(bpss));
}

@Test
public void testSelectableEvents_changedPriority() throws InterruptedException {
PrioritizedBSyncEventSelectionStrategy sut = new PrioritizedBSyncEventSelectionStrategy();
sut.setDefaultPriority(11);

BProgramSyncSnapshot bpss = TestUtils.makeBPSS(
new MockBThreadSyncSnapshot(SyncStatement.make().request(Arrays.asList(EVT_4))),
new MockBThreadSyncSnapshot(SyncStatement.make().request(Arrays.asList(EVT_1)).data(5)),
new MockBThreadSyncSnapshot(SyncStatement.make().request(Arrays.asList(EVT_2)).data(10)),
new MockBThreadSyncSnapshot(SyncStatement.make().request(Arrays.asList(EVT_3)).data(10))
);
assertEquals(new HashSet<>(Arrays.asList(EVT_4)), sut.selectableEvents(bpss));
assertEquals(11, sut.getDefaultPriority());
}

@Test
public void testSelectableEvents_withBlocking() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public void testSelectableEvents_noBlocking_double() throws InterruptedException
new MockBThreadSyncSnapshot("bt2", SyncStatement.make(bt("2")).request(Arrays.asList(EVT_2))),
new MockBThreadSyncSnapshot("bt2a", SyncStatement.make(bt("2a")).request(Arrays.asList(EVT_2A)))
);


assertEquals(new HashSet<>(Arrays.asList(EVT_2, EVT_2A)),
sut.selectableEvents(bpss));
Expand Down Expand Up @@ -129,11 +128,15 @@ public void testPriorityNumbers() {
assertEquals( 2, sut.getPriority("bt2a") );
assertEquals( 3, sut.getPriority("bt3") );

assertEquals( PrioritizedBThreadsEventSelectionStrategy.DEFAULT_PRIORITY,
assertEquals( sut.getDefaultPriority(),
sut.getPriority("was-not-registered") );

assertEquals( 3, sut.getHighestPriority() );
assertEquals( 1, sut.getLowestPriority() );

sut.setDefaultPriority(300);
assertEquals( sut.getDefaultPriority(),
sut.getPriority("was-not-registered") );
}

private BThreadSyncSnapshot bt( String name ) {
Expand Down

0 comments on commit 92738c5

Please sign in to comment.