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:


.: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?

Narender Godara said...

Packers and movers Raipur
Packers and movers Rajkot
Packers and movers Shimla
Packers and movers Surat

amine lahragui said...

Your work is very good and I appreciate you and hopping for some more informative posts. happy new year 2016 new year 2016 bonne année 2016 happy new year 2016 images feliz año nuevo 2016 imagenes de año nuevo 2016 feliz año 2016

Hosting Coupons&Discounts said...

new year 2016
diwali wishes 2015
diwali quotes 2015
diwali images 2015
new year 2016 wishes
new year 2016 sms
new year 2016 quotes
new year 2016 messages
new year 2016 poems
new year 2016 fb status
new year 2016 whatsapp status
new year hindi wishes
new year 2016 french
new year 2016 spanish

Abu sigly Ahlussunnah waljamaah said...

thank u friend
cara cepat menjadi orang pintar
Khasiat ayat kursi
resep ceker goreng tepung kryspy
polisi tangkap dua anggota TRA
sebab akibat serangan teror diparis
keajaiban air zam zam
alasan paling kuat kenapa alien belum ditemukan

Mary Brown said...

Java EE article is practical oriented and real time examples. How Java EE address the enterprise development is very important. for that you need a practical orieneted Java Training you need.

Online Java Training
Online Java Training from India
Java Training Institutes in Chennai
Java Training in Chennai
Java Training

Abu sigly Ahlussunnah waljamaah said...

Baca juga

mkasih sobat semua,salam sukses
manfaat berjalan kaki
Kekejaman nasrani
sembahlah Allah Tuhanku dan tuhanmu
penampakan ufo