Monday, August 17, 2009

Pattern: InvocationContext Propagation

Another good name for this pattern might be ThreadLocal Encapsulation.

This pattern is a real ThreadLocal killer as it is a way to track state over several calls without widespread ThreadLocal usage.

Internally in OpenEJB we have managed to boil all our ThreadLocal usage down to this sort of "one to rule them all" approach. When attempting to describe it to a user I started using the javax.interceptor.InvocationContext as an example. The result was an ejb3 design pattern that is too cool not to share.

Add the following Interceptor as a global interceptor at the beginning of the interceptor stack.
The Interceptor uses a private ThreadLocal to propagate invocation state by linking the InvocationContext objects together. The result is that you can do an infinite amount of state tracking as well as write some pretty impressive diagnostic tools.

Anyone downstream of this interceptor can make a call like this to get access the an infinite amout of state up the stack. You can move specific state forward for quick access. You can also look infinitely back the invocation chain for state set in a previous InvocationContext. Or perhaps more elegantly as a recursive method. A JavaDoc'ed and ASL licensed version here: http://gist.github.com/168153

12 comments:

.:raPHa:. said...

Hi David, I am implementing an auditor for EJBs methods and need a solution like this to record the call stack between methods in enterprise application.
This mechanism is safe for concurrent calls?

Danish Ahmed said...

Thanks for sharing this article, now you can also check your Admit card & Recuritment 2017 by following below given links...

police si admit card 2017

gpsc medical officer admit card 2017

tamilnadu teacher recuritment 2017

bihar police constable recuritment 2017

gujarat high court recruitment 2017

Habib Malik said...

Karnataka TET Notification 2017-18
Jharkhand TET Notification 2017-18
HTET Notification 2017-18
HP TET Notification 2017-18

adidas nmd said...

nhl jerseys
cheap ray bans
oakley sunglasses wholesale
ralph lauren polo
fitflops sale clearance
nike blazer pas cher
christian louboutin shoes
cheap ray ban sunglasses
oakley sunglasses
nike outlet

Habib Malik said...

Feliz año nuevo 2018 Imágenes

Habib Malik said...

Odisha CHSE Date Sheet 2018
LNMU Date Sheet 2018
Kota University Date Sheet 2018
Allahabad University Date Sheet 2018
RMLAU Time Table 2018
MAHA Board HSC Date Sheet 2018
MAHA Board SSC Date Sheet 2018
Odisha Board HSC Date Sheet 2018

Habib Malik said...

Haryana TET Admit Card 2017
REET Admit Card 2018
Bank of Baroda Specialist Officer Admit Card 2018
JEE Main Admit Card 2018

Pankaj Sehoriya said...

airtel ussd code list
idea ussd code list
bsnl ussd code list
aircel ussd code list
vodafone ussd code list
jio ussd code list
telenor ussd code list
docomo ussd code list
airtel phone no check

Pankaj Sehoriya said...

docomo balance check codes
telenor balance check codes
airtel phone no check

vodafone balance check code
airtel balance check code

Pankaj Sehoriya said...

techmaniya
tutorialshubspot
ussd codes
bestpromarket
photographer in gurgaon
genxguys
graphics card under 100 dollar

Habib Malik said...

महात्मा गांधी राष्ट्रीय ग्रामीण रोजगार गारंटी अधिनियम (मनरेगा / MNREGA)

SWAMI AYYAPPA said...

are raspberries bad for dogs
can i give my dog raspberries
know more
can dogs eat red raspberries
click here