For Coordination, State Component Transitions discusses applying lessons learned from embedded systems to Java using the BIP framework. BIP provides a toolset for component-based system design with independent software entities that must be coordinated as they share resources and exchange data and communication can be complex. The document presents examples of how BIP separates coordination concerns from component behavior through the use of finite state machines and an engine to control interactions based on priorities. It describes implementing coordination of Camel routes using a BIP model and monitor component to limit the number of active routes.
For Coordination, State Component Transitions - Radoslaw Szymanek, Simon Bliudze
1. For Coordination, State Component Transitions
Simon Bliudze
Anastasia Mavridou
Alina Zolotukhina
Rigorous System Design Laboratory (EPFL)
{firstname.surname}@epfl.ch
Radoslaw Szymanek
Crossing-Tech S.A.
radoslaw.szymanek@crossing-tech.com
With partial support from
the Swiss Commission for Technology and Innovation
2. BIP background
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 learned
from Embedded Systems
to Java
2
3. Need for coordination
Independent software entities share access to resources.
Communication and data exchange can be complex.
Component execution must be coordinated.
3
7. Can we do worse? Yes, we can!
Task 1:
Task 2:
initialise(x);
free(S1);
take(S2);
sh = max(x, sh);
free(S2);
take(S1);
x = sh;
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
8. Can we do worse? Yes, we can!
Task 1:
Task 2:
initialise(x);
free(S1);
take(S2);
sh = max(x, sh);
free(S2);
take(S1);
x = sh;
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
9. Separation of concerns: The BIP approach
b1
f1
b1
r1
b2
f1
p1
p1
r1
r2
f2
f2
p2
b2
p2
r2
Coordination glue is a separate entity
Component behaviour specified by Finite State Machines
8
10. Finite State Machines are everywhere
http://www.uml-diagrams.org
Android MediaRecorder interface
http://developer.android.com/reference/
android/media/MediaRecorder.html
9
11. BIP by example: Mutual exclusion
b1
f1
b2
sleep
f1
f2
sleep
b1
f2
work
b2
work
Interaction model:
{b1, f1, b2, f2, b1f2, b2f1}
Maximal progress:
b1 < b1 f2, b2 < b2 f1
Design front-end
Semantic back-end
sleep
sleep
f1
work
sleep
b1
b2
b 1b 2
f1b2
b2
f2
f2
f1f2
work
work
b1f2
b1
f1
sleep
work
sleep
sleep
f1
work
sleep
b1
f1b2
f1
b2
b1f2
b1
b2
f2
f2
work
work
f1
sleep
work
sleep
sleep
work
sleep
f2
b1
f1b2
f2
b2
b1f2
work
work
sleep
work
f1
10
12. Engine-based execution
1. Components
notify the Engine
about enabled
transitions.
B
E
H
A
V
I
O
U
R
Interactions
Priorities
2. The Engine
picks an
interaction and
instructs the
components.
11
14. 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
simultaneously
13
15. Camel routes
public class RouteBuilder(...)
{
from(…).routeId(…).process(…).to(…);
}
Camel API: suspendRoute and resumeRoute
Transition types:
•
• Spontaneous
Enforceable
(can be controlled by the Engine)
working
off
finishing
off
begin
end
end
off
(inform about uncontrollable external events)
ready
begin
end
suspended
on
on
14
16. Use case: BIP model
BIP Specifications
working
off
finishing
off
finished
off
begin
off
end
off
done
end
[!g]
end
end
internal
[g]
wait
off
ready
on
begin
end
suspended
on
on
on
finished
on
add
add
0
rm
add
1
rm
2
rm
BIP Monitor
The Monitor component
limits the number of
active routes to two
15
17. Implemented architecture
Spring app context bundle
BIP Component
Spring
bean to
control
Notifier
BIP
Control
Spec
BIP
Model
Executor
Interaction
specification
inform
execute
OSGi bundle
BIP Component
BIP Monitor
Spec
BIP Model
Executor
Behaviour
specification
Arrows:
• Blue — API calls between model and entity
• Red — OSGi-managed through published services
• Green — called once at initialisation phase
16
18. BIP Specification: Ports, Initial state
@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
{ … }
Behavior
finished
off
off
done
end
[!g]
internal
[g]
wait
on
end
off
on
on
finished
17
19. BIP Specification: Transitions
@bipTransition(name = "off",
source = "on", target = "wait", guard = "")
public void stopRoute() throws Exception {
camelContext.suspendRoute(routeId);
}
Transition annotations provide
•
•
•
Label: a port, declared by @bipPort
Source and target states
Guard expression
Behavior
finished
off
off
done
end
[!g]
internal
[g]
wait
on
end
off
on
on
finished
18
20. BIP Specification: Guards
@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 { … }
Behavior
finished
off
off
done
end
[!g]
internal
[g]
wait
on
end
off
on
on
finished
19
21. BIP Specification: Guards
@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")
Behavior
public boolean isFinished() {
finished
CamelContext cc = camelContext;
off
done
return
end
cc.getInflightRepository().size(
[!g]
wait
cc.getRoute(routeId).getEndpoint()
end
) == 0;
off
}
on
off
internal
[g]
on
on
finished
19
22. BIP Component interface
public interface BIPComponent extends BIPSpecification
{
void execute(String portID);
void inform(String portID);
}
Interface methods:
• execute — called by the Engine to
•
execute an enforceable transition
inform — called by Notifiers to inform
about spontaneous events
Behavior
finished
off
off
done
end
[!g]
internal
[g]
wait
on
end
off
on
on
finished
20
23. BIP Executor interface
public interface Executor extends BIPComponent {
void publish();
void unpublish();
void register(BIPEngine bipEngine);
void deregister();
}
Interface methods:
• publish/unpublish
•
— collaborates with OSGi
service registry
register/deregister — manage connection with the
BIP Engine
Implements the component execution semantics
21
24. Spontaneous event notifiers
new RoutePolicy() {
…
public void onExchangeDone(
Route route, Exchange exchange)
{
executor.inform("end");
}
}
BIP Specification may also need
to know it’s executor in order to
set up notification mechanisms
Behavior
finished
off
off
done
end
[!g]
internal
[g]
wait
on
end
off
on
on
finished
22
25. 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
26. 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
27. Future work
• Data transfer
• Exception handling & transaction support
• Further experimentation with real-life applications
• Adding BIP coordination to the OSGi standard
25