I wouldn't even try to model this part of your application using EJB as it is
not a fit. I would put the caching into the image server that you have written.
I would make the image server responsible for detecting when the image has been
changed in the image repository.

If you really want to use EJB, then at least one pattern comes to mind.

1. If you use Entity Beans your images will have to have some sort of PK to be
somewhat functional.
2. In your ejbLoad() you would check to see if the image was in your local
cache.
3. If it is, then you pass some checksum to the image server and it determines
whether you need to refresh your local cache.
4. If you do, or if you don't have the image yet, you would get the image from
the server.
5. Store the image in your local cache and calculate the new checksum.

Please note, that this local cache would end up storing images for each PK it
was tasked with looking up. The first time it is used, it holds no images, but
may hold image 1382 after the call. The next time this bean instance is used,
the server may want to get image 1451. The cache would have to then store that
image as well.

I would venture a guess to say that the same pattern can be applied to Stateless
Session Beans and it would perform even better. (Less cache misses).

When it comes time for the container to passivate the bean, I wouldn't bother. I
would simply clear the cache. The cost of passivating that cache of image data
hardly seems worth it. Your mileage may vary.

As you can see, EJB isn't bringing anything to the table here except another
layer and more serialization.


jim
----- Original Message -----
From: Bolt, Dave
To: [EMAIL PROTECTED] ; [EMAIL PROTECTED]
Sent: Friday, April 06, 2001 4:29 PM
Subject: [JBoss-user] 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.

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to