SlideShare una empresa de Scribd logo
1 de 11
Architectural Patterns
[PART 4]
(Concurrency Pattern)

Based on
Pattern-Oriented Software Architecture, Patterns for Concurrent and
Networked Objects, Volume 2
by Douglas Schmidt, Michael Stal, Hans Rohnert and Frank Buschmann
Active Object
It decouples method execution from method invocation to enhance concurrency and simplify
synchronized access to objects that reside in their own thread of control.
Components –
Proxy – Resides in client thread . It provides an interface that allows clients to invoke publicly
accessible methods on an active object.
Client – It invokes public methods provided by proxy which in turn creates method request
object . when client invokes a method on a proxy, it receives a future. Each future reserves space
for the invoked method to store its result. The future allows the client to obtain the result of the
method invocation after the servant finishes executing the method.
Method Request object - It provides an interface for executing the methods of an active object.
This interface also contains guard methods that can be used to determine when a method
request can be executed
Activation list – proxy updated the list to keep track of pending method requests created by the
proxy and which method requests can execute.
Scheduler - It runs in the active object's thread. It decides which method request to execute next
on an active object. It scheduler uses the activation list to manage method requests that are
pending execution.
Servant – It defines methods correspond to the interface of the proxy and method requests the
proxy creates. It may also contain other predicate methods that method requests can use to
implement their guards. The servant method is executed on the active object.
Active Object
Implimentation –
Half-Sync/Half-Async
This pattern decouples asynchronous and synchronous service processing in
concurrent systems without reducing efficiency.
Decompose services in the system into two layers (synchronous and
asynchronous) and add a queuing layer between them to mediate the
communication between services in the asynchronous and synchronous
layers.

Components:
Synchronous service layer - Services in this layer run in separate threads or
processes that can block while performing operations.(e.g. ftp, telnet)
Asynchronous service layer - Services in this layer performs lower-level
processing services and cannot block while performing operations. (e.g.
Hardware interrupts)
Queuing layer - It is responsible for notifying services in one layer when
messages are passed to them from the other layer.
Half-Sync/Half-Async
External event sources - Generate events that are received and processed by
the asynchronous service layer (e.g. end-user terminal, disk controllers)
Asynchronous interrupts strategy - when an event occurs on an external
event source, an interrupt notifies the handler associated with the event,
which then processes the event to completion.
Proactive I/O strategy - I/O operations are executed by an asynchronous
operation processor. When an asynchronous operation finishes, the
asynchronous operation processor generates a completion event. This event
is then dispatched to the handler associated with the event, which processes
the event to completion.
Services in the asynchronous and synchronous layers can exchange messages
via queuing layer. This queuing layer buffers messages so that synchronous
and asynchronous services can run concurrently.
Notification strategy - It may be required to notify a service in one layer when
messages addressed to it arrive from another layer.
Leader/Followers
This pattern provides an efficient concurrency model where multiple threads
take turns sharing a set of event sources in order to detect, demultiplex,
dispatch, and process service requests that occur on the event sources
A pool of threads shares a set of event sources efficiently by taking turns,
demultiplexing events that arrive on these event sources and synchronously
dispatching the events to application services that process them.

Components Handle set - It is a collection of handles that can be used to wait for one or
more events to occur on handles in the set. A handle set returns to its
caller when it is possible to initiate an operation on a handle in the set
without the operation blocking.
event handlers - They implement the hook method(s) responsible for
processing events received from a handle
Leader/Followers
Thread pool – Threads that take turns playing three roles.
Leader role - The leader thread waits for an event to occur on any handle in
the handle set. If there is no current leader thread available, the underlying
operating system can queue events internally until a leader thread is
available.
Follower role - After the leader thread has detected a new event, it uses the
thread pool to choose a follower thread to become the new leader.
Processing role - This thread concurrently demultiplexes the event it detected
to the event's associated handler and then dispatches the handler's hook
method to process the event. After the processing thread has run its event
handling to completion, it can rejoin the thread pool.
Leader/Followers
Implementation –
Leader
Thread

Follower
Thread

Thread Set

Concrete
Event
Handler

Handle Set

Join()
Become new leader
Join()

wait_for_event()
wait
Event
promote_new_leader()
Become new leader
handle_event()
wait_for_event()

select
Thread-Specific Storage
This pattern allows multiple threads to use one 'logically global' access point
to retrieve an object that is local to a thread—called a 'threadspecific
object'—without incurring locking overhead for each access to the object.
Components thread-specific object - It is an instance of an object that can be accessed
only by a particular thread (e.g. errno)
key factory - Keys generated by the key factory are assigned from a single
range of values to ensure that each thread-specific object is 'logically' global.
thread-specific object set – it contains the collection of thread-specific
objects that are associated with a particular thread. (e.g. OS threads library
implements the thread-specific object set that contains the errno data)
thread-specific object proxy - It can be defined to enable clients to access a
specific type of thread-specific object.(e.g. errno is implemented as a
preprocessor macro that plays the role of the proxy )
Application threads are clients that use thread-specific object proxies to
access particular thread-specific objects that reside in thread-specific storage
Thread-Specific Storage
Implementation ThreadSpecific
Object Set

Thread –
Specific
Object Proxy

Application
Thread
Method()

Key

get()

TSObject
Result
Result

ThreadSpecific
Object

Method()
Thank You

Your suggestions and comments are always welcome.
Please send me your feedback at
a_s_sinha@yahoo.com

Más contenido relacionado

La actualidad más candente

Chain of Responsibility Pattern
Chain of Responsibility PatternChain of Responsibility Pattern
Chain of Responsibility PatternHüseyin Ergin
 
Context-Oriented Programming: Beyond Layers
Context-Oriented Programming: Beyond LayersContext-Oriented Programming: Beyond Layers
Context-Oriented Programming: Beyond LayersESUG
 
Java Components and their applicability in Mule Anypoint Studio
Java Components and their applicability in Mule Anypoint StudioJava Components and their applicability in Mule Anypoint Studio
Java Components and their applicability in Mule Anypoint StudioVenkataNaveen Kumar
 
Threads And Synchronization in C#
Threads And Synchronization in C#Threads And Synchronization in C#
Threads And Synchronization in C#Rizwan Ali
 
Threads and Synchronization in c#
Threads and Synchronization in c#Threads and Synchronization in c#
Threads and Synchronization in c#Rizwan Ali
 
Concurrency Programming in Java - 06 - Thread Synchronization, Liveness, Guar...
Concurrency Programming in Java - 06 - Thread Synchronization, Liveness, Guar...Concurrency Programming in Java - 06 - Thread Synchronization, Liveness, Guar...
Concurrency Programming in Java - 06 - Thread Synchronization, Liveness, Guar...Sachintha Gunasena
 
Iterator Design Pattern
Iterator Design PatternIterator Design Pattern
Iterator Design PatternVarun Arora
 
Concurrency with java
Concurrency with javaConcurrency with java
Concurrency with javaHoang Nguyen
 
Command Design Pattern
Command Design PatternCommand Design Pattern
Command Design PatternShahriar Hyder
 
Design patterns - Singleton&Command
Design patterns - Singleton&CommandDesign patterns - Singleton&Command
Design patterns - Singleton&CommandKai Aras
 
iiwas 2010
iiwas 2010iiwas 2010
iiwas 2010steccami
 
Concurrent programming with Agents
Concurrent programming with AgentsConcurrent programming with Agents
Concurrent programming with AgentsTomas Petricek
 

La actualidad más candente (16)

Chain of Responsibility Pattern
Chain of Responsibility PatternChain of Responsibility Pattern
Chain of Responsibility Pattern
 
Context-Oriented Programming: Beyond Layers
Context-Oriented Programming: Beyond LayersContext-Oriented Programming: Beyond Layers
Context-Oriented Programming: Beyond Layers
 
Java Components and their applicability in Mule Anypoint Studio
Java Components and their applicability in Mule Anypoint StudioJava Components and their applicability in Mule Anypoint Studio
Java Components and their applicability in Mule Anypoint Studio
 
Threads And Synchronization in C#
Threads And Synchronization in C#Threads And Synchronization in C#
Threads And Synchronization in C#
 
Mule expression
Mule expressionMule expression
Mule expression
 
C# Thread synchronization
C# Thread synchronizationC# Thread synchronization
C# Thread synchronization
 
Threads and Synchronization in c#
Threads and Synchronization in c#Threads and Synchronization in c#
Threads and Synchronization in c#
 
Concurrency Programming in Java - 06 - Thread Synchronization, Liveness, Guar...
Concurrency Programming in Java - 06 - Thread Synchronization, Liveness, Guar...Concurrency Programming in Java - 06 - Thread Synchronization, Liveness, Guar...
Concurrency Programming in Java - 06 - Thread Synchronization, Liveness, Guar...
 
Iterator Design Pattern
Iterator Design PatternIterator Design Pattern
Iterator Design Pattern
 
Mule java part-4
Mule java part-4Mule java part-4
Mule java part-4
 
Concurrency with java
Concurrency with javaConcurrency with java
Concurrency with java
 
Command Design Pattern
Command Design PatternCommand Design Pattern
Command Design Pattern
 
Design patterns - Singleton&Command
Design patterns - Singleton&CommandDesign patterns - Singleton&Command
Design patterns - Singleton&Command
 
React hooks
React hooksReact hooks
React hooks
 
iiwas 2010
iiwas 2010iiwas 2010
iiwas 2010
 
Concurrent programming with Agents
Concurrent programming with AgentsConcurrent programming with Agents
Concurrent programming with Agents
 

Similar a Architectural patterns part 4

seminarembedded-150504150805-conversion-gate02.pdf
seminarembedded-150504150805-conversion-gate02.pdfseminarembedded-150504150805-conversion-gate02.pdf
seminarembedded-150504150805-conversion-gate02.pdfkarunyamittapally
 
Java Advance Concepts
Java Advance ConceptsJava Advance Concepts
Java Advance ConceptsEmprovise
 
2. Distributed Systems Hardware & Software concepts
2. Distributed Systems Hardware & Software concepts2. Distributed Systems Hardware & Software concepts
2. Distributed Systems Hardware & Software conceptsPrajakta Rane
 
Process Synchronization And Deadlocks
Process Synchronization And DeadlocksProcess Synchronization And Deadlocks
Process Synchronization And Deadlockstech2click
 
characteristicsofdistributedsystem-121004123308-phpapp02.ppt
characteristicsofdistributedsystem-121004123308-phpapp02.pptcharacteristicsofdistributedsystem-121004123308-phpapp02.ppt
characteristicsofdistributedsystem-121004123308-phpapp02.pptRamkumardevendiranDe
 
Cloud 2010
Cloud 2010Cloud 2010
Cloud 2010steccami
 
Lesson10 behavioral patterns
Lesson10 behavioral patternsLesson10 behavioral patterns
Lesson10 behavioral patternsOktJona
 
DS R16 - UNIT-3.pdf
DS R16 - UNIT-3.pdfDS R16 - UNIT-3.pdf
DS R16 - UNIT-3.pdfVarshaBaini
 
Multithreading Presentation
Multithreading PresentationMultithreading Presentation
Multithreading PresentationNeeraj Kaushik
 

Similar a Architectural patterns part 4 (20)

Tech talk
Tech talkTech talk
Tech talk
 
Java Tutorials - Concurrency
Java Tutorials - ConcurrencyJava Tutorials - Concurrency
Java Tutorials - Concurrency
 
Remoting and serialization
Remoting and serializationRemoting and serialization
Remoting and serialization
 
Real Time Operating Systems
Real Time Operating SystemsReal Time Operating Systems
Real Time Operating Systems
 
seminarembedded-150504150805-conversion-gate02.pdf
seminarembedded-150504150805-conversion-gate02.pdfseminarembedded-150504150805-conversion-gate02.pdf
seminarembedded-150504150805-conversion-gate02.pdf
 
Dot NET Remoting
Dot NET RemotingDot NET Remoting
Dot NET Remoting
 
MultiThreading in Python
MultiThreading in PythonMultiThreading in Python
MultiThreading in Python
 
Java Advance Concepts
Java Advance ConceptsJava Advance Concepts
Java Advance Concepts
 
2. Distributed Systems Hardware & Software concepts
2. Distributed Systems Hardware & Software concepts2. Distributed Systems Hardware & Software concepts
2. Distributed Systems Hardware & Software concepts
 
Process Synchronization And Deadlocks
Process Synchronization And DeadlocksProcess Synchronization And Deadlocks
Process Synchronization And Deadlocks
 
Operating system
Operating systemOperating system
Operating system
 
R1x g13 4 diagrams i
R1x g13 4 diagrams iR1x g13 4 diagrams i
R1x g13 4 diagrams i
 
characteristicsofdistributedsystem-121004123308-phpapp02.ppt
characteristicsofdistributedsystem-121004123308-phpapp02.pptcharacteristicsofdistributedsystem-121004123308-phpapp02.ppt
characteristicsofdistributedsystem-121004123308-phpapp02.ppt
 
Cloud 2010
Cloud 2010Cloud 2010
Cloud 2010
 
shashank_micro92_00697015
shashank_micro92_00697015shashank_micro92_00697015
shashank_micro92_00697015
 
Akka framework
Akka frameworkAkka framework
Akka framework
 
Lesson10 behavioral patterns
Lesson10 behavioral patternsLesson10 behavioral patterns
Lesson10 behavioral patterns
 
Hibernate3 q&a
Hibernate3 q&aHibernate3 q&a
Hibernate3 q&a
 
DS R16 - UNIT-3.pdf
DS R16 - UNIT-3.pdfDS R16 - UNIT-3.pdf
DS R16 - UNIT-3.pdf
 
Multithreading Presentation
Multithreading PresentationMultithreading Presentation
Multithreading Presentation
 

Más de assinha

Nwe Embodiment (Naba Kalebara) of Lord Jagannath of PURI - The Greatest and B...
Nwe Embodiment (Naba Kalebara) of Lord Jagannath of PURI - The Greatest and B...Nwe Embodiment (Naba Kalebara) of Lord Jagannath of PURI - The Greatest and B...
Nwe Embodiment (Naba Kalebara) of Lord Jagannath of PURI - The Greatest and B...assinha
 
SNMP AT a GLANCE
SNMP AT a GLANCESNMP AT a GLANCE
SNMP AT a GLANCEassinha
 
Layer3protocols
Layer3protocolsLayer3protocols
Layer3protocolsassinha
 
Umts explained
Umts explainedUmts explained
Umts explainedassinha
 
Architectural patterns part 1
Architectural patterns part 1Architectural patterns part 1
Architectural patterns part 1assinha
 
Data Structures used in Linux kernel
Data Structures used in Linux kernel Data Structures used in Linux kernel
Data Structures used in Linux kernel assinha
 
E nodeb handover procedure
E nodeb handover procedureE nodeb handover procedure
E nodeb handover procedureassinha
 
Initial LTE call Setup Flow
Initial LTE call Setup FlowInitial LTE call Setup Flow
Initial LTE call Setup Flowassinha
 

Más de assinha (8)

Nwe Embodiment (Naba Kalebara) of Lord Jagannath of PURI - The Greatest and B...
Nwe Embodiment (Naba Kalebara) of Lord Jagannath of PURI - The Greatest and B...Nwe Embodiment (Naba Kalebara) of Lord Jagannath of PURI - The Greatest and B...
Nwe Embodiment (Naba Kalebara) of Lord Jagannath of PURI - The Greatest and B...
 
SNMP AT a GLANCE
SNMP AT a GLANCESNMP AT a GLANCE
SNMP AT a GLANCE
 
Layer3protocols
Layer3protocolsLayer3protocols
Layer3protocols
 
Umts explained
Umts explainedUmts explained
Umts explained
 
Architectural patterns part 1
Architectural patterns part 1Architectural patterns part 1
Architectural patterns part 1
 
Data Structures used in Linux kernel
Data Structures used in Linux kernel Data Structures used in Linux kernel
Data Structures used in Linux kernel
 
E nodeb handover procedure
E nodeb handover procedureE nodeb handover procedure
E nodeb handover procedure
 
Initial LTE call Setup Flow
Initial LTE call Setup FlowInitial LTE call Setup Flow
Initial LTE call Setup Flow
 

Último

Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 

Último (20)

INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 

Architectural patterns part 4

  • 1. Architectural Patterns [PART 4] (Concurrency Pattern) Based on Pattern-Oriented Software Architecture, Patterns for Concurrent and Networked Objects, Volume 2 by Douglas Schmidt, Michael Stal, Hans Rohnert and Frank Buschmann
  • 2. Active Object It decouples method execution from method invocation to enhance concurrency and simplify synchronized access to objects that reside in their own thread of control. Components – Proxy – Resides in client thread . It provides an interface that allows clients to invoke publicly accessible methods on an active object. Client – It invokes public methods provided by proxy which in turn creates method request object . when client invokes a method on a proxy, it receives a future. Each future reserves space for the invoked method to store its result. The future allows the client to obtain the result of the method invocation after the servant finishes executing the method. Method Request object - It provides an interface for executing the methods of an active object. This interface also contains guard methods that can be used to determine when a method request can be executed Activation list – proxy updated the list to keep track of pending method requests created by the proxy and which method requests can execute. Scheduler - It runs in the active object's thread. It decides which method request to execute next on an active object. It scheduler uses the activation list to manage method requests that are pending execution. Servant – It defines methods correspond to the interface of the proxy and method requests the proxy creates. It may also contain other predicate methods that method requests can use to implement their guards. The servant method is executed on the active object.
  • 4. Half-Sync/Half-Async This pattern decouples asynchronous and synchronous service processing in concurrent systems without reducing efficiency. Decompose services in the system into two layers (synchronous and asynchronous) and add a queuing layer between them to mediate the communication between services in the asynchronous and synchronous layers. Components: Synchronous service layer - Services in this layer run in separate threads or processes that can block while performing operations.(e.g. ftp, telnet) Asynchronous service layer - Services in this layer performs lower-level processing services and cannot block while performing operations. (e.g. Hardware interrupts) Queuing layer - It is responsible for notifying services in one layer when messages are passed to them from the other layer.
  • 5. Half-Sync/Half-Async External event sources - Generate events that are received and processed by the asynchronous service layer (e.g. end-user terminal, disk controllers) Asynchronous interrupts strategy - when an event occurs on an external event source, an interrupt notifies the handler associated with the event, which then processes the event to completion. Proactive I/O strategy - I/O operations are executed by an asynchronous operation processor. When an asynchronous operation finishes, the asynchronous operation processor generates a completion event. This event is then dispatched to the handler associated with the event, which processes the event to completion. Services in the asynchronous and synchronous layers can exchange messages via queuing layer. This queuing layer buffers messages so that synchronous and asynchronous services can run concurrently. Notification strategy - It may be required to notify a service in one layer when messages addressed to it arrive from another layer.
  • 6. Leader/Followers This pattern provides an efficient concurrency model where multiple threads take turns sharing a set of event sources in order to detect, demultiplex, dispatch, and process service requests that occur on the event sources A pool of threads shares a set of event sources efficiently by taking turns, demultiplexing events that arrive on these event sources and synchronously dispatching the events to application services that process them. Components Handle set - It is a collection of handles that can be used to wait for one or more events to occur on handles in the set. A handle set returns to its caller when it is possible to initiate an operation on a handle in the set without the operation blocking. event handlers - They implement the hook method(s) responsible for processing events received from a handle
  • 7. Leader/Followers Thread pool – Threads that take turns playing three roles. Leader role - The leader thread waits for an event to occur on any handle in the handle set. If there is no current leader thread available, the underlying operating system can queue events internally until a leader thread is available. Follower role - After the leader thread has detected a new event, it uses the thread pool to choose a follower thread to become the new leader. Processing role - This thread concurrently demultiplexes the event it detected to the event's associated handler and then dispatches the handler's hook method to process the event. After the processing thread has run its event handling to completion, it can rejoin the thread pool.
  • 8. Leader/Followers Implementation – Leader Thread Follower Thread Thread Set Concrete Event Handler Handle Set Join() Become new leader Join() wait_for_event() wait Event promote_new_leader() Become new leader handle_event() wait_for_event() select
  • 9. Thread-Specific Storage This pattern allows multiple threads to use one 'logically global' access point to retrieve an object that is local to a thread—called a 'threadspecific object'—without incurring locking overhead for each access to the object. Components thread-specific object - It is an instance of an object that can be accessed only by a particular thread (e.g. errno) key factory - Keys generated by the key factory are assigned from a single range of values to ensure that each thread-specific object is 'logically' global. thread-specific object set – it contains the collection of thread-specific objects that are associated with a particular thread. (e.g. OS threads library implements the thread-specific object set that contains the errno data) thread-specific object proxy - It can be defined to enable clients to access a specific type of thread-specific object.(e.g. errno is implemented as a preprocessor macro that plays the role of the proxy ) Application threads are clients that use thread-specific object proxies to access particular thread-specific objects that reside in thread-specific storage
  • 10. Thread-Specific Storage Implementation ThreadSpecific Object Set Thread – Specific Object Proxy Application Thread Method() Key get() TSObject Result Result ThreadSpecific Object Method()
  • 11. Thank You Your suggestions and comments are always welcome. Please send me your feedback at a_s_sinha@yahoo.com