You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Michael M <ge...@gmail.com> on 2012/08/17 16:25:54 UTC

ResourceStreamResources stream multiple times when ResourceLink clicked once

Hi, short question this time: I have several ResourceLinks to
ResourceStreamResources on a page. When I click on one of those links, the
resource streams attachments dynamically out of my database.

That's working quite well now, however the stream (and whatever happens in
the method returning the streams) is called 2-4 times. E.g. opening an
image results in 4 queries to the CouchDB database. I don't really see that
happening when I'm playing an mp3 file with a flash-player pointing to the
URL of the resource.

Does anyone have an idea why? I'm only instantiating the resource once, for
any link I only use that one resource.

Here's my custom ResourceStreamResource: http://pastebin.com/9BB7LEiV

And here my custom IResouceStream: http://pastebin.com/Z7GvzGja

Thanks!

Re: ResourceStreamResources stream multiple times when ResourceLink clicked once

Posted by Michael M <ge...@gmail.com>.
Hmm, that would require quite a rewrite, unfortunately I can't afford that
time-effort right now (I chose Wicket for my thesis project). I'm not even
sure if I could do that, because in some cases I also need the URL from the
ResourceLink (e.g. to pass it to JW Player JavaScript for playing an
'audio' content-type attachment from the DB).

IMHO, making this possible is also the whole point of having dynamic
resources.

I'll see if I can file that as a bug. Until then I think I just have to
ignore the stream-resource behavior, since it's not really noticeable in
the prototype yet.

Thanks for your help up to this point! If anyone has more suggestions, feel
free please. :)

2012/8/17 Sven Meier <sv...@meiers.net>

> Hm, possibly easiest would be to create the resource when it is requested
> only.
> What component are you using to integrate the resource in your page?
>
>
> >Is it possible that it's a bug that the stream gets requested multiple
> times? Or if it is by design, why?
>
> IMHO ResourceStreamResource#**internalGetResourceStream() should check
> for an already created stream and return that one. The way it is
> implemented now looks like a bug.
>
> Sven
>
>
>
> On 08/17/2012 06:19 PM, Michael M wrote:
>
>> Is it possible that it's a bug that the stream gets requested multiple
>> times? Or if it is by design, why? I can't see a reason for it.
>>
>> I also cannot only return a new IResourceStream when it's not instantiated
>> yet in my ResourceStreamResource, because the AttachmentInputStream from
>> Ektorp is not serializable, I get errors if I try that. As far as my
>> knowledge goes I see myself with no option left..
>>
>> 2012/8/17 Michael M <ge...@gmail.com>
>>
>>  Thanks for the idea, but I can't do that. That would make my resources
>>> static and all attachments would be loaded at page load. I did that at
>>> the
>>> beginning, and of course that's a very flawed concept because I would run
>>> into huge performance and memory-problems even with just one user.
>>>
>>> So I need the ResourceStreamResource to be dynamic. I don't get why the *
>>> getResourceStream()* is called multiple times.. the javadoc for that
>>>
>>> method says
>>>
>>> Lazy or dynamic initialization (...)
>>>
>>>
>>> How can I get proper dynamic resource then?
>>>
>>> 2012/8/17 Sven Meier <sv...@meiers.net>
>>>
>>>  Beware that ResourceStreamResource#****getResourceStream() is called
>>>>
>>>> multiple times.
>>>>
>>>> Probably easiest is to create the resource stream in
>>>> CouchDbAttachmentStreamResourc****e's constructor and pass it to super.
>>>>
>>>>
>>>> Sven
>>>>
>>>>
>>>> On 08/17/2012 05:28 PM, Michael M wrote:
>>>>
>>>>  Hi,
>>>>>
>>>>> I wanted to, but I can't because then I don't have the stream to close
>>>>> it.
>>>>> If I don't close the stream returned by the Ektorp getAttachment()
>>>>> method I
>>>>> will have memory leaks.
>>>>>
>>>>> 2012/8/17 Sven Meier <sv...@meiers.net>
>>>>>
>>>>>   Without looking to deep into this you should create the InputStream
>>>>> in
>>>>>
>>>>>> CouchDbResourceStream#******getInputStream() instead of the
>>>>>> constructor.
>>>>>>
>>>>>>
>>>>>>
>>>>>> Sven
>>>>>>
>>>>>>
>>>>>> On 08/17/2012 04:25 PM, Michael M wrote:
>>>>>>
>>>>>>   Hi, short question this time: I have several ResourceLinks to
>>>>>>
>>>>>>> ResourceStreamResources on a page. When I click on one of those
>>>>>>> links,
>>>>>>> the
>>>>>>> resource streams attachments dynamically out of my database.
>>>>>>>
>>>>>>> That's working quite well now, however the stream (and whatever
>>>>>>> happens in
>>>>>>> the method returning the streams) is called 2-4 times. E.g. opening
>>>>>>> an
>>>>>>> image results in 4 queries to the CouchDB database. I don't really
>>>>>>> see
>>>>>>> that
>>>>>>> happening when I'm playing an mp3 file with a flash-player pointing
>>>>>>> to
>>>>>>> the
>>>>>>> URL of the resource.
>>>>>>>
>>>>>>> Does anyone have an idea why? I'm only instantiating the resource
>>>>>>> once,
>>>>>>> for
>>>>>>> any link I only use that one resource.
>>>>>>>
>>>>>>> Here's my custom ResourceStreamResource:
>>>>>>> http://pastebin.com/9BB7LEiV
>>>>>>>
>>>>>>> And here my custom IResouceStream: http://pastebin.com/Z7GvzGja
>>>>>>>
>>>>>>> Thanks!
>>>>>>>
>>>>>>>
>>>>>>>   ------------------------------******--------------------------**
>>>>>>> --**
>>>>>>>
>>>>>> --**---------
>>>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.****apa**che.org<
>>>>>> http://apache.org**>
>>>>>> <users-unsubscribe@**wicket.**apache.org <http://wicket.apache.org><
>>>>>> users-unsubscribe@**wicket.apache.org<us...@wicket.apache.org>
>>>>>> >
>>>>>>
>>>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>>>
>>>>>>
>>>>>>
>>>>>>  ------------------------------****----------------------------**
>>>> --**---------
>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.**apa**che.org<http://apache.org>
>>>> <us...@wicket.apache.org>
>>>> >
>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>
>>>>
>>>>
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: users-unsubscribe@wicket.**apache.org<us...@wicket.apache.org>
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: ResourceStreamResources stream multiple times when ResourceLink clicked once

Posted by Sven Meier <sv...@meiers.net>.
Hm, possibly easiest would be to create the resource when it is 
requested only.
What component are you using to integrate the resource in your page?

 >Is it possible that it's a bug that the stream gets requested multiple 
times? Or if it is by design, why?

IMHO ResourceStreamResource#internalGetResourceStream() should check for 
an already created stream and return that one. The way it is implemented 
now looks like a bug.

Sven


On 08/17/2012 06:19 PM, Michael M wrote:
> Is it possible that it's a bug that the stream gets requested multiple
> times? Or if it is by design, why? I can't see a reason for it.
>
> I also cannot only return a new IResourceStream when it's not instantiated
> yet in my ResourceStreamResource, because the AttachmentInputStream from
> Ektorp is not serializable, I get errors if I try that. As far as my
> knowledge goes I see myself with no option left..
>
> 2012/8/17 Michael M <ge...@gmail.com>
>
>> Thanks for the idea, but I can't do that. That would make my resources
>> static and all attachments would be loaded at page load. I did that at the
>> beginning, and of course that's a very flawed concept because I would run
>> into huge performance and memory-problems even with just one user.
>>
>> So I need the ResourceStreamResource to be dynamic. I don't get why the *
>> getResourceStream()* is called multiple times.. the javadoc for that
>> method says
>>
>> Lazy or dynamic initialization (...)
>>
>>
>> How can I get proper dynamic resource then?
>>
>> 2012/8/17 Sven Meier <sv...@meiers.net>
>>
>>> Beware that ResourceStreamResource#**getResourceStream() is called
>>> multiple times.
>>>
>>> Probably easiest is to create the resource stream in
>>> CouchDbAttachmentStreamResourc**e's constructor and pass it to super.
>>>
>>> Sven
>>>
>>>
>>> On 08/17/2012 05:28 PM, Michael M wrote:
>>>
>>>> Hi,
>>>>
>>>> I wanted to, but I can't because then I don't have the stream to close
>>>> it.
>>>> If I don't close the stream returned by the Ektorp getAttachment()
>>>> method I
>>>> will have memory leaks.
>>>>
>>>> 2012/8/17 Sven Meier <sv...@meiers.net>
>>>>
>>>>   Without looking to deep into this you should create the InputStream in
>>>>> CouchDbResourceStream#****getInputStream() instead of the constructor.
>>>>>
>>>>>
>>>>> Sven
>>>>>
>>>>>
>>>>> On 08/17/2012 04:25 PM, Michael M wrote:
>>>>>
>>>>>   Hi, short question this time: I have several ResourceLinks to
>>>>>> ResourceStreamResources on a page. When I click on one of those links,
>>>>>> the
>>>>>> resource streams attachments dynamically out of my database.
>>>>>>
>>>>>> That's working quite well now, however the stream (and whatever
>>>>>> happens in
>>>>>> the method returning the streams) is called 2-4 times. E.g. opening an
>>>>>> image results in 4 queries to the CouchDB database. I don't really see
>>>>>> that
>>>>>> happening when I'm playing an mp3 file with a flash-player pointing to
>>>>>> the
>>>>>> URL of the resource.
>>>>>>
>>>>>> Does anyone have an idea why? I'm only instantiating the resource once,
>>>>>> for
>>>>>> any link I only use that one resource.
>>>>>>
>>>>>> Here's my custom ResourceStreamResource: http://pastebin.com/9BB7LEiV
>>>>>>
>>>>>> And here my custom IResouceStream: http://pastebin.com/Z7GvzGja
>>>>>>
>>>>>> Thanks!
>>>>>>
>>>>>>
>>>>>>   ------------------------------****----------------------------**
>>>>> --**---------
>>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.**apa**che.org<http://apache.org>
>>>>> <us...@wicket.apache.org>
>>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>>
>>>>>
>>>>>
>>> ------------------------------**------------------------------**---------
>>> To unsubscribe, e-mail: users-unsubscribe@wicket.**apache.org<us...@wicket.apache.org>
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>
>>>


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


Re: ResourceStreamResources stream multiple times when ResourceLink clicked once

Posted by Michael M <ge...@gmail.com>.
Is it possible that it's a bug that the stream gets requested multiple
times? Or if it is by design, why? I can't see a reason for it.

I also cannot only return a new IResourceStream when it's not instantiated
yet in my ResourceStreamResource, because the AttachmentInputStream from
Ektorp is not serializable, I get errors if I try that. As far as my
knowledge goes I see myself with no option left..

2012/8/17 Michael M <ge...@gmail.com>

> Thanks for the idea, but I can't do that. That would make my resources
> static and all attachments would be loaded at page load. I did that at the
> beginning, and of course that's a very flawed concept because I would run
> into huge performance and memory-problems even with just one user.
>
> So I need the ResourceStreamResource to be dynamic. I don't get why the *
> getResourceStream()* is called multiple times.. the javadoc for that
> method says
>
> Lazy or dynamic initialization (...)
>
>
> How can I get proper dynamic resource then?
>
> 2012/8/17 Sven Meier <sv...@meiers.net>
>
>> Beware that ResourceStreamResource#**getResourceStream() is called
>> multiple times.
>>
>> Probably easiest is to create the resource stream in
>> CouchDbAttachmentStreamResourc**e's constructor and pass it to super.
>>
>> Sven
>>
>>
>> On 08/17/2012 05:28 PM, Michael M wrote:
>>
>>> Hi,
>>>
>>> I wanted to, but I can't because then I don't have the stream to close
>>> it.
>>> If I don't close the stream returned by the Ektorp getAttachment()
>>> method I
>>> will have memory leaks.
>>>
>>> 2012/8/17 Sven Meier <sv...@meiers.net>
>>>
>>>  Without looking to deep into this you should create the InputStream in
>>>> CouchDbResourceStream#****getInputStream() instead of the constructor.
>>>>
>>>>
>>>> Sven
>>>>
>>>>
>>>> On 08/17/2012 04:25 PM, Michael M wrote:
>>>>
>>>>  Hi, short question this time: I have several ResourceLinks to
>>>>> ResourceStreamResources on a page. When I click on one of those links,
>>>>> the
>>>>> resource streams attachments dynamically out of my database.
>>>>>
>>>>> That's working quite well now, however the stream (and whatever
>>>>> happens in
>>>>> the method returning the streams) is called 2-4 times. E.g. opening an
>>>>> image results in 4 queries to the CouchDB database. I don't really see
>>>>> that
>>>>> happening when I'm playing an mp3 file with a flash-player pointing to
>>>>> the
>>>>> URL of the resource.
>>>>>
>>>>> Does anyone have an idea why? I'm only instantiating the resource once,
>>>>> for
>>>>> any link I only use that one resource.
>>>>>
>>>>> Here's my custom ResourceStreamResource: http://pastebin.com/9BB7LEiV
>>>>>
>>>>> And here my custom IResouceStream: http://pastebin.com/Z7GvzGja
>>>>>
>>>>> Thanks!
>>>>>
>>>>>
>>>>>  ------------------------------****----------------------------**
>>>> --**---------
>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.**apa**che.org<http://apache.org>
>>>> <us...@wicket.apache.org>
>>>> >
>>>>
>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>
>>>>
>>>>
>>
>> ------------------------------**------------------------------**---------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.**apache.org<us...@wicket.apache.org>
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>

Re: ResourceStreamResources stream multiple times when ResourceLink clicked once

Posted by Michael M <ge...@gmail.com>.
Thanks for the idea, but I can't do that. That would make my resources
static and all attachments would be loaded at page load. I did that at the
beginning, and of course that's a very flawed concept because I would run
into huge performance and memory-problems even with just one user.

So I need the ResourceStreamResource to be dynamic. I don't get why the *
getResourceStream()* is called multiple times.. the javadoc for that method
says

Lazy or dynamic initialization (...)


How can I get proper dynamic resource then?

2012/8/17 Sven Meier <sv...@meiers.net>

> Beware that ResourceStreamResource#**getResourceStream() is called
> multiple times.
>
> Probably easiest is to create the resource stream in
> CouchDbAttachmentStreamResourc**e's constructor and pass it to super.
>
> Sven
>
>
> On 08/17/2012 05:28 PM, Michael M wrote:
>
>> Hi,
>>
>> I wanted to, but I can't because then I don't have the stream to close it.
>> If I don't close the stream returned by the Ektorp getAttachment() method
>> I
>> will have memory leaks.
>>
>> 2012/8/17 Sven Meier <sv...@meiers.net>
>>
>>  Without looking to deep into this you should create the InputStream in
>>> CouchDbResourceStream#****getInputStream() instead of the constructor.
>>>
>>>
>>> Sven
>>>
>>>
>>> On 08/17/2012 04:25 PM, Michael M wrote:
>>>
>>>  Hi, short question this time: I have several ResourceLinks to
>>>> ResourceStreamResources on a page. When I click on one of those links,
>>>> the
>>>> resource streams attachments dynamically out of my database.
>>>>
>>>> That's working quite well now, however the stream (and whatever happens
>>>> in
>>>> the method returning the streams) is called 2-4 times. E.g. opening an
>>>> image results in 4 queries to the CouchDB database. I don't really see
>>>> that
>>>> happening when I'm playing an mp3 file with a flash-player pointing to
>>>> the
>>>> URL of the resource.
>>>>
>>>> Does anyone have an idea why? I'm only instantiating the resource once,
>>>> for
>>>> any link I only use that one resource.
>>>>
>>>> Here's my custom ResourceStreamResource: http://pastebin.com/9BB7LEiV
>>>>
>>>> And here my custom IResouceStream: http://pastebin.com/Z7GvzGja
>>>>
>>>> Thanks!
>>>>
>>>>
>>>>  ------------------------------****----------------------------**
>>> --**---------
>>> To unsubscribe, e-mail: users-unsubscribe@wicket.**apa**che.org<http://apache.org>
>>> <us...@wicket.apache.org>
>>> >
>>>
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>
>>>
>>>
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: users-unsubscribe@wicket.**apache.org<us...@wicket.apache.org>
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: ResourceStreamResources stream multiple times when ResourceLink clicked once

Posted by Sven Meier <sv...@meiers.net>.
Beware that ResourceStreamResource#getResourceStream() is called 
multiple times.

Probably easiest is to create the resource stream in 
CouchDbAttachmentStreamResource's constructor and pass it to super.

Sven

On 08/17/2012 05:28 PM, Michael M wrote:
> Hi,
>
> I wanted to, but I can't because then I don't have the stream to close it.
> If I don't close the stream returned by the Ektorp getAttachment() method I
> will have memory leaks.
>
> 2012/8/17 Sven Meier <sv...@meiers.net>
>
>> Without looking to deep into this you should create the InputStream in
>> CouchDbResourceStream#**getInputStream() instead of the constructor.
>>
>> Sven
>>
>>
>> On 08/17/2012 04:25 PM, Michael M wrote:
>>
>>> Hi, short question this time: I have several ResourceLinks to
>>> ResourceStreamResources on a page. When I click on one of those links, the
>>> resource streams attachments dynamically out of my database.
>>>
>>> That's working quite well now, however the stream (and whatever happens in
>>> the method returning the streams) is called 2-4 times. E.g. opening an
>>> image results in 4 queries to the CouchDB database. I don't really see
>>> that
>>> happening when I'm playing an mp3 file with a flash-player pointing to the
>>> URL of the resource.
>>>
>>> Does anyone have an idea why? I'm only instantiating the resource once,
>>> for
>>> any link I only use that one resource.
>>>
>>> Here's my custom ResourceStreamResource: http://pastebin.com/9BB7LEiV
>>>
>>> And here my custom IResouceStream: http://pastebin.com/Z7GvzGja
>>>
>>> Thanks!
>>>
>>>
>> ------------------------------**------------------------------**---------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.**apache.org<us...@wicket.apache.org>
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>


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


Re: ResourceStreamResources stream multiple times when ResourceLink clicked once

Posted by Michael M <ge...@gmail.com>.
Hi,

I wanted to, but I can't because then I don't have the stream to close it.
If I don't close the stream returned by the Ektorp getAttachment() method I
will have memory leaks.

2012/8/17 Sven Meier <sv...@meiers.net>

> Without looking to deep into this you should create the InputStream in
> CouchDbResourceStream#**getInputStream() instead of the constructor.
>
> Sven
>
>
> On 08/17/2012 04:25 PM, Michael M wrote:
>
>> Hi, short question this time: I have several ResourceLinks to
>> ResourceStreamResources on a page. When I click on one of those links, the
>> resource streams attachments dynamically out of my database.
>>
>> That's working quite well now, however the stream (and whatever happens in
>> the method returning the streams) is called 2-4 times. E.g. opening an
>> image results in 4 queries to the CouchDB database. I don't really see
>> that
>> happening when I'm playing an mp3 file with a flash-player pointing to the
>> URL of the resource.
>>
>> Does anyone have an idea why? I'm only instantiating the resource once,
>> for
>> any link I only use that one resource.
>>
>> Here's my custom ResourceStreamResource: http://pastebin.com/9BB7LEiV
>>
>> And here my custom IResouceStream: http://pastebin.com/Z7GvzGja
>>
>> Thanks!
>>
>>
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: users-unsubscribe@wicket.**apache.org<us...@wicket.apache.org>
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: ResourceStreamResources stream multiple times when ResourceLink clicked once

Posted by Sven Meier <sv...@meiers.net>.
Without looking to deep into this you should create the InputStream in 
CouchDbResourceStream#getInputStream() instead of the constructor.

Sven

On 08/17/2012 04:25 PM, Michael M wrote:
> Hi, short question this time: I have several ResourceLinks to
> ResourceStreamResources on a page. When I click on one of those links, the
> resource streams attachments dynamically out of my database.
>
> That's working quite well now, however the stream (and whatever happens in
> the method returning the streams) is called 2-4 times. E.g. opening an
> image results in 4 queries to the CouchDB database. I don't really see that
> happening when I'm playing an mp3 file with a flash-player pointing to the
> URL of the resource.
>
> Does anyone have an idea why? I'm only instantiating the resource once, for
> any link I only use that one resource.
>
> Here's my custom ResourceStreamResource: http://pastebin.com/9BB7LEiV
>
> And here my custom IResouceStream: http://pastebin.com/Z7GvzGja
>
> Thanks!
>


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