Download presentation
Presentation is loading. Please wait.
Published byLaura Horton Modified over 9 years ago
1
Interceptor CS562 Spring 2002 Jan 29 2002 Anand Krishnan Morgan Deters Venkita Subramonian
2
Discussion Topics Interceptor definition Motivating Examples Problem definition and solutions Implementation details Scope for Generic Programming Relationship with other patterns
3
Interceptor Architectural pattern Allows services to be transparently added to a framework Services triggered automatically when certain events occur
4
Problem –How to integrate out-of-band tasks with in-band tasks transparently ?
5
Example 1 – Java event model public class Demo extends JApplet { public void init() { bHandler = new ButtonHandler(); button = new JButton("Click Me"); getContentPane().add(button, BorderLayout.CENTER); button.addActionListener(bHandler); } public class ButtonHandler implements ActionListener void actionPerformed(ActionEvent e) { Toolkit.getDefaultToolkit().beep(); } Applet Framework Button clicked Action Listener Some action ActionEvent
6
Example 2 – Unix signals void catch_int(int sig_num) { signal(SIGINT, catch_int); printf("Don't do that"); fflush(stdout); } main() { ….. signal(SIGINT, catch_int); for ( ;; ) pause(); } OS Framework Ctrl + C signal handler Some action Signal info
7
Example 3 - Database Triggers CREATE TRIGGER print_salary_changes BEFORE UPDATE ON emp FOR EACH ROW WHEN (new.empno > 0) DECLARE sal_diff number; BEGIN sal_diff := new.sal - old.sal; dbms_output.put('Old salary: ' || :old.sal); dbms_output.put(' New salary: ' || :new.sal); dbms_output.put(' Difference ' || sal_diff); END; UPDATE emp SET sal = sal + 500.00 WHERE deptno = 10 Trigger will fire once for each row that is updated, and it prints the new and old salaries, and the difference. Database Framework Update Request Before Update Trigger After Update Trigger Result
8
Example 4 – CORBA ORB In-band tasks –Connection management with peer ORB –Request/reply marshaling/demarshaling –Demultiplexing requests to objects Out-of-band tasks –Added at interceptor points –Security, Fault Tolerance ORB Security Service Fault Tolerance Service
9
Solution Problem –How to integrate out-of-band tasks with in-band tasks transparently ? Solution –Out-of-band tasks register with framework via specific interfaces get triggered by framework on certain events are provided access to framework internals via specific interfaces
10
UML Class Diagram implement * implement z4 Application Concrete Interceptor
11
UML Class Diagram implement * implement Application Concrete Interceptor
12
UML Class Diagram register implement * implement Application Concrete Interceptor Dispatcher
13
UML Class Diagram register implement * event / trigger implement Application Concrete Interceptor Dispatcher Concrete Framework
14
UML Class Diagram register instantiateimplement * event / trigger implement Application Concrete Interceptor Dispatcher Concrete Framework Context Object (CO)
15
UML Class Diagram register instantiateimplement * event / trigger * notify (CO) implement Application Concrete Interceptor Dispatcher Concrete Framework Context Object (CO)
16
UML Class Diagram register instantiateimplement * event / trigger * notify (CO) (CO) 1.. * implement Application Concrete Interceptor Dispatcher Concrete Framework Context Object (CO)
17
UML Class Diagram Application Concrete Interceptor Dispatcher Concrete Framework Context Object (CO)
18
Implementation Model Internal Behavior of Concrete Framework Identify and model interception points –Identify concrete framework state transitions –Partition interception points into reader / writer sets –Integrate them into state machine model –Partition them into disjoint interception groups Specify the context object –context object semantics –number of context object types –strategy for passing context objects to interceptors Per-registration / Per-event
19
Implementation Specify the interceptors Specify the dispatchers –interceptor registration interface –dispatcher callback interface Implement CallBack mechanisms in Concrete Framework Implement Concrete Interceptors
20
Interceptor Themes A priori knowledge of engineering context –Have you covered all the bases? Flexibility –How much influence can the Interceptor have? Performance –How simple can the Interceptor model be? "in-band" vs. "out-of-band“ –Are the concerns that Interceptors realize orthogonal?
21
Generic Interceptors? Templatization of context object? –Use context_traits to achieve compile-time negotiation of dispatcher & interceptor
22
Interceptors as a Language Construct Interception becomes 1 st class language concern Interception points are language constructs –Variable mutation, method execution, object instantiation, etc... Concrete Framework need not be specially prepared for extension –This is a major consequence Aspect-Oriented Programming (AOP)
23
Interceptors and AOP Join Points –Language constructs (execution/data, static/dynamic) –Correspond to interception points Aspect –Collection of (possibly abstract) Interceptors –Specifies the join points to operate on –Attach advice to a particular place in execution (or piece of data) in the system, reflectively reason about its place in the system
24
Interceptors as a Language Construct: Examples Component Configurator –Infrequently-used features (e.g., backward-compatible protocol support) can be loaded, unloaded without the application being aware of it Customization –Quality of Service –Fault-Tolerance
25
+ Separation of Concerns + (Future) Flexibility + Reusability/Portability − Efficiency/Heterogenity − Evil Interceptors Consequences
26
Interceptor Variants Bind Interceptor - Fault Tolerance Client Request Interceptor - Load Balancing Interceptor Proxy / Delegator - Customized Service Portable Interceptor Strategies –Single Interceptor Per Dispatcher –Interceptor Factory –Implicit Interceptor Registration Component Configurator Pattern similar (partly) to AOP -- AOP languages can differ load from a library at runtime, Concrete Framework creates the Interceptors
27
Relationships to Other Patterns Chain of Responsibility (single handler) Observer/Publisher-Subscriber (notification) Template Method (localized interception) –Interceptor reaches across multiple layers Pipes & Filters Reflection
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.