org.apache.myfaces.orchestra.conversation
Class CurrentConversationAdvice

java.lang.Object
  extended by org.apache.myfaces.orchestra.conversation.CurrentConversationAdvice
All Implemented Interfaces:
Serializable, org.aopalliance.aop.Advice, org.aopalliance.intercept.Interceptor, org.aopalliance.intercept.MethodInterceptor

public class CurrentConversationAdvice
extends Object
implements org.aopalliance.intercept.MethodInterceptor, Serializable

An advice which is added to all conversation scoped beans.

It does the following:

A bean that is declared as belonging to a particular conversation is always wrapped by the IOC system in a proxy object. When any method is called on that proxy, the call is forwarded to the "invoke" method here. This class then ensures that the "current conversation" is set to the conversation configured for that target bean. The result is that the real bean can call Conversation.getCurrentInstance() and always receives a reference to the conversation object that has been configured for it.

In addition, on return from the target bean method, this object checks whether the conversation has been marked as invalid. If so (and the conversation is not in use by something further up the call stack) then destroy the conversation object.

Attempting to invoke a methods on a bean that is associated with a conversation that has been destroyed will cause an IllegalStateException to be thrown. This is a safety-net to detect cases where a reference to a proxy object bound to a specific conversation has been kept for longer than the conversation lifetime. This is bad, as it (a) attempts to access a "stale" conversation, and (b) prevents the destroyed conversation from being garbage-collected (although all the beans in it will already have been removed).

See Also:
Serialized Form

Constructor Summary
CurrentConversationAdvice(Conversation conversation, String beanName)
           
 
Method Summary
 Object invoke(org.aopalliance.intercept.MethodInvocation methodInvocation)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CurrentConversationAdvice

public CurrentConversationAdvice(Conversation conversation,
                                 String beanName)
Method Detail

invoke

public Object invoke(org.aopalliance.intercept.MethodInvocation methodInvocation)
              throws Throwable
Specified by:
invoke in interface org.aopalliance.intercept.MethodInterceptor
Throws:
Throwable


Copyright © 2012 The Apache Software Foundation. All Rights Reserved.