There are several ways of refreshing read-only beans as addressed in the following sections:
Invoking any transactional method invokes ejbLoad.
Use the refresh-period-in-seconds element in the sun-ejb-jar.xml file to refresh a read-only bean periodically.
If the value specified in refresh-period-in-seconds is zero or not specified, which is the default, the bean is never refreshed (unless a transactional method is accessed).
If the value is greater than zero, the bean is refreshed at the rate specified.
This is the only way to refresh the bean state if the data can be modified external to the Application Server.
Typically, beans that update any data that is cached by read-only beans need to notify the read-only beans to refresh their state. Use ReadOnlyBeanNotifier to force the refresh of read-only beans.
To do this, invoke the following methods on the ReadOnlyBeanNotifier bean:
public interface ReadOnlyBeanNotifier extends java.rmi.Remote { refresh(Object PrimaryKey) throws RemoteException; }
The implementation of the ReadOnlyBeanNotifier interface is provided by the container. The bean looks up ReadOnlyBeanNotifier using a fragment of code such as the following example:
com.sun.appserv.ejb.ReadOnlyBeanHelper helper = new com.sun.appserv.ejb.ReadOnlyBeanHelper(); com.sun.appserv.ejb.ReadOnlyBeanNotifier notifier = helper.getReadOnlyBeanNotifier("java:comp/env/ejb/ReadOnlyCustomer"); notifier.refresh(PrimaryKey);
For a local read-only bean notifier, the lookup has this modification:
helper.getReadOnlyBeanLocalNotifier("java:comp/env/ejb/LocalReadOnlyCustomer");
Beans that update any data that is cached by read-only beans need to call the refresh methods. The next (non-transactional) call to the read-only bean invokes ejbLoad.
Programmatic refresh of read-only beans is not supported in a clustered environment.