Programming Coordinated Behavior in Java David Harel, Assaf Marron, - - PowerPoint PPT Presentation

programming coordinated behavior in java david harel
SMART_READER_LITE
LIVE PREVIEW

Programming Coordinated Behavior in Java David Harel, Assaf Marron, - - PowerPoint PPT Presentation

Programming Coordinated Behavior in Java David Harel, Assaf Marron, Gera Weiss Ben-Gurion University of the Negev 1 David Harel Gera Weiss Assaf Marron 2 Overview Scenario-based


slide-1
SLIDE 1

Programming Coordinated Behavior in Java David Harel, Assaf Marron, Gera Weiss

1

ב תטיסרבינוא בגנב וירוג Ben-Gurion University of the Negev

slide-2
SLIDE 2

David Harel

2

Gera Weiss Assaf Marron

slide-3
SLIDE 3

Overview

  • Scenario-based programming is a natural and useful approach:

– Behaviors are programmed separately – oblivious of each other – Interlaced and coordinated centrally at run time

  • Introduced via the visual language LSC - Live Sequence Charts

– [Damm and H., 2001, H. and Marelly, 2003]

  • We extend it to OO / procedural programming

– Behaviors are coded as Java threads (b-threads) – Coordination/ interlacing thru a new Java lib & API

  • A general paradigm emerges: Behavioral Programming

3

slide-4
SLIDE 4

Outline

  • Formal semantics
  • The Java library: BPJ
  • Examples
  • Future research directions

4

slide-5
SLIDE 5

Decomposing Complex Behaviors Human behavior can often be decomposed into interlaced threads

Traveling =

  • Directions + Daily Schedule

5

Game Playing = Rules + Basic Strategies + Tips & Tricks

slide-6
SLIDE 6

A software component that coordinates and controls a system behavior. The b-thread:

  • Requests that events be considered for triggering

Behavior thread (“b-thread”)

  • Requests that events be considered for triggering
  • Watches for events that were triggered
  • Blocks events (requested by others) from being triggered

…and all b-threads are interlaced and synchronized

6

slide-7
SLIDE 7
  • 1. “Bidding”
  • 2. “Auction and Announcement”

Interlacing and Synchronization Cycle

: Each b-thread announces requested, blocked , watched events : Select a requested, not blocked event

  • 3. Arbitrary computing

7

Requested events Blocking Selected event b-thread b-thread b-thread b-thread

slide-8
SLIDE 8

The “Block” Idiom

Example: B-Threads for adjusting water temperature & flow

(Thanks to Amir Nissim)

AdjustHighTemp:

– watch for tempTooHigh – request addCold or reduceHot, and block addHot and reduceCold

AdjustLowTemp AdjustLowTemp

– watch for tempTooLow – request reduceCold or addHot, and block reduceHot and addCold

AdjustHighFlow

– watch for flowTooHigh – request reduceHot or reduceCold, and block addHot and addCold

AdjustLowFlow

– watch for flowTooLow – request addHot or addCold, and block reduceCold and reduceHot

8

H C

slide-9
SLIDE 9

A b-thread is: – a transition system →; and – for each state :

  • a set ()of requested events
  • a set () of blocked events

b-Thread: Formal Definition

9

()={,} ()={,}

,

()={,} ()={}

,, . . .

The events on arrows are called watched events

slide-10
SLIDE 10

Execution of a set of b-threads: Formal Def.

A run of a set of b-threads {→ }: The event causes the transition iff:

10

slide-11
SLIDE 11

Controlling Event Selection

  • Priorities/order are added for programming control
  • Current implementation:

– Each b-thread has a distinct priority (a real number) – Within each b-thread, the requested-events set is ordered

  • Select the first event that is requested and not blocked

11

slide-12
SLIDE 12

The BPJ Library and API

BThread

  • B-threads are Java threads
  • Events and event sets are Java objects and collections
  • Development and execution do not require special environments
  • Direct integration with other Java code

12

Online: www.cs.bgu.ac.il/~geraw

requestedEvents : Event set blockedEvents : Event set watchedEvents : Event set priority : Real runBThread() /* overridden for every b-thread */ bSync(requested, watched, blocked)

Event

slide-13
SLIDE 13

Example 1: “Hello, World!”

Part 1. Events

13

slide-14
SLIDE 14

Part 2. b-Threads

14

slide-15
SLIDE 15

Part 3. Final Output

15

slide-16
SLIDE 16

Demo “Hello, World!” in Eclipse

16

slide-17
SLIDE 17

Example 2: A Behavioral Program for Tic-Tac-Toe

  • Events:

– Move events – XWin, Owin, Draw

  • B-Threads

X<0,0> X<0,1> X<0,2> X<1,0> X<1,1> X<1,2> X<2,0> X<2,1> X<2,2> O<0,0> O<0,1> O<0,2> O<1,0> O<1,1> O<1,2> O<2,0> O<2,1> O<2,2>

  • B-Threads

– Rules:

  • Alternate player turns
  • Prevent multiple marking in same square
  • Detect win and draw conditions

– Tactics, e.g. :

  • Attack: Wait for two O moves in a line – request marking of third square
  • Defense: Wait for two X moves in a line – request marking of third square
  • Prevent “fork” conditions
  • Default moves

17

slide-18
SLIDE 18

Incrementality and Behavior Autonomy

Note that when b-threads were added:

Little or no change to existing code Meaningful/Interesting behavior from early development stages

18

New code has little or no dependency on old code

slide-19
SLIDE 19

Development with BP: Advantages

  • Natural : Alignment with how people think about behavior / specify requirements
  • Suitability to multi-core architectures
  • Incremental:

– Add/remove behavior with little or no change to existing b-threads – Suitability for collaborative / open source projects – Possibility for dynamic updates. – Possibility for dynamic updates.

  • Modularity – Behavior Autonomy:

– Code of b-threads has little or no dependency on code in other b-threads – “Redundant” requested events are unified, events that are not watched are ignored

  • Early/partial execution
  • Integration with powerful languages (e.g. Java)
  • Explicit behavior prioritization
  • Ability to “explain” program actions

19

slide-20
SLIDE 20

Evolution leading to this work

  • Natural language descriptions of behavior (e.g. requirements / specification docs)
  • Formal languages: MSCs (1996), UML Sequence Diagrams (1997)
  • Executable visual languages – StateCharts (1987, 1990)
  • LSC and the Play Engine: Scenario based programming (1999,2001,2003)

– Programming and running scenarios: play-in and play-out – Programming and running scenarios: play-in and play-out – Multi-modality:

  • Must vs. May, Allow vs. Forbid, Universal vs. Existential, Execute vs. monitor

– Focused on executing or monitoring the specification

  • BPJ: Imperative idioms for programming behaviors (2010)

– Basic idioms: b-threads, request/watch/block – BPJ: Integrate b-thread programming with OO – Focused on enabling scenario-based programming in traditional environments.

20

slide-21
SLIDE 21

LSC Example Phone - Speed Dialing Scenario

21

slide-22
SLIDE 22

Future Research Directions

  • Deadlock/conflict detection: verification/model-checking, ‘’smart play-out’’

(Java pathfinder)

  • Visualization of synchronized b-threads
  • Enriched semantics: Concurrent events, sets/hierarchy of behavioral programs,

dynamic priorities, prioritized blocking

  • Higher level interfaces and DSLs; end-user programming; tools;
  • Higher level interfaces and DSLs; end-user programming; tools;
  • Applications: robotics, hybrid systems (w/ideas from fuzzy logic), games, biological

simulation, multi-agent/swarms.

  • Expand programming environments: e.g. functional, in Erlang.
  • Automatic patching, genetic programming.
  • Performance: analysis and optimization
  • Development methodologies
  • Quantitative comparison to other approaches

22

slide-23
SLIDE 23

BPJ and Behavioral Programming: Summary

  • Behavioral programming – an emerging general paradigm
  • Bringing advantages of scenario-based programming from the realm of LSCs

to classical programming:

– Behavior modularity, incrementality, suitability for multi-core, natural development,…

  • A working Java implementation + several small-scale examples
  • Basic idioms: request / watch / block

– implementable in other languages – extendable

  • Many interesting research questions
  • The library is available at www.cs.bgu.ac.il/~geraw

23

slide-24
SLIDE 24

Thank You Questions / Discussion

24