Title: Lazy loading media in EJB

I have an bean-managed entity bean which reads an image from a custom multimedia repository. The image is stored inside my bean as a byte array and can be served to a web client via a servlet. The bean is read-only in regards to the repository, it is not used as the mechanism for updating the binary data.

I'd like to lazy load my bean, by only talking to the media repository (via sockets) when absolutely needed. This will keep the load on the server down. The only reliable scheme I have found is to code the read into my ejbLoad() callback so that it happens every time.

Here is what I'd like.

1) Load the media only when the media is requested, once it is requested, it can stay in memory until passivated.
2) If the media has been loaded, I need the bean to dump it and reload it when my bean instance is swapped out.

Thus loading the media is defered, until absolutely necessary, but once loaded it is maintained in memory until the bean is swapped out.

What scheme can I use that combines ejbActivate(), ejbPassivate(), and ejbLoad() to get this behavior.

Dave Bolt
There is always plenty of bandwidth, just none for you.

Reply via email to