0% found this document useful (0 votes)
26 views37 pages

8 Services and IPC Part 17

The document discusses the Activator pattern which allows services in a system to only consume resources when actively accessed by clients. It describes the pattern's applicability, structure involving clients, services, and an activator manager, and dynamics where the activator looks up and activates services on demand to improve resource utilization.

Uploaded by

ims
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views37 pages

8 Services and IPC Part 17

The document discusses the Activator pattern which allows services in a system to only consume resources when actively accessed by clients. It describes the pattern's applicability, structure involving clients, services, and an activator manager, and dynamics where the activator looks up and activates services on demand to improve resource utilization.

Uploaded by

ims
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 37

Android Services & Local IPC:

The Activator Pattern (Part 1)

Douglas C. Schmidt
[email protected]
www.dre.vanderbilt.edu/~schmidt

Professor of Computer Science


Institute for Software
Integrated Systems

Vanderbilt University
Nashville, Tennessee, USA
Android Services & Local IPC Douglas C. Schmidt

Learning Objectives in this Part of the Module


• Understand the Activator pattern

2
www.dre.vanderbilt.edu/~schmidt/PDF/Activator.pdf
Android Services & Local IPC Douglas C. Schmidt

Challenge: Minimizing Resource Utilization


Context

• Resource constrained & highly Small Memory Device


dynamic environments
• Random-access memory (RAM)
is a valuable resource in any
software environment

3
Android Services & Local IPC Douglas C. Schmidt

Challenge: Minimizing Resource Utilization


Context

• Resource constrained & highly Small Memory Device


dynamic environments
• Random-access memory (RAM)
is a valuable resource in any
software environment
• It's even more valuable on a
mobile OS like Android where
physical memory is often
constrained

4
Android Services & Local IPC Douglas C. Schmidt

Challenge: Processing a Long-Running Action


Problem
• It‘s not feasible to have all App Small Memory Device
Service implementations running
all the time since this ties up end-
system resources unnecessarily

5
developer.android.com/training/articles/memory.html has more info
Android Services & Local IPC Douglas C. Schmidt

Challenge: Processing a Long-Running Action


Solution
• Apply the Activator pattern ActivityManagerService
bindService()
to activate & deactivate Client 1
ServiceMap
Android Services
automatically mServicesByNamePerUser

mServicesByIntentPerUser
• If your app needs a Service
to perform work in the 2 Process.start()
background, don’t keep it
3
running unless it's actively someMethodCall()
performing a job
4 Service

6
Android Services & Local IPC Douglas C. Schmidt

Challenge: Processing a Long-Running Action


Solution
• Apply the Activator pattern ActivityManagerService
bindService()
to activate & deactivate Client 1
ServiceMap
Android Services
automatically mServicesByNamePerUser

mServicesByIntentPerUser
• If your app needs a Service
to perform work in the 2 Process.start()
background, don’t keep it
3
running unless it's actively someMethodCall()
performing a job
4 Service
• Be careful to never leak
your Service by failing to stop
it when its work is done

7
developer.android.com/training/articles/memory.html#Services has more info
Android Services & Local IPC Douglas C. Schmidt

Activator POSA4 Design Pattern


Intent
• Activator automates scalable on-demand activation & deactivation of
service execution contexts to run services accessed by many clients
without consuming excessive resources

8
www.dre.vanderbilt.edu/~schmidt/PDF/Activator.pdf has more info
Android Services & Local IPC Douglas C. Schmidt

Activator POSA4 Design Pattern


Applicability
• When services in a system should only consume resources when they
are accessed actively by clients

9
Android Services & Local IPC Douglas C. Schmidt

Activator POSA4 Design Pattern


Applicability
• When services in a system should only consume resources when they
are accessed actively by clients
• When clients should be shielded from where services are located, how
they are deployed onto hosts or processes, & how their lifecycle is
managed

10
Android Services & Local IPC Douglas C. Schmidt

Activator POSA4 Design Pattern


Structure & Participants

Activity

11
Android Services & Local IPC Douglas C. Schmidt

Activator POSA4 Design Pattern


Structure & Participants

Intent

12
Android Services & Local IPC Douglas C. Schmidt

Activator POSA4 Design Pattern


Structure & Participants

Context

13
Android Services & Local IPC Douglas C. Schmidt

Activator POSA4 Design Pattern


Structure & Participants

Activity
Manager
Service

14
Android Services & Local IPC Douglas C. Schmidt

Activator POSA4 Design Pattern


Structure & Participants
ServiceMap

15
Android Services & Local IPC Douglas C. Schmidt

Activator POSA4 Design Pattern


Structure & Participants

Linux Process

16
Android Services & Local IPC Douglas C. Schmidt

Activator POSA4 Design Pattern


Structure & Participants

IntentService

17
Android Services & Local IPC Douglas C. Schmidt

Activator POSA4 Design Pattern


Dynamics The Client uses the Activator
to get service access

18
Android Services & Local IPC Douglas C. Schmidt

Activator POSA4 Design Pattern


Dynamics

When incoming requests arrive, the Activator looks up


whether a target object is already active & if the object is
not running it activates the Service Execution Context

19
Android Services & Local IPC Douglas C. Schmidt

Activator POSA4 Design Pattern


Dynamics

An Activator can activate & passivate a


Service running in a server after each
method call, each transaction, etc

20
Android Services & Local IPC Douglas C. Schmidt

Activator POSA4 Design Pattern


Dynamics The Activation Table
stores associations
between services &
their physical location

21
Android Services & Local IPC Douglas C. Schmidt

Activator POSA4 Design Pattern


Dynamics

A Service implements a specific type of


functionality that it provides to clients
22
Android Services & Local IPC Douglas C. Schmidt

Activator POSA4 Design Pattern


Consequences
ActivityManagerService
+ More effective resource bindService()

utilization Client 1
ServiceMap
• Servers can be spawned mServicesByNamePerUser
“on-demand,” thereby mServicesByIntentPerUser
minimizing resource
utilization until clients 2 Process.start()
actually require them 3
someMethodCall()
4 Service

23
Android Services & Local IPC Douglas C. Schmidt

Activator POSA4 Design Pattern


Consequences
ActivityManagerService
+ More effective resource bindService()

utilization Client 1
ServiceMap
+ Coarse-grained concurrency mServicesByNamePerUser

• By spawning server mServicesByIntentPerUser


processes to run on
multi-core/CPU computers 2 Process.start()

3
someMethodCall()
4 Service

24
Android Services & Local IPC Douglas C. Schmidt

Activator POSA4 Design Pattern


Consequences
ActivityManagerService
+ More effective resource bindService()

utilization Client 1
ServiceMap
+ Coarse-grained concurrency mServicesByNamePerUser

+ Modularity, testability, & mServicesByIntentPerUser


reusability
2 Process.start()
• Application modularity &
reusability is improved by 3
someMethodCall()
decoupling server 4 Service
implementations from
the manner in which the
servers are activated

25
Android Services & Local IPC Douglas C. Schmidt

Activator POSA4 Design Pattern


Consequences
ActivityManagerService
– Lack of determinism & bindService()

ordering dependencies Client 1


ServiceMap
• Hard to determine or mServicesByNamePerUser
analyze the behavior of mServicesByIntentPerUser
an app until its components
are activated at runtime 2 Process.start()

3
someMethodCall()
4 Service

26
Android Services & Local IPC Douglas C. Schmidt

Activator POSA4 Design Pattern


Consequences
ActivityManagerService
– Lack of determinism & bindService()

ordering dependencies Client 1


ServiceMap
– Reduced security & reliability mServicesByNamePerUser

• An application that uses mServicesByIntentPerUser


Activator may be less
secure or reliable than 2 Process.start()

an equivalent statically- 3
configured application
someMethodCall()
4 Service

27
Android Services & Local IPC Douglas C. Schmidt

Activator POSA4 Design Pattern


Consequences
ActivityManagerService
– Lack of determinism & bindService()

ordering dependencies Client 1


ServiceMap
– Reduced security & reliability mServicesByNamePerUser

– Increased run-time overhead & mServicesByIntentPerUser


infrastructure complexity
2 Process.start()
• By adding levels of abstraction
& indirection when activating 3
someMethodCall()
& executing components 4 Service

28
Android Services & Local IPC Douglas C. Schmidt

Activator POSA4 Design Pattern


Known Uses
• UNIX Inetd “super server” Internal Internal Internal
service service service
• Internal services are fixed at
static link time
• e.g., ECHO & DAYTIME

29
Android Services & Local IPC Douglas C. Schmidt

Activator POSA4 Design Pattern


Known Uses
• UNIX Inetd “super server” Internal Internal Internal
service service service
• Internal services are fixed at
static link time
• External services can be
dynamically reconfigured
• e.g., FTP, TELNET, & HTTP

30
See en.wikipedia.org/wiki/Inetd for more on Inetd
Android Services & Local IPC Douglas C. Schmidt

Activator POSA4 Design Pattern


Known Uses
• UNIX Inetd “super server”
• CORBA Implementation Repository

1. some_request

Client ImR (ringil:5000)


iiop://ringil:5000/poa_name/object_name 4. LOCATION_FORWARD
poa_name server.exe ringil:5500
iiop://ringil:5500/poa_name/object_name airplane_poa plane.exe ringil:4500

2. ping
3. is_running
2.1 start

5. some_request Server (ringil:5500)


6. some_response

31
Android Services & Local IPC Douglas C. Schmidt

Activator POSA4 Design Pattern


Known Uses
• UNIX Inetd “super server”
• CORBA Implementation Repository
• Android ActivityManagerService

ActivityManagerService
bindService()
Client 1
ServiceMap
mServicesByNamePerUser

mServicesByIntentPerUser

32
Android Services & Local IPC Douglas C. Schmidt

Activator POSA4 Design Pattern


Known Uses
• UNIX Inetd “super server”
• CORBA Implementation Repository
• Android ActivityManagerService

ActivityManagerService
bindService()
Client 1
ServiceMap
mServicesByNamePerUser

mServicesByIntentPerUser

2 Process.start()

Service

33
Android Services & Local IPC Douglas C. Schmidt

Activator POSA4 Design Pattern


Known Uses
• UNIX Inetd “super server”
• CORBA Implementation Repository
• Android ActivityManagerService

ActivityManagerService
bindService()
Client 1
ServiceMap
mServicesByNamePerUser

mServicesByIntentPerUser

2 Process.start()

3
someMethodCall()
Service

34
Android Services & Local IPC Douglas C. Schmidt

Activator POSA4 Design Pattern


Known Uses
• UNIX Inetd “super server”
• CORBA Implementation Repository
• Android ActivityManagerService

ActivityManagerService
bindService()
Client 1
ServiceMap
mServicesByNamePerUser

mServicesByIntentPerUser

2 Process.start()

3
someMethodCall()
4 Service

35
Android Services & Local IPC Douglas C. Schmidt

Summary

• Activator frees clients from the responsibility of (re)activating the resources


they use
• It appears to them as if all resources were always (virtually) available

36
Android Services & Local IPC Douglas C. Schmidt

Summary

• Activator frees clients from the responsibility of (re)activating the resources


they use
• Activator also ensures that (re)activating a resource incurs minimal overhead
because it maintains information about how to optimize this process
• e.g., an activator could reload the resource’s persistent state & reacquire
the needed computing resources in parallel, thereby speeding resource
initialization

37
www.dre.vanderbilt.edu/~schmidt/PDF/Activator.pdf has more info

You might also like