RE: accessing interceptor members from another interceptor

Jon Tirsén <[email protected]> Tue, 4 Mar 2003 07:49:53 +0100
Newsgroups gmane.comp.java.nanning.devel
Message-ID <001d01c2e21a$43a6ff00$6c4a59d5@jon>
For this kind of thing I'd probably use a ThreadLocal, ie:

interceptor A:
CurrentTransaction.setTransactionId(txId);

interceptor B:
long txId = CurrentTransaction.getTransactionId();

CurrentTransaction:
ThreadLocal transactionId;
public void setTransactionId(long txId) {
	transactionId.set(new Long(txId));
}
public long getTransactionId() {
	return ((Long) transactionId.get()).longValue();
}

Using a mixin is kind of awkward because then it's not thread-safe.
Transactions are associated with threads because there could be several
threads with different transactions involving the same object. For this
reason none of the alternatives you've outlined are satisfactory.

I'm going to implement attachements on Invocations too so you could do:
interceptor A:
invocation.setAttachment("transactionId", new Long(txId));

interceptor B:
long txId = ((Long)
invocation.getAttachment("transactionId")).longValue();

This has the disadvantage that if somebody else than the interceptors
need to access the txId it's not gonna be possible. Other than that it's
fine.


> -----Original Message-----
> From: [email protected] 
> [mailto:[email protected]] On 
> Behalf Of Talip Ozturk
> Sent: Tuesday, March 04, 2003 12:08 AM
> To: nanning
> Subject: [Nanning-developer] accessing interceptor members 
> from another interceptor
> 
> 
> Hey guys, 
> 
> i have a question about inter-interceptor communication. lets 
> say we have a interceptor A and B. B needs to access variable 
> that are set and available at interceptor A. what are the 
> recommended ways of passing/reading/accessing data that are 
> in another interceptor in an invocation chain? 
> 
> i have two ways right now.
> 1. Use a special State Mixin that holds shared data among 
> interceptors and other Mixin..
> 
> in interceptor A
> 	StateMixin sm = (StateMixin) invocation.getProxy();
> 	sm.setTransactionId (txId);
> 
> then in interceptor B
> 	StateMixin sm = (StateMixin) invocation.getProxy();
> 	long txId = sm.getTransactionId ());
> 
> 
> 2. Each interceptor should keep its own specific data. if 
> they need to access some other interceptor's data, they need 
> to get a hold on that interceptor first, and then access its 
> variables. Example.
> 
> in interceptor A
> 	setTransactionId (txnId);
> 
> 
> then in Interceptor B .. 
> 	A a = (A) invocation.getInterceptorNamed("a");
> 	a.getTransactionId();
> 
> 
> what do you guys think about this? please be as verbose as you can..
> 
> 
> 
> 
> 
> 
> 
> -------------------------------------------------------
> This SF.net email is sponsored by: Etnus, makers of 
> TotalView, The debugger 
> for complex code. Debugging C/C++ programs can leave you 
> feeling lost and 
> disoriented. TotalView can help you find your way. Available 
> on major UNIX 
> and Linux platforms. Try it free. www.etnus.com 
> _______________________________________________
> Nanning-developer mailing list [email protected]
> https://lists.sourceforge.net/lists/listinfo/nanning-developer
> 



-------------------------------------------------------
This SF.net email is sponsored by: Etnus, makers of TotalView, The debugger 
for complex code. Debugging C/C++ programs can leave you feeling lost and 
disoriented. TotalView can help you find your way. Available on major UNIX 
and Linux platforms. Try it free. www.etnus.com