Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » Disposing Images / keeping Images just for a time or user session
Disposing Images / keeping Images just for a time or user session [message #122632] Wed, 25 February 2009 14:39 Go to next message
p-lex is currently offline p-lexFriend
Messages: 18
Registered: July 2009
Junior Member
Dear RAP friends,

I’m developing a rap application that should have a kind of image-gallery.
This gallery has to display many images coming as byte-Array (byte[]) from
an Enterprise Application.

Every RAP-User Session has a connection to the Enterprise-Application and
every user can display other images (images can be same). The user should
have the possibility to scale the images displayed in the gallery.

So it is not necessary to keep these images for the whole application
life-time even not the session one. I’m searching for a way to dispose
images when I don’t need them any more and to share images where possible.
I don’t want to keep them in the memory or as image-files on the hard
drive. So maybe the best way would be to keep the images as files on hard
drive but have the possibility to delete them if not needed any more
(dispose).

See Bug 245635 https://bugs.eclipse.org/bugs/show_bug.cgi?id=245635

Currently I’m converting the byte[]s to InputStreams and create ImageData
objects using the constructor ImageData(InputStream). When I’m holding
references to these ImageDatas to call the ImageData.scaleTo(int, int) for
getting images (using ResourceFactory.findImage(imageData)) for displaying.

See
http://www.eclipse.org/newsportal/article.php?id=5375&gr oup=eclipse.technology.rap#5375

The problems are:
1. The hold ImageDatas needs memory for every full Image and even worse
for each user session. So I see me get in a lot of memory problems.
See
http://www.eclipse.org/newsportal/article.php?id=5412&gr oup=eclipse.technology.rap#5412
2. I don’t know if the Images I created but don’t use any more are keep as
image files on the RAP-App Host.
3. Some security reasons require that the images should be not reachable
through a direct link to an image-file.

So I would be very happy to get professional advice for these problems.
Maybe I should use a Custom-Widget that uses an image-servlet for
displaying the images.

What is the best way to solve this problem, can somebody explain me the
different concepts of Images in RAP?

Best regards

p-lex
Re: Disposing Images / keeping Images just for a time or user session [message #123292 is a reply to message #122632] Fri, 27 February 2009 08:53 Go to previous messageGo to next message
p-lex is currently offline p-lexFriend
Messages: 18
Registered: July 2009
Junior Member
--- Behavior of ResourceFactory.findImage(imageData) ---

p-lex wrote:

> 2. I don’t know if the Images I created but don’t use any more are keep as
> image files on the RAP-App Host.

Images created throw ResourceFactory.findImage(imageData) go to
resources\generated\ where they are saved as image-files named by a
special (created from the byte[] data) hashCode + File-Extension. If the
"hashcode" of a
ImageData was already put in this first inputed one is used. (see source
code of ResourceFactory.findImage(imageData))

The image files are never deleted, right? This should be changed. Maybe
throw a parameter declaring the life time(SESSION, APPLICATION,
PERSISTENT) of the Image or maybe just throw an image dispose method that
deletes the image file and remove the image path from the image map.

best regards

p-lex
Re: Disposing Images / keeping Images just for a time or user session [message #123357 is a reply to message #122632] Fri, 27 February 2009 15:10 Go to previous messageGo to next message
Rüdiger Herrmann is currently offline Rüdiger HerrmannFriend
Messages: 581
Registered: July 2009
Senior Member
Hi,

as described in bug 245635, currently all Images have application
scope.
Your suggestion to use a custom widget and an image servlet sound
like a reasonable approach. Instead of an extra servlet you could
delver the images with an IServiceHandler (see the JavaDoc for details).

HTH
Rüdiger

p-lex wrote:
> Dear RAP friends,
>
> I�m developing a rap application that should have a kind of
> image-gallery. This gallery has to display many images coming as
> byte-Array (byte[]) from an Enterprise Application.
>
> Every RAP-User Session has a connection to the Enterprise-Application
> and every user can display other images (images can be same). The user
> should have the possibility to scale the images displayed in the gallery.
>
> So it is not necessary to keep these images for the whole application
> life-time even not the session one. I�m searching for a way to dispose
> images when I don�t need them any more and to share images where
> possible. I don�t want to keep them in the memory or as image-files on
> the hard drive. So maybe the best way would be to keep the images as
> files on hard drive but have the possibility to delete them if not
> needed any more (dispose).
>
> See Bug 245635 https://bugs.eclipse.org/bugs/show_bug.cgi?id=245635
>
> Currently I�m converting the byte[]s to InputStreams and create
> ImageData objects using the constructor ImageData(InputStream). When I�m
> holding references to these ImageDatas to call the
> ImageData.scaleTo(int, int) for getting images (using
> ResourceFactory.findImage(imageData)) for displaying.
>
> See
> http://www.eclipse.org/newsportal/article.php?id=5375&gr oup=eclipse.technology.rap#5375
>
>
> The problems are:
> 1. The hold ImageDatas needs memory for every full Image and even
> worse for each user session. So I see me get in a lot of memory problems.
> See
> http://www.eclipse.org/newsportal/article.php?id=5412&gr oup=eclipse.technology.rap#5412
>
> 2. I don�t know if the Images I created but don�t use any more are
> keep as image files on the RAP-App Host.
> 3. Some security reasons require that the images should be not
> reachable through a direct link to an image-file.
>
> So I would be very happy to get professional advice for these problems.
> Maybe I should use a Custom-Widget that uses an image-servlet for
> displaying the images.
>
> What is the best way to solve this problem, can somebody explain me the
> different concepts of Images in RAP?
>
> Best regards
>
> p-lex
>
Re: Disposing Images / keeping Images just for a time or user session [message #124017 is a reply to message #123357] Mon, 09 March 2009 15:19 Go to previous messageGo to next message
p-lex is currently offline p-lexFriend
Messages: 18
Registered: July 2009
Junior Member
@ Rüdiger
thx a lot for your suggestion to use a ServiceHandler to deliver images.
This is a great solution for my needs.

Instead of writing an c-widget to display the images coming from the
ServiceHandler is there a way to create images using just an url to the
image file?
I dont know how the widgets wich display images get the URL to the image
but I think it is done by ResourceFactory#getImagePath(Image). But this
way
the path to the image has to be already registered through one of the
findImage methods.

So what do you think about that? What are the problems? And is the
RAP-Image-API on the way to change soon?

best regards,

p-lex
Re: Disposing Images / keeping Images just for a time or user session [message #124030 is a reply to message #124017] Mon, 09 March 2009 15:29 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: benjamin.wolff.web.de

Hi,

mybe you should consider to use the Browser Widgets to Display the images..?! That's how i do it.
you could set the Browser Widget's URL to the servicehandler...


HTH,
Ben



p-lex schrieb:
> @ Rüdiger
> thx a lot for your suggestion to use a ServiceHandler to deliver images.
> This is a great solution for my needs.
>
> Instead of writing an c-widget to display the images coming from the
> ServiceHandler is there a way to create images using just an url to the
> image file?
> I dont know how the widgets wich display images get the URL to the image
> but I think it is done by ResourceFactory#getImagePath(Image). But this
> way the path to the image has to be already registered through one of
> the findImage methods.
>
> So what do you think about that? What are the problems? And is the
> RAP-Image-API on the way to change soon?
>
> best regards,
>
> p-lex
>
Re: Disposing Images / keeping Images just for a time or user session [message #124118 is a reply to message #124030] Mon, 09 March 2009 21:15 Go to previous messageGo to next message
p-lex is currently offline p-lexFriend
Messages: 18
Registered: July 2009
Junior Member
thx a lot for your reply :)

Yes this is the solution that I've tried first. But the problem using the
browser widget is that I dont get the focus events for the images.

The images should be displayed in a gallery. In this gallery the user
should can "select" the images. If he klicks on an Image inside a browser
widget I dont get it.

The browser widget could be a nice solution if it could be used in some
kind of background mode so that I could have a gui layer over the browsers
content to handle focus events.

If you take a look e.g. at bug 245635
https://bugs.eclipse.org/bugs/show_bug.cgi?id=245635 there are already
requests to have more possibility to use images.

RAP use image objekts just as identifier for image paths and keeps the
width and height of the image.

So why images cant be just created using an url to an image and the
scalled size of the image?

The providing of images in RAP is dont solved very well. It is not really
tranparent that happens if you create images.

I just want the best solution I can get without writing my own widgets :)

p-lex
Re: Disposing Images / keeping Images just for a time or user session [message #124131 is a reply to message #124118] Tue, 10 March 2009 08:44 Go to previous messageGo to next message
Stefan   is currently offline Stefan Friend
Messages: 316
Registered: July 2009
Senior Member
Hi,

I would also not prefer using the Browser widget. You can use
Graphics.getImage(String, Inputstream) to register your images and to
return an Image instance that you can simply set to a Label, Button, or
whatever. Additionally, your ServiceHandler should keep a reference to
the Image (e.g. a Stream) and return it on demand.

To make this work, you'll have to pass a absolute URL to
Graphics.getImage() as path, e.g.
http://localhost:9080?custom_service_handler=ImageProvider&a mp;imageId=0x12345

Unfortunately, you'll need to patch the RAP method
org.eclipse.ui.internal.servlet.ResourceManagerFactory.Resou rceManagerWrapper.register(String,
InputStream)
to prevent registering your URL-resource image, which is not necessary.
The implementation of this method should be replaced with sth. like that:

public void register( final String name, final InputStream is ) {
// RAP HACK
if (!name.startsWith("http:")) {
resourceManager.register( name, is );
registerAtHttpService( name );
} }


In your ServiceHandler you can implement any kind of strategy to
"forget" images. Another side effect: Calls to ServiceHandlers carry
session information so you can check, if the request comes from a valid
session or not. In contrast, statically registered images are visible
outside session scope.

Hope that helps,
Stefan.





p-lex schrieb:
> thx a lot for your reply :)
>
> Yes this is the solution that I've tried first. But the problem using
> the browser widget is that I dont get the focus events for the images.
>
> The images should be displayed in a gallery. In this gallery the user
> should can "select" the images. If he klicks on an Image inside a
> browser widget I dont get it.
>
> The browser widget could be a nice solution if it could be used in some
> kind of background mode so that I could have a gui layer over the
> browsers content to handle focus events.
>
> If you take a look e.g. at bug 245635
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=245635 there are already
> requests to have more possibility to use images.
>
> RAP use image objekts just as identifier for image paths and keeps the
> width and height of the image.
>
> So why images cant be just created using an url to an image and the
> scalled size of the image?
>
> The providing of images in RAP is dont solved very well. It is not
> really tranparent that happens if you create images.
>
> I just want the best solution I can get without writing my own widgets :)
>
> p-lex
>
Re: Disposing Images / keeping Images just for a time or user session [message #124158 is a reply to message #124131] Tue, 10 March 2009 09:20 Go to previous messageGo to next message
p-lex is currently offline p-lexFriend
Messages: 18
Registered: July 2009
Junior Member
That seems to be a great idea. Thank you for this.

I thought about something like that to solve my problem, but I didnt know
how to do it best way. So your suggestion is very helpfull for me, thx a
lot.

I hope that the image part of the RAP API will become better soon.

p-lex
Re: Disposing Images / keeping Images just for a time or user session [message #128878 is a reply to message #122632] Mon, 20 April 2009 12:28 Go to previous messageGo to next message
Miroslav Zebrak is currently offline Miroslav ZebrakFriend
Messages: 1
Registered: July 2009
Junior Member
Hello,

I also need some image gallery for RAP. Do you already have some results?

Thx

Miroslav
Re: Disposing Images / keeping Images just for a time or user session [message #128904 is a reply to message #128878] Mon, 20 April 2009 13:52 Go to previous messageGo to next message
p-lex is currently offline p-lexFriend
Messages: 18
Registered: July 2009
Junior Member
For delivering Images I use an IServiceHandler (you should know about
IServiceHandler that they can be only registered programmatically - the
way through the servicehandler.xml doesnt work) you can register the
serviceHandler in a start-method of your plugin activator class e. g.:

if (imageServiceHandler == null) {
imageServiceHandler = new ImageServiceHandler();
RWT.getServiceManager().registerServiceHandler(ImageServiceH andler.REQUEST_PARAMETER_ID,
imageServiceHandler);
}

see
http://www.eclipse.org/newsportal/article.php?id=5711&gr oup=eclipse.technology.rap#5711

In the service-method of the service handler you can just write the data
of an image in a stream, like that:

byte[] data = loadImage(id, width, height);
OutputStream out = RWT.getResponse().getOutputStream();
out.write(data, 0, data.length);
out.flush();
out.close();

For display the images I started with the suggestion of Stefan Roeck see
http://www.eclipse.org/newsportal/article.php?id=5772&gr oup=eclipse.technology.rap#5772

For this I created a path-fragment to patch the rap way of creating images.

I patched the ResourceFactory class. I Just added the following methods:

public static synchronized Image createExternalImage(final String path,
int width, int height) {
//IResourceManager manager = ResourceManager.getInstance();

Image image = createImageInstance(width, height);
images.put(image.toString() + path, image);

//manager.register(path, (InputStream) null);

return image;
}

public static synchronized boolean disposeImage(Image image)
{
return disposeImage(image.toString()+getImagePath(image));
}

and changed the getImagePath method:

public static synchronized String getImagePath( final Image image ) {
String result = null;
Iterator it = images.entrySet().iterator();
boolean next = true;
while( next && it.hasNext() ) {
Map.Entry entry = ( Map.Entry )it.next();
if( entry.getValue().equals( image ) ) {
result = ( String )entry.getKey();

String imageHash = image.toString();
if(result.startsWith(imageHash))
{
result = result.substring(imageHash.length());
}

next = false;
}
}
return result;
}

This change is needed becouse I use a little hack that allows me to create
more than one image using the same path. (The hashcode of the image is
used as a extension of the path that is used as identifier for the image
objects)

Now you can create images through the createExternalImage Method and use
them like any other image.

Hope that helps :)
if not just ask ;)
Re: Disposing Images / keeping Images just for a time or user session [message #130382 is a reply to message #128904] Mon, 27 April 2009 13:13 Go to previous message
Stefan   is currently offline Stefan Friend
Messages: 316
Registered: July 2009
Senior Member
As this seems to be a common use case I created a bug
https://bugs.eclipse.org/bugs/show_bug.cgi?id=273827 with a patch to
allow providing images from ServiceHandlers (or from somewhere else).

Regards,
Stefan.
Previous Topic:Change perspective
Next Topic:Gradient Color
Goto Forum:
  


Current Time: Tue Dec 07 13:23:40 GMT 2021

Powered by FUDForum. Page generated in 0.02823 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top