Note: the mechanism described here is not stable and tested yet.
Jucas provides a mechanism which informs JucasBeans when they are not anymore used by the BeanManager.
The mechanism is not save. It is not guaranteed that a JucasBean will be informed. Especially: A container is not required to inform its children that they are released and a PageBean which is held in Session is never informed. Therefore you should never rely on the mechanism to do necessary cleanup.
However the mechanism is quit useful for pooling, where it does not matter if occasionally certain instances are not returned to the pool. However note generally on Pooling. Modern Virtual-Machines are quite efficient on creating and garbage collecting light objects. Because JucasBeans are in general quite light and also pooling has some overhead the gains of making the beans poolable are general small. So we recommend that you first search other bottlenecks in your web-app before you implement IPoolable or IDestroyable.
If a Bean wants to be informed that it is not used anymore it should implement the interface org.jucas.IDestroyable. The only method of this interface is destroyJucasOnly(). JucasOnly means as always this method should only be called by the framework. When the method is called by the framework the Bean is notified that it will now leave the control of the BeanManager. Afterwards the Bean won?t be valid any more. The bean must release in the destroyJucasOnly() all its child JucasBeans. Also they won?t be valid anymore (their name and BeanHelper instance) when the parent leaves the BeanManager. After the method is called the Bean?s BeanHelper instance will be set to null by calling IJucasBean.givenBeanHelperJucasOnly(null).
Note: If you do not implement this interface and you do not pool the JucasBean, you do not have to worry about being invalid or so. Because the Bean will be garbage collected. This is because no one is allowed to hold a direct reference (whithout org.jucas.BeanLink) to a JucasBean which does not belong to the same PageBean (is created directly or indirectly by the same PageBean).
If the Bean implements Poolable which is a subinterface of IDestroyable the bean will be pooled in a org.jucas.JucasBeanPool. The BeanManager maintains one such pool for the whole web-app. The pool can be retrieved by BeanManager.getJucasBeanPool(). When loading a JucasBean which is poolable the BeanManager will lookup in this Pool for an instance and than inform the Bean by calling IPoolable.retrievedFromPool(). In the destroyJucasOnly() method the Bean should return itself to the Pool retrieved from the BeanManager.