Acceptor – Connector Pattern

Download Report

Transcript Acceptor – Connector Pattern

Pattern Oriented Software
Architecture
for Networked Objects
Based on the book
By
Douglas Schmidt
Michael Stal
Hans Roehnert
Frank Buschmann
Scope of application of patterns
for Networking and Distributed Systems
• Applications to “middleware” development.
• Applications to higher and lower-level systems and
applications not based directly on middleware.
• As hardware capacity and sophistication increases, software
needs to keep up.
• Decrease complexity of the process of software development
for complex networks and services.
• Continuous reinvention of core concepts leads to changes in
the underlying software components.
• Object – oriented approach leads to the modular approach
and faster development.
Four important aspects of Networked
Application Development
Service Access and Configuration
-Effectively design and configure application access to the
system interface and implementation of evolving service components.
Wrapper Façade Pattern – This design pattern shields the developer
from having to interface with the low level system specific functions.
Component Configurator Pattern – This allows the for the dynamic
initialization and stopping of services/components.
Interceptor Pattern – Allows for the handling of unexpected events
into the software framework so that responses to these events can be
handled at run – time.
Extension Interface – This allows for the addition of extra interfaces
into the applications without affecting applications itself.
Wrapper Façade Pattern
Server
1.socket();6)thre_cre();
2.bind();
3.listen();
5.accept();
Handle Factory
Client
8.recv();
9.write();
Logging
Handler
4)connect();
send();
Prototype for short throw-away types of applications
CRC card for Wrapper Façade Class
Class
Wrapper Facade
Responsibilty
Encapsulates
non-object functions
And data structures
with a cohesive objectoriented abstraction
Collaborator
-API Functions
Application using Wrapper Façade
sequence diagram
Known Uses
of Wrapper Façade
• ACE – This is a set of C++ classes which allow the user
to use/extend low-level system API’s.
• JVM and class libraries – These use the low – level
system API’s .The JVM itself is a Wrapper Façade.
• A simple book organization system – Individual papers
and books are organized into various “themes” so that the
collection can be easily accessible.
Event Handling
-It is important to have efficient event-driven applications. Two
patterns which help achieve this are :
Reactor pattern :- Allows event-driven applications to
demultiplex and dispatch service requests from clients.
Acceptor – Connector Design pattern:- Decouples the
connection and initialization of co-operating services from
the processing done by the services after they are connected
and initialized.
Acceptor – Connector Pattern
Problem
-How to separate initialization and connection
establishment from service behavior.
Solution
-An Acceptor waits for connection requests and
dispatches them to a reactor.
-A Connector initiates connection with servers and
dispatches replies to a Reactor.
- Acceptor and Connector decouple passive and active
roles during service initialization.
CRC cards for Acceptor – Connector pattern
Class
Acceptor
Responsibility
-Passively
connects and
initializes an
associated service
Handler.
Collaborator
-Service handler.
-Dispatcher
- Transport
Endpoint
Class
Connector
Responsibility
-Actively
connects and
initializes an
associated service
Handler.
Class
Reactor
Responsibility
-Registers and removes
event handlers and their
Handles.
-Runs the applications event
loop.
Collaborator
-Handle set.
-Event Handlers.
-Event Demultiplexer.
Collaborator
-Service handler.
-Dispatcher
- Transport
Endpoint
Acceptor Sequence Diagram
Connector pattern
Acceptor – Connector pattern
•Acceptor-Connector is one of the most important of design patterns.
• Provides reusability – Strict separation of connection handling
ensures passive/active connection establishment procedures to be
written once and run in any framework.
• Efficiency – Can be used to establish connections with a large
number of hosts asynchronously and efficiently over long-latency
wide area networks.
Uses
1)Web-browsers.
2) JACE – Java ACE has built – in Acceptors , Connectors
and SvcHandlers to implements core aspects of the Acceptor – Connector
pattern.
3) Real-life examples such as managers communicating
through their secretaries . Secretaries act as acceptors/connectors , while
Managers act as service handlers.
Putting it all together
in
The ACE Framework
Concurrency Patterns
Patterns of Interest
Half-Sync/Half-Async – Decouples synchronous and asynchronous
service processing in concurrent systems.
Monitor Object – Synchronizes concurrent method execution to ensure
that only one method at time runs within an object . This also helps in
scheduling processes. Eg – Readers/Writers problem.
Half-Sync/Half – Async Pattern
Problem
Two forces to be resolved during the software development process
1)
Synchronous processing simplicity and asynchronous processing complexity (and
efficiency)
2)
Architectures must be able to exploit both the
efficiency of asynchronous operations and the simplicity of synchronous
operations.
Solution
•
Separate synchronous and asynchronous layers. Synchronous operations such as
file transfers ,write() and read() operations are done in the synchronous layers.
•
If these two layers need to communicate , then they do so through messages that
are queued up in the queuing layer
Synch Service layer
Synch Service 1
Queueing layer
Asynch Service
layer
Synch Service 2
Synch Service 3
Queue
Async Service
External Event
Source
Synchronization Patterns
Strategized Locking – Parameterized synchronization patterns
that protect a component’s critical sections from concurrent
access.
Uses – File cache access. Eg . File access may be required by
many applications at once. Many applications may require
access to the file cache. The component (file cache) must
contain multiple synchronization mechanisms to support
various applications that implement different synchronization
primitives.
CRC cards
• CRC cards are a method to simplify objectoriented programming
• Each card explains a class ,its
responsibilities and its collaborators.
• Each member of the design team has a card
or a set of cards for which he/she is
responsible.
Important links for Networking patterns
ACE – The Adaptive Communications Environment
- http://www.cs.wustl.edu/~schmidt/ACE.html
JACE ( JAVA ACE) – A set of reusable classes which are widely used for the
development of networking software.
- http://www.cs.wustl.edu/~schmidt/ACE-overview.html
Documentation - http://www.cs.wustl.edu/~schmidt/ACE-documentation.html
ACE applied to CORBA – A description and few tutorials on the ACE appiled to ORB
- http://www.cs.wustl.edu/~schmidt/TAO.html
To Summarize
•Patterns help in tapping the knowledge of software
development .
• Patterns applied to networking simplify the process of
software development.
Further developments
Patterns can be combined together to give pattern languages
eg . Reactor – Acceptor – Connector.
Reactor
Active Object
Acceptor-Connector
Monitor Object
Conclusion contd..
Pattern languages ??
•A pattern language guides a designer by providing workable
solutions to all of the problems known to arise in the course of
design.
•A solution is arrived at by combining a set of patterns to solve
commonly encountered problem.
•Alternatively ,if we observe a set of patterns being always used in a
particular context ,then we can say that we have a pattern language
for that context.
•An example of applying pattern languages (using AcceptorConnector-Reactor) for solving a class of problems (network
routing) is described here.
http://www.cs.wustl.edu/~schmidt/PDF/TAPOS-00.pdf