These as well as further features and advantages of the invention will be better appreciated by reading the following detailed description of presently preferred exemplary embodiments taken in conjunction with accompanying drawings of which:
When a client obtains a reference to a SFSB instance through dependency injection or JNDI lookup, or when the client invokes a create<Method> method on the SFSB's home interface, a SFSB instance's life starts (JNDI=Java Naming and Directory Interface). This causes the container to invoke newInstance on the SFSB class to create a new SFSB instance. After a couple of further steps 101 by the container known in the prior art, the instance of the SFSB is in the method ready state 11.
In the method ready state 11, the SFSB has an instance in the memory of the EJB container and it is ready to serve the client. One instance of the Stateful Session Bean serves only one client. From the method ready state 11, the instance of the SFSB can be moved 104 into the does-not-exist state 10 by a remove method or a timeout. For example, a remove method is executed when the container calls the ejbRemove or PreDestroy callback.
If the container's caching algorithm decides that the SFSB instance should be evicted from memory, the container issues ejbPassivate on the SFSB instance and the SFSB instance is passivated by moving 102 the SFSB instance from the method ready state 11 to the passive state 12.
In the passive state 12 the SFSB instance is passivated to conserve the resource. The passivate method is called before the SFSB instance enters the “passive” state. The SFSB instance should release any resources that it can re-acquire later in the ejbActivate( ) method. After the passivate method completes, the SFSB instance must be in a state that allows the container to use the Java Serialization protocol to externalize and store away the SFSB instance's state. The ejbRemove callback method or a timeout moves the bean into the Does Not Exist stage.
According to a first embodiment of the invention described in
By virtue of the fact that the SFSB instance is not removed from the passive state 12 in a direct way but via the method ready state 11, the instance of the SFSB can be informed about its nearby removal. Likewise, the conversational state associated with the SFSB can be notified about the imminent invalidity of the SFSB. Thus, there is a possibility for the clean-up of external states associated with the SFSB instance before the SFSB instance does not exist any more.
At the generation step 201 of a SFSB instance, it is checked and defined, respectively, whether the SFSB instance needs the behaviour as given above in the embodiment of the invention related to
Then, the SFSB instance may be passivated and moved 202 from the method ready state 21 to the passive state 22, as described above with reference to
When the container decides to remove the passivated SFSB instance from the passive state 22, this may proceed in either of two alternative ways.
The first alternative is that, as is shown in
By virtue of the fact that a SFSB instance is not necessarily removed from the passive state 22 in a direct way but that it may be removed via the method ready state 21, the instance of the SFSB can be informed about its nearby removal. Likewise, the conversational state associated with the SFSB can be notified about the imminent invalidity of the SFSB. Thus, there is a possibility—for selectively defined SFSBs which may need this possibility—for the clean-up of external states associated with the SFSB instance before the SFSB instance does not exist any more.
However, not every SFSB may need this re-activation to the method ready state 11 or 21 before being moved into the does-not-exist state 10 or 20. For these SFSB instances, the second alternative is advantageous. The second alternative is that the SFSB instance for which said flag is not set is directly removed 205 from the passive state 22 to the does-not-exist state 20.
The basic idea of this embodiment is to modify the SFSB lifecycle, as presented in
Basically, the embodiment according to
This name of this new type of callback function may be, e.g., ejbRemoveFromPassive or PreDestroyFromPassive.
Let us assume that a SFSB instance has been generated 301 and, after the generation 301 of its method ready state 31, moved 302 from the method ready state 31 into the passive state 32. If the container decides that the SFSB instance should be removed from the passive state 32, the function of the container checks whether the SFSB instance has provided the new callback method. Each SFSB may have meta-data associated with it from which the information can be retrieved whether the SFSB supports the new callback method.
If so, the function of the container calls the new callback method on the SFSB instance. The SFSB instance, called upon by this new callback method, is put 303 into a new state 33 where it does not re-claim resources, though. Preferably, the new state 33 may represent a state where the SFSB instance and the external resources associated with the SFSB instance are semi-activated. From this new state 33, the SFSB instance is then removed, i.e., moved 304 into the does-not-exist state 30. The bean provider can implement this callback method in such a way to avoid unnecessary external resource reservations, yet it is possible to indicate to external states to clean up their states as well. Thus, resources associated with the SFSB instance to be removed and not needed any more can be released in due time.
By calling the new type of callback method, the instance of the SFSB is informed about its nearby removal. Likewise, the conversational state associated with the SFSB can be notified about the imminent invalidity of the SFSB, although the SFSB instance has not been re-activated in the traditional manner, i.e., by moving the SFSB instance to the method ready state.
However, if the examination of the meta-data of the SFSB show that the SFSB does not support the new callback method, the SFSB instance is removed from the passive state in a process 305 without the near remove state 33, e.g., in a remove method 305 known from prior art. If the new callback method is not supported also any of the other remove methods described above may be used to remove the SFSB instance from the passive state 32.
Number | Date | Country | Kind |
---|---|---|---|
06291366.0 | Aug 2006 | EP | regional |