architectural pattern: interceptor

8
Architectural pattern: Interceptor Source: POSA II pp 109 – 140 • Environment: developing frameworks that can be extended transparently • Recurring problem: – Frameworks cannot anticipate all of the services they will need – The benefit of a framework is lost if new services have to be implemented by applications

Upload: ramona-may

Post on 30-Dec-2015

22 views

Category:

Documents


0 download

DESCRIPTION

Architectural pattern: Interceptor. Source: POSA II pp 109 – 140 Environment: developing frameworks that can be extended transparently Recurring problem: Frameworks cannot anticipate all of the services they will need - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Architectural pattern: Interceptor

Architectural pattern: Interceptor

• Source: POSA II pp 109 – 140

• Environment: developing frameworks that can be extended transparently

• Recurring problem: – Frameworks cannot anticipate all of the services

they will need– The benefit of a framework is lost if new

services have to be implemented by applications

Page 2: Architectural pattern: Interceptor

Requirements for extensibility

• Add a service without requiring modifications to the framework’s core architecture

• Adding application-specific services should not break existing components or applications

• Applications using a framework may need to monitor and control its behavior

Page 3: Architectural pattern: Interceptor

Examples of framework services that might use such an extension

mechanism• Security

• Event logging

• Load balancing

• Transaction management

Page 4: Architectural pattern: Interceptor

(Core of a) solution - interceptors• Interceptor interfaces provide hooks that

can call service code when certain events occur– Event example: arrival of a client request

• Dispatchers manage the concrete interceptors registered for framework events

• Context objects provide access to event information and the framework’s internal state and behavior

Page 5: Architectural pattern: Interceptor

Dynamics1. Application instantiates a concrete interceptor

and registers it with the appropriate dispatcher2. Framework receives an event3. Framework passes a context object to the

dispatcher for that type of event4. Dispatcher calls registered interceptors in the

appropriate order, passing the context object5. Interceptors do their thing, using the context

object for event data and methods to control certain aspects of the framework’s behavior

Page 6: Architectural pattern: Interceptor

Implementation1. Model framework’s internal behavior2. Identify and model interception points3. Specify context objects4. Specify the interceptors5. Specify the dispatchers

• Registration interface• Callback interface

6. Implement callback mechanisms7. Implement concrete interceptors

Page 7: Architectural pattern: Interceptor

Known uses

• Component-based application servers– EJB, CORBA components, COM+

• CORBA ORBs

• Web browsers– Plug-ins are concrete interceptors

• Non-software: paper mail forwarding

Page 8: Architectural pattern: Interceptor

Consequences• Benefits

– Extensibility and flexibility– Separation of concerns– Support for monitoring and control– Layer symmetry– Reuse of interceptors across applications

• Liabilities– Complex design issues– Malicious or erroneous interceptors– Risk of interception cascades