Download Programming Coordinated Behavior in Java

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Abstraction (computer science) wikipedia , lookup

Functional programming wikipedia , lookup

Library (computing) wikipedia , lookup

Comment (computer programming) wikipedia , lookup

Reactive programming wikipedia , lookup

Indentation style wikipedia , lookup

Go (programming language) wikipedia , lookup

Programming language wikipedia , lookup

Monitor (synchronization) wikipedia , lookup

Block sort wikipedia , lookup

Falcon (programming language) wikipedia , lookup

Object-oriented programming wikipedia , lookup

Thread (computing) wikipedia , lookup

Interpreter (computing) wikipedia , lookup

C Sharp (programming language) wikipedia , lookup

Structured programming wikipedia , lookup

Transcript
Gera Weiss
Department of Computer Science
Ben Gurion University of The Negev
» Program a separate code module for each "paragraph"
in the requirements document
» When requirements are added or refined, add
modules with little or no change to existing code
» Use an application-agnostic interweaving mechanism
to run the modules together
» ... In the framework of the familiar programming
languages, constructs, and concepts
Driving Directions
Daily Schedule
...
Drive for 4 hrs.
…
Stop for Lunch
Drive for 5 hrs.
…
3
A 6-day trip from NYC to LA
Maintenance without modifying existing code ?!
… and can we implement new requirements
without expertise in the legacy code?
4
» The program modules, called behavior-threads (b-threads), are
ordinary procedures in a programming language
» All b-threads meet before each action the system takes
» In each meeting, b-threads specify what they request and
what they forbid for the next step
» At the end of each meeting,
an application-agnostic mechanism
selects an action (event) that is
requested but not forbidden
Wait
Behavior B-s
Threads
Request
6
Block
Wait
Behavior B-s
Threads
Request
7
Block
Wait
Behavior B-s
Threads
Request
8
Block
Wait
Behavior B-s
Threads
Request
9
Block
AddHotFiveTimes() {
for i=1 to 5 {
bSync(request=addHot, wait-for=none, block=none);
}
}
AddColdFiveTimes() {
for i=1 to 5 {
bSync(request=addCold, wait-for=none, block=none);
}
}
Interleave() {
forever {
bSync(request=none, wait-for=addHot, block=addCold);
bSync(request=none, wait-for=addCold, block=addHot);
}
}
1
0
Hot
Water
Cold
Water
addHot
addHot
addHot
addHot
addHot
addHot
addCold
addHot
addHot
addHot
addHot
addHot
addCold
addHot
addHot
addCold
addCold
addCold
addHot
addCold
addCold
addCold
addHot
addCold
addCold
1. All behavior threads (b-threads) post declarations:
• Request events: propose events to be considered for triggering;
• Wait for events: ask to be notified when events are triggered;
• Block events: temporarily forbid the triggering of events.
2. When all declarations are collected:
An event that is requested and not blocked is selected.
All b-threads waiting for this event can update their declaration
1
1
Distributed Data Processing
Robotics
Mobile Computing
Complexity stems from the need to
interleave many simultaneous behaviors
1
2
Scalability
• Tools for developing many b-threads
• Architectures for efficient execution of many b-threads
Dealing with conflicts and under-specification
•
•
•
•
Model checking
Automatic program repair
Machine learning
Planning
Evaluation
• Empirical studies
• Complex applications
• Theoretical advantages
and limitations
1
3
And more…
» David Harel
»
»
»
»
»
Werner Damm
Rami Marelly
Hillel Kugler
Shahar Maoz
Itai Segall
» Assaf Marron
»
»
»
»
»
»
»
»
»
»
Robby Lampert
Guy Wiener
Amir Nissim
Nir Eitan
Michal Gordon
Guy Katz
Moshe Weinstock
Michael Bar-Sinai
Ronen Brafman
...
LSC: A visual language for scenario specification
 Damm and Harel 2001, Harel and Marelly 2003
 Natural yet executable scenario-based specification
 Initially for requirement specification, evolved into a programming language
 PlayGo – an IDE for programming with LSC
BPJ: A package for programming scenarios in Java
(and equivalents for other languages)
 Harel, Marron, and Weiss 2010
class AddHotFiveTimes extends BThread {
public void runBThread() {
for (int i=1; i<=5; i++) {
bSync(addHot, none, none);
}
}
}
 Bringing advantages of scenario-based specification to programming
 Integrate with & complement other paradigms (OOP, aspects, rule-based, agile, …).
1
5
Programming by dragging & dropping Scratch like bricks: You will soon see…
Asynchronous
Communication
B-thread
B-thread
Behavior
Nodes
B-thread
B-thread
B-thread
B-thread
B-thread
Sensors and
Actuators
World
1
6
B-thread
1
7
When I put two Xs in a line, you
need to put an O in the third
square
1
8
1
9
Each new game rule or strategy is added in a
separate b-thread
without changing existing code
2
0
» What about conflicts?
» Sources of conflicts:
» Implementation error / misunderstanding of a requirement
» Conflicting requirements
» In both cases: Good to catch as early as possible !
» Tools for catching conflicts: trace visualization, model-checking
2
1
2
2
D
Program states are the
Cartesian product of
b-thread states
G
B
H
C
ADG
I
BDG
…
…
…
BDH
2
3
E
A
AEG
…
AEI
Backtrack using Apache
javaflow continuations
Transition using standard
execution (by the native JVM)
Notations for
nondeterministic
transitions
State matching and search
pruning by b-threads
2
4
Deadlocks detected
automatically
State tagging for safety
and liveness properties
by b-threads
» What if several events are requested and not blocked ?
» The run-time environment can choose the next event :
1.
Randomly and reinforce probabilities using machine learning; or,
2.
By looking ahead and planning an optimal path
» Programmers can easily code assessment of states in b-threads
?
?
2
5
Capture each requirement in a separate code-module
Verify that requirements do not conflict
Interweave and execute using a general mechanism
Wait
Behavior B-s
Threads
Request
Block