SurfaceFlinger is a vital system service in Android system, responsible for the composting all the application and system layer and displaying them. In this slide,we looked in detail how surfaceFlinger was designed from Design Pattern's perspective.
9. Examples
You subscribe to an RSS to get notification for new article
Controller subscribe to View for Event
MediaPlayer notify user the status of current player
ConsumerBase subscribe to BufferQueue for enqueue
event
SurfaceFlinger subscribe to HWC for hotplug/vsync
19. Questions?
Isn’t put and get enough to describe the model?
Why we need dequeue?
is dequeue an consumer action or producer action?
dequeue acquire
enqueue release
20. Sushi shop, example
Each Plate cost $1000
So for each customer they only provide you 3 Plate
You have to return the used Plate to the trail so that
servant can make next sushi.
26. Producer in another Process
+ Proxy
BQ
dequeue acquire
enqueue
release
Observer Scheduler
Message
Proxy
trigger
27. +Sync-er
When a dequeue a resource but actually you can not use it
immediately. You have to wait until that resource is free.
Then, why not dequeue block?
BQ
dequeue acquire
enqueue
release
Observer Scheduler
Message
Proxy
trigger
sync-er
Sync-er
35. Goal:
Increase throughput and
Improve responsiveness
ServerSocket socket = new ServerSocket();
While(true){
Socket con = socket.accept();
handleRequest(con);
}
Sequential execution
Thread– Per -Task
service
client
client
client
client
client
client
36. Thread pool Pattern is where a number of threads are created to
perform tasks submitted to task queue
client
Task submission Task execution
Submit task
retrieve result
37. Let’s return to
Producer/Consumer a while…
Task Queue is a Producer/Consumer , multiply Consumer,
one or more Producer
BufferQueue is really a Resource Pool
41. The active object design pattern
decouples
method execution from
method invocation
for objects that each reside in their own thread of control.
42. Why not Passive Object
Object called in the client thread, result in more
complex synchronization
Schedule/MessageQueue sequential the request to
servant object