Software Patterns - F04 Asynchronous Completion Token 1.

17
Software Pattern Software Pattern s - F04 s - F04 Asynchronous Completion Asynchronous Completion Token Token 1 Asynchronous Asynchronous Completion Token Completion Token
  • date post

    22-Dec-2015
  • Category

    Documents

  • view

    242
  • download

    1

Transcript of Software Patterns - F04 Asynchronous Completion Token 1.

Page 1: Software Patterns - F04 Asynchronous Completion Token 1.

Software Patterns - F04Software Patterns - F04 Asynchronous Completion TokenAsynchronous Completion Token 11

Asynchronous Asynchronous Completion TokenCompletion Token

Page 2: Software Patterns - F04 Asynchronous Completion Token 1.

Software Patterns - F04Software Patterns - F04 Asynchronous Completion TokenAsynchronous Completion Token 22

ContextContext

An event-driven system in which An event-driven system in which applications invoke operations applications invoke operations asynchronously on services and asynchronously on services and subsequently process the associated subsequently process the associated service completion event response.service completion event response.

Page 3: Software Patterns - F04 Asynchronous Completion Token 1.

Software Patterns - F04Software Patterns - F04 Asynchronous Completion TokenAsynchronous Completion Token 33

DefinitionsDefinitions

SynchronousSynchronous

BlockingBlocking

MultiplexMultiplex

AsynchronousAsynchronous

Non-blockingNon-blocking

DemultiplexDemultiplex

Page 4: Software Patterns - F04 Asynchronous Completion Token 1.

Software Patterns - F04Software Patterns - F04 Asynchronous Completion TokenAsynchronous Completion Token 44

ProblemProblem

Initiator invokes an operation request Initiator invokes an operation request asynchronously on one or more services, that asynchronously on one or more services, that returns its response via a completion event.returns its response via a completion event.

For each completion event the initiator performs For each completion event the initiator performs the appropriate action to process the result of the appropriate action to process the result of the operation.the operation.

There must be a demultiplexing mechanism to There must be a demultiplexing mechanism to associate service response with the action associate service response with the action performed by the initiator.performed by the initiator.

Page 5: Software Patterns - F04 Asynchronous Completion Token 1.

Software Patterns - F04Software Patterns - F04 Asynchronous Completion TokenAsynchronous Completion Token 55

SynopsisSynopsis

The The Asynchronous Completion TokenAsynchronous Completion Token design pattern allows an application to design pattern allows an application to demultiplex and process demultiplex and process efficientlyefficiently the the response of asynchronous operations it response of asynchronous operations it invoke on services.invoke on services.

Also known as:Also known as:

Active Demultiplexing, Magic CookieActive Demultiplexing, Magic Cookie

Page 6: Software Patterns - F04 Asynchronous Completion Token 1.

Software Patterns - F04Software Patterns - F04 Asynchronous Completion TokenAsynchronous Completion Token 66

ExampleExampleElectronic Medical Imaging SystemElectronic Medical Imaging System

Single HostSingle Host Multiple HostsMultiple Hosts

Page 7: Software Patterns - F04 Asynchronous Completion Token 1.

Software Patterns - F04Software Patterns - F04 Asynchronous Completion TokenAsynchronous Completion Token 77

Common Traps and PitfallsCommon Traps and Pitfalls

Spawn new thread for each requestSpawn new thread for each request• Increased complexityIncreased complexity• Poor performancePoor performance• Lack of portabilityLack of portability

Service provide sufficient info in eventService provide sufficient info in event• Excessive bandwidthExcessive bandwidth• Lack of contextLack of context• Performance degradationPerformance degradation

Page 8: Software Patterns - F04 Asynchronous Completion Token 1.

Software Patterns - F04Software Patterns - F04 Asynchronous Completion TokenAsynchronous Completion Token 88

ForcesForces

Initiator and not the service should be Initiator and not the service should be responsible for determining how the responsible for determining how the completion events are demultiplexed.completion events are demultiplexed.

Minimizing communication overhead is Minimizing communication overhead is important.important.

Spend as little time as possible Spend as little time as possible demultiplexing the completion event to the demultiplexing the completion event to the handler.handler.

Page 9: Software Patterns - F04 Asynchronous Completion Token 1.

Software Patterns - F04Software Patterns - F04 Asynchronous Completion TokenAsynchronous Completion Token 99

SolutionSolution

With every asynchronous operation that a With every asynchronous operation that a client invokes on a service, transmit client invokes on a service, transmit information that identifies how the initiator information that identifies how the initiator should process the services response.should process the services response.

The service returns the information to the The service returns the information to the client, allowing it to efficiently demultiplex client, allowing it to efficiently demultiplex and process the response.and process the response.

Page 10: Software Patterns - F04 Asynchronous Completion Token 1.

Software Patterns - F04Software Patterns - F04 Asynchronous Completion TokenAsynchronous Completion Token 1010

StructureStructure

ServiceService• Provide asynchronous Provide asynchronous

functionalityfunctionality

InitiatorInitiator• Invokes operations on services Invokes operations on services

asynchronouslyasynchronously• Defines completion handlersDefines completion handlers

Completion HandlerCompletion Handler• Defines an interface for Defines an interface for

processing the resultsprocessing the results

Asynchronous Completion Asynchronous Completion Token (ACT)Token (ACT)

• Identifies the completion Identifies the completion handlerhandler

Page 11: Software Patterns - F04 Asynchronous Completion Token 1.

Software Patterns - F04Software Patterns - F04 Asynchronous Completion TokenAsynchronous Completion Token 1111

DynamicsDynamics

Page 12: Software Patterns - F04 Asynchronous Completion Token 1.

Software Patterns - F04Software Patterns - F04 Asynchronous Completion TokenAsynchronous Completion Token 1212

Implementation DetailsImplementation DetailsInteresting…Interesting…

Define ACT representationDefine ACT representation• Pointer ACTsPointer ACTs• Object reference ACTsObject reference ACTs• Index ACTsIndex ACTs

Holding ACTs at the initiatorHolding ACTs at the initiator• Implicit Implicit • ExplicitExplicit

Page 13: Software Patterns - F04 Asynchronous Completion Token 1.

Software Patterns - F04Software Patterns - F04 Asynchronous Completion TokenAsynchronous Completion Token 1313

Implementation DetailsImplementation DetailsNot so interesting…Not so interesting…

How to pass the ACTs ?How to pass the ACTs ? Holding ACTs at the service ?Holding ACTs at the service ? Strategy for demultiplexing ACTs ?Strategy for demultiplexing ACTs ? How often can an ACT be used ?How often can an ACT be used ?

What if we have a chain of services?What if we have a chain of services?

Page 14: Software Patterns - F04 Asynchronous Completion Token 1.

Software Patterns - F04Software Patterns - F04 Asynchronous Completion TokenAsynchronous Completion Token 1414

BenefitsBenefits

Simplified initiator data structuresSimplified initiator data structures Time efficient demultiplexingTime efficient demultiplexing Space efficient demultiplexingSpace efficient demultiplexing Flexible (use what you want as an ACT)Flexible (use what you want as an ACT) Initiators can be single-threaded or multi-Initiators can be single-threaded or multi-

threadedthreaded

Page 15: Software Patterns - F04 Asynchronous Completion Token 1.

Software Patterns - F04Software Patterns - F04 Asynchronous Completion TokenAsynchronous Completion Token 1515

LiabilitiesLiabilities

Memory leaksMemory leaks Authentication of ACTsAuthentication of ACTs Application re-mappingApplication re-mapping

Page 16: Software Patterns - F04 Asynchronous Completion Token 1.

Software Patterns - F04Software Patterns - F04 Asynchronous Completion TokenAsynchronous Completion Token 1616

Known UsesKnown Uses

HTTP-CookieHTTP-Cookie• Server as initiator, browser as serviceServer as initiator, browser as service

OS asynchronous I/OOS asynchronous I/O• Windows NTWindows NT• POSIXPOSIX

CORBA demultiplexingCORBA demultiplexing JINIJINI FedEx inventory trackingFedEx inventory tracking

• Write a note for yourself on your notification when the Write a note for yourself on your notification when the transaction has completedtransaction has completed

Page 17: Software Patterns - F04 Asynchronous Completion Token 1.

Software Patterns - F04Software Patterns - F04 Asynchronous Completion TokenAsynchronous Completion Token 1717

Questions ?Questions ?