![Page 1: For Coordination, State Component Transitions - Radoslaw Szymanek, Simon Bliudze](https://reader034.vdocuments.us/reader034/viewer/2022051412/549c42b8b47959cf318b46ce/html5/thumbnails/1.jpg)
Simon BliudzeAnastasia MavridouAlina Zolotukhina
Rigorous System Design Laboratory (EPFL){firstname.surname}@epfl.ch
Radoslaw SzymanekCrossing-Tech [email protected]
With partial support fromthe Swiss Commission for Technology and Innovation
For Coordination, State Component Transitions
![Page 2: For Coordination, State Component Transitions - Radoslaw Szymanek, Simon Bliudze](https://reader034.vdocuments.us/reader034/viewer/2022051412/549c42b8b47959cf318b46ce/html5/thumbnails/2.jpg)
BIP background
2
A framework and a toolset for component-based system design
Developed and maintained• by Verimag and RiSD • directed by Joseph Sifakis
(ACM Turing award 2007)
We apply lessons learnedfrom Embedded Systems to Java
![Page 3: For Coordination, State Component Transitions - Radoslaw Szymanek, Simon Bliudze](https://reader034.vdocuments.us/reader034/viewer/2022051412/549c42b8b47959cf318b46ce/html5/thumbnails/3.jpg)
Need for coordination
Independent software entities share access to resources.
Communication and data exchange can be complex.
Component execution must be coordinated.3
![Page 4: For Coordination, State Component Transitions - Radoslaw Szymanek, Simon Bliudze](https://reader034.vdocuments.us/reader034/viewer/2022051412/549c42b8b47959cf318b46ce/html5/thumbnails/4.jpg)
Semaphores, locks, monitors, etc.
Coordination based on low-level primitives rapidly becomes unpractical.
4
![Page 5: For Coordination, State Component Transitions - Radoslaw Szymanek, Simon Bliudze](https://reader034.vdocuments.us/reader034/viewer/2022051412/549c42b8b47959cf318b46ce/html5/thumbnails/5.jpg)
Synchronisation
Task 1:
...free(S1);take(S2);...
Task 2:
...take(S1);free(S2);...
5
A simple synchronisation barrier
![Page 6: For Coordination, State Component Transitions - Radoslaw Szymanek, Simon Bliudze](https://reader034.vdocuments.us/reader034/viewer/2022051412/549c42b8b47959cf318b46ce/html5/thumbnails/6.jpg)
Synchronisation
6
Three-way synchronisation barrier
Task 2:...take(S1);free(S2);free(S2);take(S3);...
Task 3:...take(S1);take(S2);free(S3);free(S3);...
Task 1:...free(S1);free(S1);take(S2);take(S3);...
![Page 7: For Coordination, State Component Transitions - Radoslaw Szymanek, Simon Bliudze](https://reader034.vdocuments.us/reader034/viewer/2022051412/549c42b8b47959cf318b46ce/html5/thumbnails/7.jpg)
Can we do worse? Yes, we can!
Task 1:initialise(x);free(S1);take(S2);sh = max(x, sh);free(S2);take(S1);x = sh;
Task 2:initialise(y);take(S1);free(S2);sh = max(y, sh);take(S2);free(S1);y = sh;
Coordination mechanisms mixed up with computation do not scale.
7
![Page 8: For Coordination, State Component Transitions - Radoslaw Szymanek, Simon Bliudze](https://reader034.vdocuments.us/reader034/viewer/2022051412/549c42b8b47959cf318b46ce/html5/thumbnails/8.jpg)
Can we do worse? Yes, we can!
Task 1:initialise(x);free(S1);take(S2);sh = max(x, sh);free(S2);take(S1);x = sh;
Task 2:initialise(y);take(S1);free(S2);sh = max(y, sh);take(S2);free(S1);y = sh;
Coordination mechanisms mixed up with computation do not scale.
Code maintenance is a nightmare!7
![Page 9: For Coordination, State Component Transitions - Radoslaw Szymanek, Simon Bliudze](https://reader034.vdocuments.us/reader034/viewer/2022051412/549c42b8b47959cf318b46ce/html5/thumbnails/9.jpg)
Separation of concerns: The BIP approach
Coordination glue is a separate entity
Component behaviour specified by Finite State Machines
8
b1 f1p1
r1
b2
f2
p2
r2b1
f1 p1
r1
b2
f2 p2
r2
![Page 10: For Coordination, State Component Transitions - Radoslaw Szymanek, Simon Bliudze](https://reader034.vdocuments.us/reader034/viewer/2022051412/549c42b8b47959cf318b46ce/html5/thumbnails/10.jpg)
Finite State Machines are everywhere
9
Android MediaRecorder interface http://developer.android.com/reference/android/media/MediaRecorder.htmlhttp://www.uml-diagrams.org
![Page 11: For Coordination, State Component Transitions - Radoslaw Szymanek, Simon Bliudze](https://reader034.vdocuments.us/reader034/viewer/2022051412/549c42b8b47959cf318b46ce/html5/thumbnails/11.jpg)
BIP by example: Mutual exclusion
10
work sleep
sleep work
sleep sleep
work work
f1b2
b1f2
f2
b1
f1
b2
f2
b2 b1
f1
b1b2
f1f2
Interaction model:{b1, f1, b2, f2, b1f2, b2f1}
Maximal progress:b1 < b1 f2, b2 < b2 f1
sleep
work
b1f1
b1 f1sleep
work
b2f2
b2 f2
work sleep
sleep work
sleep sleep
work work
f1b2
b1f2
f2b1
f1b2
f2
b2 b1
f1
work sleep
sleep work
sleep sleep
work work
f1b2
b1f2
f2b1
f1b2
f2 f1
Design front-end
Semantic back-end
![Page 12: For Coordination, State Component Transitions - Radoslaw Szymanek, Simon Bliudze](https://reader034.vdocuments.us/reader034/viewer/2022051412/549c42b8b47959cf318b46ce/html5/thumbnails/12.jpg)
Engine-based execution
1. Components notify the Engine about enabled transitions.
2. The Engine picks an interaction and instructs the components.
11
Priorities
Interactions
B E H A V I O U R
![Page 13: For Coordination, State Component Transitions - Radoslaw Szymanek, Simon Bliudze](https://reader034.vdocuments.us/reader034/viewer/2022051412/549c42b8b47959cf318b46ce/html5/thumbnails/13.jpg)
OSGi bundle states
Only lifecycle state is shown.
All functional states are hidden in the ‘Active’ state.12
Installed
ResolvedUninstalled
StoppingStarting
Active
install
uninstall resolve
uninstall
start
stop
update
![Page 14: For Coordination, State Component Transitions - Radoslaw Szymanek, Simon Bliudze](https://reader034.vdocuments.us/reader034/viewer/2022051412/549c42b8b47959cf318b46ce/html5/thumbnails/14.jpg)
Use case: Camel Routes
Many independent routes share memory• We have to control the memory usage• e.g., by limiting to only a safe number of routes
simultaneously13
![Page 15: For Coordination, State Component Transitions - Radoslaw Szymanek, Simon Bliudze](https://reader034.vdocuments.us/reader034/viewer/2022051412/549c42b8b47959cf318b46ce/html5/thumbnails/15.jpg)
Camel routes
14
public class RouteBuilder(...){from(…).routeId(…).process(…).to(…);
}
working
ready
begin end
begin
end
finishing
suspended
end
off
off
on on
offTransition types:• Enforceable
(can be controlled by the Engine)
• Spontaneous (inform about uncontrollable external events)
Camel API: suspendRoute and resumeRoute
![Page 16: For Coordination, State Component Transitions - Radoslaw Szymanek, Simon Bliudze](https://reader034.vdocuments.us/reader034/viewer/2022051412/549c42b8b47959cf318b46ce/html5/thumbnails/16.jpg)
off
on
end[!g] on
end
off
wait
doneinternal[g]
off
finished
finishedon
add rm
0
add
1 2
add
rmrm
15
Use case: BIP model
The Monitor component limits the number of active routes to two
BIP Specifications
BIP Monitor
working
ready
begin end
begin
end
finishing
suspended
end
off
off
on on
off
![Page 17: For Coordination, State Component Transitions - Radoslaw Szymanek, Simon Bliudze](https://reader034.vdocuments.us/reader034/viewer/2022051412/549c42b8b47959cf318b46ce/html5/thumbnails/17.jpg)
Implemented architecture
16
Arrows:• Blue — API calls between model and entity• Red — OSGi-managed through published services• Green — called once at initialisation phase
OSGi bundle
BIP Component
Spring app context bundleBIP ComponentSpring
bean to control
Notifier
BIP Control Spec
BIP Model Executor
BIP Monitor Spec
BIP Model Executor
Interaction specification
inform
execute
Behaviour specification
![Page 18: For Coordination, State Component Transitions - Radoslaw Szymanek, Simon Bliudze](https://reader034.vdocuments.us/reader034/viewer/2022051412/549c42b8b47959cf318b46ce/html5/thumbnails/18.jpg)
BIP Specification: Ports, Initial state
17
Behavioroff
on
end[!g] on
end
off
wait
doneinternal[g]
off
finished
finishedon
@bipPorts({@bipPort(name = "end", type = "spontaneous"), @bipPort(name = "off", type = "enforceable"), …
})
@bipComponentType(initial = "off", name = "org.bip.spec.switchableRoute")
public class SwitchableRoute implements CamelContextAware, InitializingBean, DisposableBean { … }
![Page 19: For Coordination, State Component Transitions - Radoslaw Szymanek, Simon Bliudze](https://reader034.vdocuments.us/reader034/viewer/2022051412/549c42b8b47959cf318b46ce/html5/thumbnails/19.jpg)
BIP Specification: Transitions
18
Transition annotations provide• Label: a port, declared by @bipPort
• Source and target states• Guard expression
Behavioroff
on
end[!g] on
end
off
wait
doneinternal[g]
off
finished
finishedon
@bipTransition(name = "off",source = "on", target = "wait", guard = "")
public void stopRoute() throws Exception { camelContext.suspendRoute(routeId);}
![Page 20: For Coordination, State Component Transitions - Radoslaw Szymanek, Simon Bliudze](https://reader034.vdocuments.us/reader034/viewer/2022051412/549c42b8b47959cf318b46ce/html5/thumbnails/20.jpg)
BIP Specification: Guards
19
Behavioroff
on
end[!g] on
end
off
wait
doneinternal[g]
off
finished
finishedon
@bipTransition(name = "end", source = "wait", target = "done", guard = "!isFinished")public void spontaneousEnd() throws Exception { … }
@bipTransition(name = "", source = "wait", target = "done", guard = "isFinished")public void internalEnd() throws Exception { … }
![Page 21: For Coordination, State Component Transitions - Radoslaw Szymanek, Simon Bliudze](https://reader034.vdocuments.us/reader034/viewer/2022051412/549c42b8b47959cf318b46ce/html5/thumbnails/21.jpg)
BIP Specification: Guards
19
Behavioroff
on
end[!g] on
end
off
wait
doneinternal[g]
off
finished
finishedon
@bipTransition(name = "end", source = "wait", target = "done", guard = "!isFinished")public void spontaneousEnd() throws Exception { … }
@bipTransition(name = "", source = "wait", target = "done", guard = "isFinished")public void internalEnd() throws Exception { … }
@bipGuard(name = "isFinished")public boolean isFinished() { CamelContext cc = camelContext; return cc.getInflightRepository().size( cc.getRoute(routeId).getEndpoint() ) == 0;}
![Page 22: For Coordination, State Component Transitions - Radoslaw Szymanek, Simon Bliudze](https://reader034.vdocuments.us/reader034/viewer/2022051412/549c42b8b47959cf318b46ce/html5/thumbnails/22.jpg)
BIP Component interface
20
Interface methods:• execute — called by the Engine to
execute an enforceable transition• inform — called by Notifiers to inform
about spontaneous events
Behavioroff
on
end[!g] on
end
off
wait
doneinternal[g]
off
finished
finishedon
public interface BIPComponent extends BIPSpecification { void execute(String portID); void inform(String portID);}
![Page 23: For Coordination, State Component Transitions - Radoslaw Szymanek, Simon Bliudze](https://reader034.vdocuments.us/reader034/viewer/2022051412/549c42b8b47959cf318b46ce/html5/thumbnails/23.jpg)
BIP Executor interface
21
Interface methods:• publish/unpublish — collaborates with OSGi
service registry• register/deregister — manage connection with the
BIP Engine
Implements the component execution semantics
public interface Executor extends BIPComponent { void publish(); void unpublish();
void register(BIPEngine bipEngine); void deregister();}
![Page 24: For Coordination, State Component Transitions - Radoslaw Szymanek, Simon Bliudze](https://reader034.vdocuments.us/reader034/viewer/2022051412/549c42b8b47959cf318b46ce/html5/thumbnails/24.jpg)
Spontaneous event notifiers
22
Behavioroff
on
end[!g] on
end
off
wait
doneinternal[g]
off
finished
finishedon
BIP Specification may also need to know it’s executor in order to set up notification mechanisms
new RoutePolicy() {…public void onExchangeDone(Route route, Exchange exchange)
{executor.inform("end");
}}
![Page 25: For Coordination, State Component Transitions - Radoslaw Szymanek, Simon Bliudze](https://reader034.vdocuments.us/reader034/viewer/2022051412/549c42b8b47959cf318b46ce/html5/thumbnails/25.jpg)
Conclusion: Separation of concerns
Coordination code depends on the execution environment
No coordination code in business components
Coordination code is confined to • BIP Glue specification• BIP Specification of the monitors imposing system
properties
23
![Page 26: For Coordination, State Component Transitions - Radoslaw Szymanek, Simon Bliudze](https://reader034.vdocuments.us/reader034/viewer/2022051412/549c42b8b47959cf318b46ce/html5/thumbnails/26.jpg)
Conclusion: Developer perspective
Developer provides BIP Spec as a Java class
BIP Spec is reusable
BIP Executor • implements the BIP semantics• interacts with the BIP Engine
24
![Page 27: For Coordination, State Component Transitions - Radoslaw Szymanek, Simon Bliudze](https://reader034.vdocuments.us/reader034/viewer/2022051412/549c42b8b47959cf318b46ce/html5/thumbnails/27.jpg)
Future work
• Data transfer
• Exception handling & transaction support
• Further experimentation with real-life applications
• Adding BIP coordination to the OSGi standard
25
![Page 28: For Coordination, State Component Transitions - Radoslaw Szymanek, Simon Bliudze](https://reader034.vdocuments.us/reader034/viewer/2022051412/549c42b8b47959cf318b46ce/html5/thumbnails/28.jpg)
Thank you!
Any question
s?
![Page 29: For Coordination, State Component Transitions - Radoslaw Szymanek, Simon Bliudze](https://reader034.vdocuments.us/reader034/viewer/2022051412/549c42b8b47959cf318b46ce/html5/thumbnails/29.jpg)
State stability
It must be possible to postpone the treatment of spontaneous events.
27
working
ready
begin end
begin
end
finishing
suspended
end
off
off
on on
off
![Page 30: For Coordination, State Component Transitions - Radoslaw Szymanek, Simon Bliudze](https://reader034.vdocuments.us/reader034/viewer/2022051412/549c42b8b47959cf318b46ce/html5/thumbnails/30.jpg)
working
ready
begin
end
finishing
suspended
end
off
off
on
on
finishing suspendedend
off
internal[!g]
on
wait
internal[g]
on
suspended
off
end[!g]
on
wait
internal[g]
on
done
off
end[!g]
on
wait
internal[g]
offfinished
28
g = isFinished()
on
begin
end
finishing
suspended
endoff off
on