Mapped resource reference and urlFor()

2011-12-14 Thread Bertrand Guay-Paquet

Hi,

I am using resource references for the first time to implement fetching 
images from a DB. The URLs will be of the following form:
/resources/dbImages/DB_ID.png where DB_ID is an identifier to retrieve 
the image from the DB.


I'm using the article at 
http://wicketinaction.com/2011/07/wicket-1-5-mounting-resources/ as a 
guide and have a couple of questions.


1. What is the purpose of the equals() override in the class 
ImageResource? I don't understand the explanation given in the 
article... Also, I put a breakpoint in my own resource class' equals() 
method and it never hits!


2. Can I use part of the resources namespace or is that asking for 
trouble since Wicket can use it however it likes?


3. When using getRequestCycle().urlFor(new MyResourceReference(), 
imageParameters), the following happens:

at line 216 in ResourceMapper#addCachingDecoration(Url, PageParameters) :
final IResource resource = resourceReference.getResource();

with a comment right above that says // TODO is calling getResource() a 
potential performance bottleneck?


I am concerned that each time a url to my image resource reference is 
created, the DB will be hit, simply for getting the Url! It will then 
maybe be hit a second time afterwards if the client doesn't have the 
image in cache. Am I completely off-base here? Is there another way to 
manage resources so this doesn't happen?


Thanks,
Bertrand

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: Mapped resource reference and urlFor()

2011-12-14 Thread Martin Grigorov
HI,

On Wed, Dec 14, 2011 at 7:59 PM, Bertrand Guay-Paquet
ber...@step.polymtl.ca wrote:
 Hi,

 I am using resource references for the first time to implement fetching
 images from a DB. The URLs will be of the following form:
 /resources/dbImages/DB_ID.png where DB_ID is an identifier to retrieve the
 image from the DB.

 I'm using the article at
 http://wicketinaction.com/2011/07/wicket-1-5-mounting-resources/ as a guide
 and have a couple of questions.

 1. What is the purpose of the equals() override in the class ImageResource?
 I don't understand the explanation given in the article... Also, I put a
 breakpoint in my own resource class' equals() method and it never hits!

Until recently both ResRef's #equals() and IResource#equals() were
needed to find the mapped ResRef.
This was improved recently (1.5.3 or trunk, not sure) and now only
ResRef#equals() is used. See ResourceMapper#mapRequest().


 2. Can I use part of the resources namespace or is that asking for trouble
 since Wicket can use it however it likes?

Use it. /resources/... is for 1.4.x
In 1.5 the special one is /wicket/resource/... See IMapperContext


 3. When using getRequestCycle().urlFor(new MyResourceReference(),
 imageParameters), the following happens:
 at line 216 in ResourceMapper#addCachingDecoration(Url, PageParameters) :
    final IResource resource = resourceReference.getResource();

 with a comment right above that says // TODO is calling getResource() a
 potential performance bottleneck?

 I am concerned that each time a url to my image resource reference is
 created, the DB will be hit, simply for getting the Url! It will then maybe
 be hit a second time afterwards if the client doesn't have the image in
 cache. Am I completely off-base here? Is there another way to manage
 resources so this doesn't happen?

 Thanks,
 Bertrand

 -
 To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
 For additional commands, e-mail: users-h...@wicket.apache.org




-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: Mapped resource reference and urlFor()

2011-12-14 Thread Peter Ertl
Try to do the real work in the IResource#respond() (accessing the database and 
retrieving the image) and make calling the constructor cheap, then you should 
not have any bottlenecks at all.

Am 14.12.2011 um 18:59 schrieb Bertrand Guay-Paquet:

 Hi,
 
 I am using resource references for the first time to implement fetching 
 images from a DB. The URLs will be of the following form:
 /resources/dbImages/DB_ID.png where DB_ID is an identifier to retrieve the 
 image from the DB.
 
 I'm using the article at 
 http://wicketinaction.com/2011/07/wicket-1-5-mounting-resources/ as a guide 
 and have a couple of questions.
 
 1. What is the purpose of the equals() override in the class ImageResource? I 
 don't understand the explanation given in the article... Also, I put a 
 breakpoint in my own resource class' equals() method and it never hits!
 
 2. Can I use part of the resources namespace or is that asking for trouble 
 since Wicket can use it however it likes?
 
 3. When using getRequestCycle().urlFor(new MyResourceReference(), 
 imageParameters), the following happens:
 at line 216 in ResourceMapper#addCachingDecoration(Url, PageParameters) :
final IResource resource = resourceReference.getResource();
 
 with a comment right above that says // TODO is calling getResource() a 
 potential performance bottleneck?
 
 I am concerned that each time a url to my image resource reference is 
 created, the DB will be hit, simply for getting the Url! It will then maybe 
 be hit a second time afterwards if the client doesn't have the image in 
 cache. Am I completely off-base here? Is there another way to manage 
 resources so this doesn't happen?
 
 Thanks,
 Bertrand
 
 -
 To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
 For additional commands, e-mail: users-h...@wicket.apache.org
 


-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: Mapped resource reference and urlFor()

2011-12-14 Thread Bertrand Guay-Paquet
@Peter: This is actually what I was doing already via the 
ByteArrayResource class! I just didn't notice that only the constructor 
was called... Thanks for opening my eyes!


@Martin: In 1.5.3, I think the code you referenced is :

// see if request handler addresses the resource we serve
if (resourceReference.equals(handler.getResourceReference()) == 
false 

resourceReference.getResource().equals(handler.getResource()) == false)

{
return null;
}

Indeed, it suffices for the ResourceReference to implement equals which 
it already does by default using its key. Thanks for explaining!


Regards,
Bertrand

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org